The My Namespace

My is a VB-exclusive shortcut to common .NET functionality.

Machine info, file system, audio, clipboard, registry, network App info, startup events, culture, log Typed user/application settings

My.Settings.LastUser = "Ana": My.Settings.Save() Strongly typed embedded resources

My.Resources.Logo, My.Resources.WelcomeText Current user identity/roles

My.User.Name, My.User.IsInRole("Admin") Default form instances (WinForms) Web service proxies (legacy)

The VB Application Framework (WinForms) adds a single-instance application, splash screen, startup/shutdown events, and an unhandled exception event (ApplicationEvents.vb).

TextFieldParser (Microsoft.VisualBasic.FileIO) is an excellent CSV/fixed-width parser:

On .NET Core/.NET 5+, most of My is available for WinForms and some for console/libraries. My.Settings and My.Resources work in SDK-style projects.

' File system
Dim text = My.Computer.FileSystem.ReadAllText("notes.txt")
My.Computer.FileSystem.WriteAllText("log.txt", "Entry" & vbCrLf, append:=True)
My.Computer.FileSystem.CopyDirectory("src", "backup", overwrite:=True)
For Each f In My.Computer.FileSystem.GetFiles("C:\Data", FileIO.SearchOption.SearchAllSubDirectories, "*.csv")
    Console.WriteLine(f)
Next
My.Computer.FileSystem.DeleteFile("old.txt", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)

' System info
Console.WriteLine(My.Computer.Name)
Console.WriteLine(My.Computer.Info.OSFullName)
Console.WriteLine(My.Computer.Info.TotalPhysicalMemory \ (1024 * 1024) & " MB")
My.Computer.Clipboard.SetText("copied!")
My.Computer.Audio.Play("chime.wav")
Dim isOnline = My.Computer.Network.IsAvailable
My.Computer.Network.DownloadFile("https://example.com/file.zip", "file.zip")
Dim regValue = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\MyApp", "Theme", "Light")

' Application
Console.WriteLine($"{My.Application.Info.ProductName} v{My.Application.Info.Version}")
Console.WriteLine(My.Application.Info.DirectoryPath)
Using parser As New FileIO.TextFieldParser("data.csv")
    parser.TextFieldType = FileIO.FieldType.Delimited
    parser.SetDelimiters(",")
    parser.HasFieldsEnclosedInQuotes = True
    While Not parser.EndOfData
        Dim fields As String() = parser.ReadFields()
        Console.WriteLine(String.Join(" | ", fields))
    End While
End Using