By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

File Access error - writing to .txt file

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <ca********@msn.com> wrote in message
news:%2****************@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

Nov 17 '05 #2

P: n/a
Thanks Steve

"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:O$**************@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
http://Steve.Orr.net
"John Carnahan" <ca********@msn.com> wrote in message
news:%2****************@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


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.