-2

What i am trying to do is to Create or writea text file in the server to work as a data log, this code works fine in my pc, but when i build the solution and upload the server files, it creates nothing. Could it be that this code only appends the data and as it doesn't find the file, it doesn't do anything?

string fileName= HttpContext.Current.Server.MapPath("~\\logs.txt");

using (FileStream SourceStream = File.Open(fileName, FileMode.Append))
{
  using (StreamWriter file = new StreamWriter(SourceStream))
  {
     file.WriteLine(data);
  }
}

I also checked the server folder permissions and it is ok

Am i missing something? is something wrong? something that could be done better?

1 Answers1

2

You should give write Permission to your IIS application pool, so your application can write file on directory. On local, application has this permission by default but on server you should give this permission manually.

Ali Zeinali
  • 551
  • 4
  • 16