I am checking file is present if specified location and if so I am replacing single quote by '. For this I am using WriteAllText method. For my knowledge WriteAllText will be used to Create file and write the text and close it, target file is already exists, it will be overwritten
.
I don't know why I am getting System.IOException
while using
var file = AppDomain.CurrentDomain.BaseDirectory + "test";
if (Directory.Exists(file))
{
string text = File.ReadAllText(file + "\\test.txt");
text = text.Replace("'", "'");
File.WriteAllText(file + "\\test.txt", text);
}
Note: I am using this inside Application_BeginRequest
method.
Suggest me how to avoid this exception ?