Click here to Skip to main content
14,328,524 members
Rate this:
Please Sign up or sign in to vote.
Hello guys,

I have a problem ,I have a code that saves a text file in my computer with the destination :

C:\Users\Georgegas\Desktop\Log.txt


The problem isn't about the code as it is for the location of the file. I want to use it in other computers not only on my PC , which its name is "GeorgeGkas" :P

In C# i would write that
C:\Users\%USERPROFILE%\Desktop\Log.txt


but in VB.Net that doesn't work for me!

So how do I set my destination to save my file in computers with different name?

I hope you guys understand my problem!
Posted
Comments
Wes Aday 10-Jul-14 16:18pm
   
You would use GetfolderPath and SpecialFolder, http://msdn.microsoft.com/en-us/library/14tx8hby(v=vs.110).aspx
Maciej Los 10-Jul-14 16:23pm
   
It's an answer! Why don't you posted it? I'll promise to vote up ;)
Rate this:
Please Sign up or sign in to vote.

Solution 2

To save in another computer, you need to have access and write permissions to that folder.
For e.g. \\OtherComputer\LogFiles provided you have access to the LogFiles folder.
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

'Declaration
Public Shared Function GetFolderPath ( _
	folder As Environment.SpecialFolder _
) As String


and use it like following


Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.System))
   End Sub 'Main
End Class 'Sample


as suggested in microsoft website.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

O I find it! You just add
+ Environment.UserName.ToString + 


Example
"C:\Users\" + Environment.UserName.ToString + "\AppData\Roaming\program.exe"
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100