Jump to content

C# Visual studio, %USERPROFILE% not working.

im trying to do

webBrowser1.Navigate("file:///C:/Users/%USERPROFILE%/Downloads

but i get file not found using %USERPROFILE% but using my Account name 5 instead of %USERPROFILE% the path works, so how then can i navigate to file:///C:/Users/%USERPROFILE%/Desktop when %USERPROFILE% does not work...

Link to comment
https://linustechtips.com/topic/1057538-c-visual-studio-userprofile-not-working/
Share on other sites

Link to post
Share on other sites

1 hour ago, ughiwanthackintosh said:

im trying to do


webBrowser1.Navigate("file:///C:/Users/%USERPROFILE%/Downloads

but i get file not found using %USERPROFILE% but using my Account name 5 instead of %USERPROFILE% the path works, so how then can i navigate to file:///C:/Users/%USERPROFILE%/Desktop when %USERPROFILE% does not work...

That's not what you want to use. It is NOT expecting variable path. You need the exact path. There is no way to get the download folder properly without issues.

 

First, not all windows version have a "Download" folder

Second, the name changes depending on the OS version (sp : Descargar, fr : téléchargements)

 

You should use an environment safe folder listed in the Enum : Environment.SpecialFolder.

All folders listed in that enum are language safe and will exist on all versions. you retrieve the full path like this :

var userMyDocumentFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

 

Link to post
Share on other sites

22 hours ago, Franck said:

That's not what you want to use. It is NOT expecting variable path. You need the exact path. There is no way to get the download folder properly without issues.

 

First, not all windows version have a "Download" folder

Second, the name changes depending on the OS version (sp : Descargar, fr : téléchargements)

 

You should use an environment safe folder listed in the Enum : Environment.SpecialFolder.

All folders listed in that enum are language safe and will exist on all versions. you retrieve the full path like this :


var userMyDocumentFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

 

Hey! Let me freshen up my problem, the path C:\Users\5\Downloads works,

 

but on others computers the folder name will changed based on system name.

example, C:\Users\Emma\Downloads

but on another it might be Jake

im trying to find something like %userprofile% to place in C:\Users\   \Downloads that will work cross system and independent of system name

Link to post
Share on other sites

29 minutes ago, ughiwanthackintosh said:

Hey! Let me freshen up my problem, the path C:\Users\5\Downloads works,

 

but on others computers the folder name will changed based on system name.

example, C:\Users\Emma\Downloads

but on another it might be Jake

im trying to find something like %userprofile% to place in C:\Users\   \Downloads that will work cross system and independent of system name

Get windows currently logged in user. Don't remember by hearth this one.

 

Just be carefull. For example your code will never run on my computer. First my OS drive is M:\ not C:\ and secondly my user folder is actually redirected on my fourth drive J:\Profiles\Dev\Franck\Downloads\

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×