C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,112 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I was just coding some C# stuff and I came across an issue.
My code is:
string desktop = @"C:\Users\" + Environment.UserName + @"\Desktop";
string localFilename = @"C:\Users\" + Environment.UserName + @"\Desktop\image.jpg";
I tried it like this and it worked fine:
string desktop = @"C:\Users\USERNAME\Desktop";
string localFilename = @"C:\Users\USERNAME\Desktop\fronk.jpg";
But I need it so others can use it, and therefore cannot use my username. Please could I have some help, thank you.
If you want to get the user Desktop folder, use :
string sDesktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);