File Access error - writing to .txt file

Discussion in 'ASP .Net' started by John Carnahan, Jul 18, 2003.

  1. 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\MCP\VisitCount2.txt" is
    denied.

    Stack Trace:
    [UnauthorizedAccessException: Access to the path
    "\\premfs6\sites\premium5\michaelcarlin\webroot\MCP\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, Jul 18, 2003
    #1
    1. Advertising

  2. 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
    http://Steve.Orr.net


    "John Carnahan" <> wrote in message
    news:%...
    > 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\MCP\VisitCount2.txt" is
    > denied.
    >
    > Stack Trace:
    > [UnauthorizedAccessException: Access to the path
    > "\\premfs6\sites\premium5\michaelcarlin\webroot\MCP\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, Jul 18, 2003
    #2
    1. Advertising

  3. Thanks Steve

    "Steve C. Orr, MCSD" <> wrote in message
    news:O$...
    > 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
    > http://Steve.Orr.net
    >
    >
    > "John Carnahan" <> wrote in message
    > news:%...
    > > 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\MCP\VisitCount2.txt" is
    > > denied.
    > >
    > > Stack Trace:
    > > [UnauthorizedAccessException: Access to the path
    > > "\\premfs6\sites\premium5\michaelcarlin\webroot\MCP\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, Jul 18, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Uri
    Replies:
    4
    Views:
    311
    Fuzzyman
    May 11, 2004
  2. Sameen
    Replies:
    2
    Views:
    450
    Victor Bazarov
    Aug 29, 2005
  3. bilgin arslan

    Trouble writing txt

    bilgin arslan, Jan 21, 2009, in forum: Python
    Replies:
    1
    Views:
    320
    Jeff McNeil
    Jan 21, 2009
  4. Jochen Brenzlinger
    Replies:
    7
    Views:
    5,591
    Roedy Green
    Sep 15, 2011
  5. Replies:
    3
    Views:
    84
    Jason Friedman
    Apr 2, 2014
Loading...

Share This Page