Anyone looking to do a quick write to file from a web part or another piece of SharePoint code is not much different than in regular C# application programming.

           SPSecurity.RunWithElevatedPrivileges(delegate()
{
string[] lines = { "First line", "Second line", "Third line" };
// WriteAllLines creates a file, writes a collection of strings to the file,
// and then closes the file.
System.IO.File.WriteAllLines(@"C:\temp\WriteLines.txt", lines);
});

Be sure to include System.IO as well or you will have compile errors.

No Comments

There are no comments related to this article.

Leave a Reply

Your email address will not be published. Required fields are marked *