Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

write a file to the users desktop in c#

Tags:

c#

.net

winforms

I want to write a simple text file from my winform app in c# directly to the user's desktop and not be denied. How can I get the path? Thanks in advance.

like image 208
naf-naf Avatar asked Dec 16 '22 11:12

naf-naf


1 Answers

Use Environment.SpecialFolder to get the path to the desktop. You may need to run elevated to write to this folder.

Edit: You also need to ensure that your administrative user has access to the desktop folder. For example:

enter image description here

like image 70
Ed Bayiates Avatar answered Jan 02 '23 23:01

Ed Bayiates