I am saving a file to the desktop special folder like so:
String testFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "iTextSharpTest.pdf");
File.WriteAllBytes(testFile, bytes);
The problem I have with it is that my cheese keeps getting moved - the folder is not static, but randomly changes. For instance, right now, SpecialFolder.Desktop is C:\Users\TEMP.SP.015\Desktop
In the past, though, it has been
TEMP.SP
-and:
TEMP.SP.000 . . . TEMP.SP.014
IOW, I never know when the path will change from "C:\Users\TEMP.SP.015\Desktop" to "C:\Users\TEMP.SP.016\Desktop"
How can I retain a specific, consistent folder as the one in which my file is saved?
As a side note, when are these new folders created - IOW, what causes Windows to decide it's time to "add another wing onto the mansion" so to speak?
BTW, this occurs on a Windows Server 2008 R2 Standard, Service Pack 1, machine.
try using SpecialFolder.DesktopDirectory:
String testFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "iTextSharpTest.pdf"); File.WriteAllBytes(testFile, bytes);