Hello, i wanted to know how to write a file path for every computer
For example:

objwrite = New System.IO.StreamWriter("C:\Users\EVGA\Desktop\VB.Net Example\myfile.txt", False)

this code work only on my pc cause of its path
so i wanted to know how to write it so i can use it in another pc
please help
thanks

Use Environment.GetFolderPath() :

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim sDir As String = GetMyCustomDesktopFolderPath()
    Dim fName As String = "myfile.txt"
    Dim sFull = System.IO.Path.Combine(sDir, fName)
    System.IO.File.WriteAllText(sFull, "abc123")
  End Sub

  Private Shared Function GetMyCustomDesktopFolderPath() As String
    Const exampleDirName As String = "VB.Net Example"
    Dim sFullPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), exampleDirName)
    If Not System.IO.Directory.Exists(sFullPath) Then
      System.IO.Directory.CreateDirectory(sFullPath)
    End If
    Return sFullPath
  End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.