Link to home
Start Free TrialLog in
Avatar of edbrinkm
edbrinkm

asked on

File access error using asp.net upload control

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.
Avatar of Lalit Chandra
Lalit Chandra
Flag of India image

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.
ASKER CERTIFIED SOLUTION
Avatar of edbrinkm
edbrinkm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have given the code (help) first, thenafter how can you simply close the post like this as my comment was right.
Avatar of edbrinkm
edbrinkm

ASKER

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.
it works.  no errors