473,805 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UnauthorizedAcc ess 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.File Name 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(@s FilePath))
{
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.Unauthor izedAccessExcep tion: Access to the path "C:\Documen ts 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 3256
On Jun 9, 10:00 pm, jeff31162 <jeff31...@disc ussions.microso ft.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.File Name 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(@s FilePath))
{
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.Unauthor izedAccessExcep tion: Access to the path "C:\Documen ts 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...@disc ussions.microso ft.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.File Name 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(@s FilePath))
{
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.Unautho rizedAccessExce ption: Access to the path "C:\Documen ts 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*****@hotmai l.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.co m>
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
12777
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: "<?xml version="1.0" ?><ERROR>ORA-01403: no data found</ERROR>" HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strURIQuery);
2
13006
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 read. I thought about using MyStreamReader.BaseStream.Position, but this always seems to return a multiple of the StreamReader's buffer size (which seems natural-- as I understand it the StreamReader reads from the underlying stream in discrete...
3
5023
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 typical response in this protocol would be:
0
5815
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 the website the first time fine, then browse/refresh, it brings up an XML error. This does NOT show up on another server which we thought was indentical configuration to this one. In the error log, we get the following error: EventType...
3
3114
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) Response.Write(sReader.ReadLine) End While as well as using the FileStream object along with the StreamReader object like this:
1
1986
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 this. It is the part of the Streamreader class that creates a StreamReader instance for a given Stream. The next entry however I don't understand: - Public Fields Name Description Null A StreamReader object around an empty stream.
1
2891
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 = streamReader.ReadToEnd(); I'm using System.Text.Encoding.Default so that I can get some swedish characters working. But I'm having problem when reading a xml-file that's encoded with UTF-8. In the beginning of the xml-files you have the encoding for the...
2
3157
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 it. I checked it and found that another copy of the program still work (by task manager). That's mean closing the program will not close the serial port. I tried these : Note: I read it using a separate thread. 1)override OnClose to, close the...
0
2365
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 possibilities of calling the streamreader, but nothing worked. Dim sr As StreamReader = New StreamReader(Filename, System.Text.Encoding.Default, True) Dim sr As StreamReader = New StreamReader(Filename, _System.Text.Encoding.ASCII, False, 512)
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10356
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10361
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6874
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.