0

I have just created this .NET program in c# that is supposed to save a pdf file based on user input. the problem is that i want it to be saved on desktop(as for other folders additional permission would be needed and ClickOnce does not accept administrator rights) and for that i would need the user's path. what ways to get it after the user installs the published version exist?

razvan000
  • 5
  • 2
  • 1
    Does this answer your question? [How to get a path to the desktop for current user in C#?](https://stackoverflow.com/questions/634142/how-to-get-a-path-to-the-desktop-for-current-user-in-c) – Lance U. Matthews Mar 26 '20 at 18:52
  • "as for other folders additional permission" - no. There is a whole world of folders that compromise the user's profile, not ONLY the desktop. You can write, running as user, into all relevant folders, including locations for application data that are NOT on the desktop. Check the SpecialFolders enumeration and the Environment. – TomTom Mar 26 '20 at 18:56

2 Answers2

2

You can get the current users Desktop folder path by using System.Environment, use the following to get the Path to the Users Desktop folder.

var desktopFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

Cheers

Raymond
  • 131
  • 2
  • 9
2

You can use Enviornment.GetFolderPath() to get the path to a specific folder for the current user:

var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

Alternatively, another option would be to display a File Save dialog, and that would let the user choose where to save the PDF file. There is a class for WinForms and WPF.

Andy
  • 30,088
  • 6
  • 78
  • 89