How to get a path to the desktop for current user in C#?
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
How to get the local desktop path of the users file when the application is hosted from server?
You are hosting a website, which is using a web server like IIS and the user access the site using a browser like edge, chrome, now the file is in user desktop, so the main question remains,
Does the browser process have the access to the file system of the user
Mostly no, especially not via the call Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
, this will be good for running it on hosted sever, where w3p.exe
process is accessing the file system with required permissions
For the end user desktop
You need to provide the file dialog box, let user select the file / directory and need to plan to serialize the file to the sever (upload) for doing any processing. You can binary serialize the file using a provider like protobuf, msgpack to achieve the necessary functionality
Code you have provided, is good for for the process where you have direct control, like Console, WPF
, which runs on the system under certain permission and thus access the file system for processing
How to create the path to desktop for the target user..in C#.net
Next code will return path to the desktop of current user:
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
So, in your case it would be
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string image1 = System.IO.Path.Combine(desktop, "r.bmp");
How can i get a user's path after publishing a .NET project?
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.
C# reference to the desktop
Quick google search reveals this one:
string strPath = Environment.GetFolderPath(
System.Environment.SpecialFolder.DesktopDirectory);
EDIT: This will work for Windows, but Mono supports it, too.
How can I get the current user directory?
May be this will be a good solution: taking in account whether this is Vista/Win7 or XP and without using environment variables:
string path = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName;
if ( Environment.OSVersion.Version.Major >= 6 ) {
path = Directory.GetParent(path).ToString();
}
Though using the environment variable is much more clear.
Related Topics
How to Unserialize PHP Serialized Array/Variable/Class and Return Suitable Object in C#
What's the Difference Between System.Valuetuple and System.Tuple
Why There Are 5 Versions of Timer Classes in .Net
How to Parse Hex Values into a Uint
How to Do Appbar Docking (To Screen Edge, Like Winamp) in Wpf
Swap Two Variables Without Using a Temporary Variable
How to Cast from Parent Class to Child Class
Read the Value of an Attribute of a Method
Does C++11 Have C#-Style Properties
Catching "Maximum Request Length Exceeded"
How to Directly Execute SQL Query in C#
Xdocument Containing Namespaces
Using Side-By-Side Assemblies to Load the X64 or X32 Version of a Dll
Select Multiple Items from a Datagrid in an Mvvm Wpf Project