Solved

File access error using asp.net upload control

Posted on 2012-04-04
5
452 Views
Last Modified: 2012-04-09
I have an asp.net website that gets an access denied error when executing the below code.
The website is using an application pool configured with a service account.

 MemoryStream destination = new MemoryStream();
                    using (FileStream fileStream = File.OpenRead(this.FileUpload1.PostedFile.FileName))
                    {
                        memStream = new MemoryStream();
                        memStream.SetLength(fileStream.Length);
                        fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length);
                    }

Previously, I used the below code successfully to read the file.
////Load FileUpload's InputStream into Byte array
                    //byte[] imageBytes = new byte[FileUpload1.PostedFile.InputStream.Length + 1];
                    //FileUpload1.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length);

I want to create a memory stream to process the text file.  Any tips is greatly appreciated.
0
Comment
Question by:edbrinkm
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37807073
you can do the your task in the following way

            Stream sw     = FileUpload1.PostedFile.InputStream;
            byte[] buffer = new byte[sw.Length];  
            sw.Read(buffer, 0, buffer.Length);  
            sw.Close();  


Refer : http://forums.asp.net/t/1604848.aspx/1

Hope you will fix up your issue.
0
 

Accepted Solution

by:
edbrinkm earned 0 total points
ID: 37807113
A coworker gave me a solution.

    Stream theStream;
    theStream = FileUpload1.PostedFile.InputStream;
        using (Microsoft.VisualBasic.FileIO.TextFieldParser MyReader = new Microsoft.VisualBasic.FileIO.TextFieldParser(theStream))
        {
//process file

}
0
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37807224
I have given the code (help) first, thenafter how can you simply close the post like this as my comment was right.
0
 

Author Comment

by:edbrinkm
ID: 37807238
I had attempted that code before.  The problem is that it converts the text to a byte array.  I need it as a text file/string format.
0
 

Author Closing Comment

by:edbrinkm
ID: 37822731
it works.  no errors
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now