You need to specify the physical path instead of the relative path, use Server.MapPath("~")to get the root path of your site, and then add the path to it. You can learn more about Server.MapPath in this post.
using (System.IO.StreamWriter file = new System.IO.StreamWriter(Server.MapPath(@"~/Experiment/main.txt"), true))
{
file.WriteLine(DateTime.UtcNow.ToString() + " test");
}
source
share