File Access error - writing to .txt file

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
 
S

Steve C. Orr, MCSD

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

John Carnahan

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top