473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

UnauthorizedAccess with streamreader

Hi all
Using vs2003 and C# in a web app.
I want the user to be able to upload a file.
I have an htmlFileField (<input>) on my form.

Then in my C# codebehind, I use fileChooseHtml.PostedFile.FileName to get
the location of the file (the user chose) to read in.

Then I use the following code to actually read the file:
using (StreamReader sr = new StreamReader(@sFilePath))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
sReturnLine += line;
}
}

and I get the error:
System.UnauthorizedAccessException: Access to the path "C:\Documents blah
blah blah...

So, yes, I could give permissions to ASP.NET (I have done it on other
folders and the code works fine) but, am I going to have these same
permission issues when I put this on the web and a user wants to upload a
file from their PC?

I havent gotten that far and might as well find out now, if it is going to
break when I try to deploy it.

Thanks
Jeff

Jun 27 '08 #1
3 3226
On Jun 9, 10:00 pm, jeff31162 <jeff31...@discussions.microsoft.com>
wrote:
Hi all
Using vs2003 and C# in a web app.
I want the user to be able to upload a file.
I have an htmlFileField (<input>) on my form.

Then in my C# codebehind, I use fileChooseHtml.PostedFile.FileName to get
the location of the file (the user chose) to read in.

Then I use the following code to actually read the file:
using (StreamReader sr = new StreamReader(@sFilePath))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
sReturnLine += line;
}

}

and I get the error:
System.UnauthorizedAccessException: Access to the path "C:\Documents blah
blah blah...

So, yes, I could give permissions to ASP.NET (I have done it on other
folders and the code works fine) but, am I going to have these same
permission issues when I put this on the web and a user wants to upload a
file from their PC?

I havent gotten that far and might as well find out now, if it is going to
break when I try to deploy it.

Thanks
Jeff
check this out...

http://www.4guysfromrolla.com/webtech/091201-1.shtml

The file you are trying to read is on the clients computer and your
code is running on the webserver.
Jun 27 '08 #2
On Mon, 9 Jun 2008 19:54:55 -0700 (PDT), parez <ps*****@gmail.com>
wrote:
>On Jun 9, 10:00 pm, jeff31162 <jeff31...@discussions.microsoft.com>
wrote:
>Hi all
Using vs2003 and C# in a web app.
I want the user to be able to upload a file.
I have an htmlFileField (<input>) on my form.

Then in my C# codebehind, I use fileChooseHtml.PostedFile.FileName to get
the location of the file (the user chose) to read in.

Then I use the following code to actually read the file:
using (StreamReader sr = new StreamReader(@sFilePath))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
sReturnLine += line;
}

}

and I get the error:
System.UnauthorizedAccessException: Access to the path "C:\Documents blah
blah blah...

So, yes, I could give permissions to ASP.NET (I have done it on other
folders and the code works fine) but, am I going to have these same
permission issues when I put this on the web and a user wants to upload a
file from their PC?

I havent gotten that far and might as well find out now, if it is going to
break when I try to deploy it.

Thanks
Jeff

check this out...

http://www.4guysfromrolla.com/webtech/091201-1.shtml

The file you are trying to read is on the clients computer and your
code is running on the webserver.
Thanks, but....
I was using the stream reader because I need the file in a local
variable so that I can manipulate the contents. The article that you
refer to only states how to save it directly to the server. I need to
evaluate it and make modifications to it first.

Any other ideas?

Thanks again
Jeff
Jun 27 '08 #3
Jeff User <je*****@hotmail.comwrote:
The file you are trying to read is on the clients computer and your
code is running on the webserver.

Thanks, but....
I was using the stream reader because I need the file in a local
variable so that I can manipulate the contents. The article that you
refer to only states how to save it directly to the server. I need to
evaluate it and make modifications to it first.

Any other ideas?
Yes - look at the API that the article is using. It uses HtmlImputFile
and HttpPostedFile, which lets you get at the data being posted. Just
because they happen to save it straight to disk doesn't mean that's all
you can do with it.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: oafyuf | last post by:
Hi, I'm having performanbce issues with StreamReader and was wondering what I could do to improve it... The following takes around 3 seconds to process! The content of the response is: ...
2
by: Keith Kingsley | last post by:
I'm using a StreamReader to read in several lines from an ASCII file. I'd like to know the StreamReader's "true" position-- that is, the number of bytes into the file that the StreamReader has...
3
by: Arno | last post by:
Hi, I'm using TcpClient for communication between two PC running a small piece of software. The protocol used has been designed internally and is HTTP similar (command line, headers, body). A...
0
by: malken00 | last post by:
We've recently upgraded an IIS6 2003 Server from .NET 1.1 to 2.0 and rewrote the configuration of our program to use this new server. When browsing to the website on the server, it will bring up...
3
by: Arpan | last post by:
A file can be read using only the StreamReader object like this: Dim sReader As StreamReader sReader = New StreamReader(Server.MapPath("File1.txt")) While(sReader.Peek -1)...
1
by: garyusenet | last post by:
>From MSDN I'm trying to learn more about streamreader. I'm working my way down the MSDN definition. The first entry is the Public Constructor StreamReader. I'm fairly happy I have a basic grasp on...
1
by: Sladan | last post by:
Im trying to read a xml-file with a StreamReader. For the moment I'm using the following code. streamReader = new StreamReader(stream, System.Text.Encoding.Default); string feedData =...
2
by: Bassem | last post by:
I'm working on simple chat program via serial port. It works fine, but i face this problem. When i try to open the exe, UnauthorizedAccess exception occurs, i can't use COM1 becuase someone else has...
0
by: rajana | last post by:
Dear All, We have Ansi file with german characters (Ä / Ø) , We are using Streamreader to read the contents of the file. But Readline() not able to read the German characters. We tried all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.