Friday, 18 January 2013 14:34

how to create and write data in a file in a specified directory

Written by 
Rate this item
(0 votes)

this post will show how to create a file in dotnetnuke module
directory and write some data in the can use this
technique in application too -

here i write content from main.aspx to file.txt file -

WebClient client2 = new WebClient();
using (Stream stream2 = client2.OpenRead("http://localhost/csharp/main.aspx")
using (StreamReader reader = new StreamReader(stream2, Encoding.Default))
string data = reader.ReadToEnd();
File.WriteAllText(GetLicenseFilePath(this.TemplateSourceDirectory),data, Encoding.Default);

private static string GetLicenseFilePath(string templateDirectory)
return Path.Combine(HttpContext.Current.Server.MapPath(templateDirectory), "file.txt");

Read 2654 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.