UnauthorizedAccess with streamreader

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?amVmZjMxMTYy?=

    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.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

  • parez

    #2
    Re: UnauthorizedAcc ess with streamreader

    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...

    eSports News, Results, upcoming Matches & live Matches. Learn tricks and guides in the esports space. ✅ We cover CS:GO, Dota 2, LOL, Overwatch & PUBG. 


    The file you are trying to read is on the clients computer and your
    code is running on the webserver.

    Comment

    • Jeff User

      #3
      Re: UnauthorizedAcc ess with streamreader

      On Mon, 9 Jun 2008 19:54:55 -0700 (PDT), parez <psawant@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

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: UnauthorizedAcc ess with streamreader

        Jeff User <jen1162@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 - <skeet@pobox.co m>
        Web site: http://www.pobox.com/~skeet
        Blog: http://www.msmvps.com/jon.skeet
        C# in Depth: http://csharpindepth.com

        Comment

        Working...