0

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.

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 1
    See these links - it looks like you are getting a temporary user profile for some reason. : http://www.sysprobs.com/fixed-temporary-profile-windows-8-and-8-1-problem & http://answers.microsoft.com/en-us/windows/forum/windows_8-system/windows-8-keeps-loading-with-temporary-profile/583abee6-645d-42a1-88da-063547c6eea0 & http://setspn.blogspot.co.uk/2012/09/temporary-profiles-and-iis-application.html – PaulF Jul 15 '15 at 15:53

1 Answers1

1

try using SpecialFolder.DesktopDirectory:

String testFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "iTextSharpTest.pdf"); File.WriteAllBytes(testFile, bytes);

Greg Barlow
  • 198
  • 11