Solved

File access error using asp.net upload control

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

18 Experts available now in Live!

Get 1:1 Help Now