Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i save the file to desktop through code. On clicking button i would like to create a file on desktop.
Posted

1 solution

Try this

C#
var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
var fullFileName = Path.Combine(desktopFolder, "Test.txt");
var fs = new FileStream(fullFileName, FileMode.Create);
 
Share this answer
 
Comments
Kim Togo 22-Apr-11 8:05am    
Good answer :-) - Always use a function to get special folder path, and never hard code it.
demouser743 22-Apr-11 8:10am    
Thanks Kim Togo :)
Nish Nishant 22-Apr-11 8:19am    
Voted 5.
Sergey Alexandrovich Kryukov 22-Apr-11 22:34pm    
Correct, my 5.
--SA
Member 13301698 19-Jul-17 8:41am    
Doesn't work for me, though... if opens, empty file, but I was trying to use with excel

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900