PDA

Click to See Complete Forum and Search --> : FileStreams in aspx page?


sunburnt
Jun 6th, 2003, 11:24 PM
How can I write data using a filestream during a session? I've tried setting various IIS permissions, but I keep getting System.UnauthorizedAccessException: Access to the path "C:\inetpub\wwwroot\whatever\data.txt" is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) ...

Here's the relevant code:

private void BtnDotDotDot_Click(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
return;

string sName = Request.QueryString.Get("name");
if (sName == null)
{
// ...
}
try
{
FileStream fs = new FileStream(Request.PhysicalApplicationPath + "\\data.txt",
FileMode.Append, FileAccess.Write, FileShare.Write);
StreamWriter sw = new StreamWriter(fs);
sw.AutoFlush = true;
sw.WriteLine("Name:\t" + sName + ":\t...");
sw.Close();
}
catch(Exception ex)
{
Response.Write(ex.ToString());
return;
}
}

angiras
Jun 9th, 2003, 02:10 AM
you just must give the rights to ASPNET user

right click button on the file or the folder you want
then security
and add ASPNET
give full rights

......and you are done