File Access error - writing to .txt file

  • Thread starter Thread starter John Carnahan
  • Start date Start date
J

John Carnahan

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

Steve C. Orr said:
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 said:
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
 
Back
Top