How to get the full path to the file in c #? Suppose I have a file called "text.txt", which is located in the "Texts" folder on the desktop. I need to display its path in the format "C: / Users / User / folder name / folder name /".
1 answer
For your case, you first need to find out the path to the current user's Desktop. This is done like this:
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); Having a way to Desktop, then it’s easy:
var filePath = Path.Combine(desktopPath, "Texts", "text.txt"); - What's the difference with
Environment.SpecialFolder.Desktop? Here it is exactly where they give it as an answer: stackoverflow.com/q/634142/6766879 I get it on my PC and it’s the same way anyway - Andrey NOP - @AndreyNOP: stackoverflow.com/q/5612571/276994 - VladD
|