Solved

File access error using asp.net upload control

Posted on 2012-04-04
5
453 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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