Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
Hi
I use this code to write a string in file (strcontent)
C#
string filePath = Server.MapPath("Emailtesttemplate.html");
string writeText = StrContent;
StreamWriter sw = File.AppendText(filePath);
sw.Write(writeText);
sw.Close();

Response.Write("<script>");
Response.Write("window.open('Emailtesttemplate.html','_blank')");
Response.Write("</script>");

this code add text to end of file ! but I need to reWrite file ...
Posted

1 solution

Use the WriteAllText() method. Just make sure you have the appropriate privileges to overwrite the textfile otherwise the overwrite may be declined.

C#
System.IO.File.WriteAllText (@"D:\path.txt", contents);
 
Share this answer
 
v2
Comments
‫محم د‬‎ 16-Aug-14 3:41am    
Access to the path 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\11.0\Emailtesttemplate.html' is denied.
DecompileCodex 16-Aug-14 3:49am    
as i mentioned in my solution, you need to make sure you have the correct permissions
‫محم د‬‎ 16-Aug-14 4:06am    
how i can find the project solotion ?
DecompileCodex 16-Aug-14 4:44am    
you should know where your own project solution is
‫محم د‬‎ 16-Aug-14 4:46am    
in my computer i know ! but when I Upload my site ???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900