File Access error - writing to .txt file

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Re: File Access error - writing to .txt file

    Normally web sites run under the ASPNET user account.
    It appears that this account does not have write privileges to the file path
    you've specified.

    --
    I hope this helps,
    Steve C. Orr, MCSD
    [url]http://Steve.Orr.net[/url]


    "John Carnahan" <carnahan_j@msn.com> wrote in message
    news:%23qjqQjXTDHA.1868@TK2MSFTNGP11.phx.gbl...
    > Using .net in aspx page with following code, and get a write error on the
    > website, but everything works fine on the development machine.
    > ----- code ----
    > Dim counter As String = CType(logcount, String)
    > Dim fileName As String = mPath + mFileName
    > Dim Fs As System.IO.FileStream = New
    System.IO.FileStream(fileName,
    > IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
    >
    > Try
    > Dim Sw As System.IO.StreamWriter = New
    > System.IO.StreamWriter(Fs)
    > Sw.Write(counter)
    > Sw.Flush()
    > Sw.Close()
    >
    > -- error page returned from website ----
    >
    > Server Error in '/' Application.
    > Access to the path
    > "\\premfs6\sites\premium5\michaelcarlin\webroot\MC P\VisitCount2.txt" is
    > denied.
    >
    > Stack Trace:
    > [UnauthorizedAccessException: Access to the path
    > "\\premfs6\sites\premium5\michaelcarlin\webroot\MC P\VisitCount2.txt" is
    > denied.]
    > System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
    > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
    access,
    > FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,
    Boolean
    > bFromProxy) +859
    > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
    access)
    > +43
    > MCP._default.WriteLogCnt()
    > MCP._default.Logger()
    > MCP._default.Page_Load(Object sender, EventArgs e)
    > System.Web.UI.Control.OnLoad(EventArgs e) +67
    > System.Web.UI.Control.LoadRecursive() +29
    > System.Web.UI.Page.ProcessRequestMain() +724
    >
    >

    Steve C. Orr, MCSD Guest

  2. Similar Questions and Discussions

    1. Writing a text file to the file system
      Using Visual Studio C# When I ran the following code: System.IO; private void Button1_Click(object sender, System.EventArgs e) {...
    2. Error writing ACP file
      I get an error when attempting to do a Paper Capture. Once the program reaches the "writing ACP file" I get an error. I feel certain the problem is...
    3. Setting the file permissions of a file I'm writing to
      Is it possible to specify the permissions of a file I create when I: open ("FOO", "> ./bar") or die ("Could not create file"); Thanks in...
    4. writing XML file error
      Hi, I get an error (Access to the path "C:\Inetpub\wwwroot\LE\SMS\Mesaj_One.xml" is denied.) when I do this: string filename...
    5. A failure occurred writing to the resources file. Access is denied. -- RESX file is locked? -- WHY?
      Hi. This is an error that comes up fairly regularly when trying to run the "Rebuild All" command in a Solution that contains more than one...
  3. #2

    Default Re: File Access error - writing to .txt file

    Thanks Steve

    "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
    news:O$fiKxXTDHA.1652@TK2MSFTNGP11.phx.gbl...
    > Normally web sites run under the ASPNET user account.
    > It appears that this account does not have write privileges to the file
    path
    > you've specified.
    >
    > --
    > I hope this helps,
    > Steve C. Orr, MCSD
    > [url]http://Steve.Orr.net[/url]
    >
    >
    > "John Carnahan" <carnahan_j@msn.com> wrote in message
    > news:%23qjqQjXTDHA.1868@TK2MSFTNGP11.phx.gbl...
    > > Using .net in aspx page with following code, and get a write error on
    the
    > > website, but everything works fine on the development machine.
    > > ----- code ----
    > > Dim counter As String = CType(logcount, String)
    > > Dim fileName As String = mPath + mFileName
    > > Dim Fs As System.IO.FileStream = New
    > System.IO.FileStream(fileName,
    > > IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
    > >
    > > Try
    > > Dim Sw As System.IO.StreamWriter = New
    > > System.IO.StreamWriter(Fs)
    > > Sw.Write(counter)
    > > Sw.Flush()
    > > Sw.Close()
    > >
    > > -- error page returned from website ----
    > >
    > > Server Error in '/' Application.
    > > Access to the path
    > > "\\premfs6\sites\premium5\michaelcarlin\webroot\MC P\VisitCount2.txt" is
    > > denied.
    > >
    > > Stack Trace:
    > > [UnauthorizedAccessException: Access to the path
    > > "\\premfs6\sites\premium5\michaelcarlin\webroot\MC P\VisitCount2.txt" is
    > > denied.]
    > > System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
    > > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
    > access,
    > > FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,
    > Boolean
    > > bFromProxy) +859
    > > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
    > access)
    > > +43
    > > MCP._default.WriteLogCnt()
    > > MCP._default.Logger()
    > > MCP._default.Page_Load(Object sender, EventArgs e)
    > > System.Web.UI.Control.OnLoad(EventArgs e) +67
    > > System.Web.UI.Control.LoadRecursive() +29
    > > System.Web.UI.Page.ProcessRequestMain() +724
    > >
    > >
    >
    >

    John Carnahan Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139