Programmapad ophalen in VB.NET?

Hoe krijg ik het absolute pad van het programma dat ik gebruik?


Antwoord 1, autoriteit 100%

Daarvoor kunt u de Applicationobject.

Opstartpad, alleen de map, gebruik Application.StartupPath()

Dim appPath As String = Application.StartupPath()

Volledig .exe-pad, inclusief de naam program.exe aan het einde:, gebruik Applicatie.ExecutablePath()

Dim exePath As String = Application.ExecutablePath()

Antwoord 2, autoriteit 59%

Probeer dit: My.Application.Info.DirectoryPath[MSDN]

Dit gebruikt de functie Myvan VB.NET. Deze specifieke eigenschap is beschikbaar voor alle niet-webprojecttypen, sinds .NET Framework 2.0, inclusief console-apps zoals u dat wenst.

Zolang u erop vertrouwt dat Microsoft dit blijft werken voor alle bovenstaande projecttypen, is dit eenvoudiger te gebruiken dan toegang te krijgen tot de andere “directere” oplossingen.

Dim appPath As String = My.Application.Info.DirectoryPath

Antwoord 3, autoriteit 11%

Voor een consoletoepassing kunt u System.Reflection.Assembly.GetExecutingAssembly().Locationgebruiken zolang de aanroep wordt gedaan binnen de code van de console-app zelf, als u dit van binnenuit aanroept een andere dll of plug-in dit zal de locatie van die DLL retourneren en niet het uitvoerbare bestand.


Antwoord 4, autoriteit 8%

Je kunt het pad krijgen met deze code

Dim CurDir as string = My.Application.Info.DirectoryPath

Antwoord 5, autoriteit 8%

U kunt ook gebruiken:

Dim strPath As String = AppDomain.CurrentDomain.BaseDirectory

Antwoord 6

Stel uw eigen applicatiepad in

MijnPathsValues dimmen als string

   TextBox1.Text = Application.StartupPath
    TextBox2.Text = Len(Application.StartupPath)
    TextBox3.Text = Microsoft.VisualBasic.Right(Application.StartupPath, 10)
    myPathsValues = Val(TextBox2.Text) - 9
    TextBox4.Text = Microsoft.VisualBasic.Left(Application.StartupPath, myPathsValues) & "Reports"

Antwoord 7

Als het pad een schijf is, verschijnt er ook een schuine streep in het pad, en deze keer zal het gebruik problemen veroorzaken. Om te verenigen is de beste oplossing het volgende commando.

       Dim FileName As String = "MyFileName"
    Dim MyPath1 As String = Application.StartupPath().TrimEnd("\") & "\" & FileName
    Dim MyPath2 As String = My.Application.Info.DirectoryPath.TrimEnd("\") & "\" & FileName

Antwoord 8

Ik gebruik:

Imports System.IO
Dim strPath as String=Directory.GetCurrentDirectory

Other episodes