Solved

File access error using asp.net upload control

Posted on 2012-04-04
5
458 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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