Problem with Application.Download()

0
0

I have a strange problem, if I use this code the file is created, but when I execute the Download line, the download does not occur and the message “DISCONNECTED” appears and the App closes.

string cPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.RelativeSearchPath ?? “”) + “\\Temp\\”;

StreamWriter sw = new StreamWriter(cPath + “test.txt”);
sw.WriteLine(“1234567890”);
sw.Close();
Application.Download(cPath + “test.txt”);

But if I leave the created file and use ONLY Application.Download(cPath + “test.txt”); everything is fine, I don’t understand this behavior, maybe the StreamWriter is causing some problems?

Thank you

  • You must to post comments
0
0

Try replacing AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.RelativeSearchPath with Application.StartupPath, it’s probably an issue with the StreamWriter and the path.

Let me know if that works

Best,
Alaa

  • Francesco Leo
    I had already tried, but that path returns the root of the application and therefore I would find myself full of useless files. Furthermore it is not a StreamWriter problem because it also happens with WriteAllText.
  • Alaa (ITG)
    It is because you’re trying to write stuff in the Bin folder, the app is constantly crashing and trying to reload… You can’t write anything inside the Bin folder of the application, you can only read from there. Hence why it’s not recommended to use AppDomain.CurrentDomain.BaseDirectory AppDomain.CurrentDomain.RelativeSearchPath, use Application.MapPath() or Application.StartupPath for everything else.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.