WRITE TO THE FILE SYSTEM IN A DIRECTORY

jayprakash sharma

Total Post:117

Points:821
Posted by  jayprakash sharma
C# 
C#
 1208  View(s)
Ratings:
Rate this:

I would like to write to the file system in a directory C: \ directory name, for the moment I have this code:

if (! System.IO.File.Exists (HttpContext.Current.Server.MapPath (filename)))
{
   TXTFile = new System.IO.StreamWriter (HttpContext.Current.Server.MapPath (filename));
}
else
{
   TXTFile = System.IO.File.AppendText (HttpContext.Current.Server.MapPath (filename));
}

but in this way writes on the application folder. How to fix it?

  1. Manoj Bhatt

    Post:154

    Points:1086
    Re: Write to the file system in a directory

    You can do:

    Path.Combine(@"C:\", filename)

    instead of

    HttpContext.Current.Server.MapPath (filename)
    Ensure your application has write access to the destination.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!