-6
if (!System.IO.File.Exists(Server.MapPath(klasoradi + htmlname + ".html")))
{
    System.IO.File.WriteAllText(Server.MapPath(klasoradi + htmlname + ".html"), htmltext);
}

I'm using this code for creating and saving my html file. But I can't overwrite the file.

Can you please help me fix this situation ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Seration
  • 233
  • 2
  • 4
  • 8
  • Do you get an **error** when trying to overwrite? If so: please **post** the complete and exact error message! – marc_s Jun 23 '14 at 18:55
  • 5
    Just remove your if statement. – Daniel Jun 23 '14 at 18:55
  • Read your code. Your if statement checks if the file does NOT exist, and if it does, to write to it. Did you even bother to debug this? If you had, you'd have noticed your if statement never evaluates to true. – tnw Jun 23 '14 at 19:20
  • @DanielCook i removed if.. In the first test worked. Creted the file and saved it. But when i do this again i get this error : This process using by another proccess – Seration Jun 23 '14 at 19:47
  • @Seration Different issue. You can't overwrite a file that is already open for editing. – Daniel Jun 23 '14 at 20:03

1 Answers1

1

According to MSDN WriteAllText(string,string) will overwrite a file. So, all you need to do is remove your initial if statement and it will either create the file or overwrite it.

Austinh100
  • 598
  • 3
  • 13
  • i removed if.. In the first test worked. Creted the file and saved it. But when i do this again i get this error : This process using by another proccess – Seration Jun 23 '14 at 19:52