Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello guys,

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

VB
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#
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
[no name] 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 ;)

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.
 
Share this answer
 
VB
'Declaration
Public Shared Function GetFolderPath ( _
	folder As Environment.SpecialFolder _
) As String


and use it like following


VB
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.
 
Share this answer
 
O I find it! You just add
VB
+ Environment.UserName.ToString + 


Example
VB
"C:\Users\" + Environment.UserName.ToString + "\AppData\Roaming\program.exe"
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900