MC Fer MC Fer - 11 months ago 57
C# Question

Error saving a file on server

I am generating a Key and i need to record on server. When i tried locally, it Works ! The problem is when i try on the server...
The archive is generated but when ON THE SERVER the download finish,but i cannot open and cannot save. I don´t get an error...but i just cannot save...

The code:

string fileNamePrivate = @"pasta1/archive.txt";
StreamWriter textWriterPriv = new StreamWriter(fileNamePrivate, true);
var pemWriter = new PemWriter(textWriterPriv);

Answer Source

Try to use

string fileNamePrivate = "~/PASTA1/archive.txt";
StreamWriter textWriterPriv = new StreamWriter(fileNamePrivate, false);

How is a Server you have to use HostingEnvironment.MapPath and set "false" instead "true" on StreamWriter if you need to overwrite.