none
App Path in Visual Studio 2008

    Question

  • 1. How do I get file.txt in folder where is my application?

    2. How to load that file (like in VB6 fname = App.Path + "/ file.txt)

    3. When I do the installation for my application, whether that be file.txt in the folder where the program is installed on another computer?

    Sunday, June 16, 2013 8:27 AM

Answers

  •  Dim MyAppDir As String = My.Computer.FileSystem.CurrentDirectory

            If Not MyAppDir.EndsWith("\") Then
                'test is string path ends with "\", if not add it 
                MyAppDir &= "\"
            End If

            'to get your text file use
            Dim MyTextFile = MyAppDir & "file.txt"
    Sunday, June 16, 2013 8:58 AM
  • Hello,

    Using the following to get the application folder via Application.StartPath, using IO.Path.Combine will add a directory separater between the folder name and file name.

    IO.Path.Combine(Application.StartupPath,"File.txt")


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Sunday, June 16, 2013 8:52 AM
    Moderator
  • Sorry Sinan, I have no idea about express edition

    I have never used it before but I think that should be the same ,express and full edition

    however this is what I've talked about (snapshot from my PC)

    Sunday, June 16, 2013 12:24 PM

All replies

  • Hello,

    Using the following to get the application folder via Application.StartPath, using IO.Path.Combine will add a directory separater between the folder name and file name.

    IO.Path.Combine(Application.StartupPath,"File.txt")


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Sunday, June 16, 2013 8:52 AM
    Moderator
  •  Dim MyAppDir As String = My.Computer.FileSystem.CurrentDirectory

            If Not MyAppDir.EndsWith("\") Then
                'test is string path ends with "\", if not add it 
                MyAppDir &= "\"
            End If

            'to get your text file use
            Dim MyTextFile = MyAppDir & "file.txt"
    Sunday, June 16, 2013 8:58 AM
  • You did not answer me, or I did not understand:
    When I make an application to publish, whether file.txt to be appPath directory to a new location on another computer
    Sunday, June 16, 2013 9:22 AM
  • OK Sinan
    you need to build a setup project for your original project, do the following
    Open VB 2008 
    New project -> other projects type -> Setup and deployment 
    in the left corner, right click on "Application folder"
    select "add -> file" and choose your text file
    again: "add -> file" and choose your exe file of your project.
    click build menu to build the setup project

    is that what you've asked for?
    Sunday, June 16, 2013 10:37 AM
  • In the Window "New Project" has only "Templates"
    There's no "Projects type" in left corner
    Why?
    I use Visual Studio 2008 Express Edition
    Sunday, June 16, 2013 11:30 AM
  • Sorry Sinan, I have no idea about express edition

    I have never used it before but I think that should be the same ,express and full edition

    however this is what I've talked about (snapshot from my PC)

    Sunday, June 16, 2013 12:24 PM
  • Public Class XX
        Public Sub XX()
            Dim Path As String = Application.StartupPath
            System.Diagnostics.Process.Start(Path & "\XX.txt")
        End Sub
    End Class
    Sunday, June 16, 2013 1:18 PM
  •  Dim MyAppDir As String = My.Computer.FileSystem.CurrentDirectory

            If Not MyAppDir.EndsWith("\") Then
                'test is string path ends with "\", if not add it 
                MyAppDir &= "\"
            End If

            'to get your text file use
            Dim MyTextFile = MyAppDir & "file.txt"

    There is no need to check for a directory separator character  figure 1 and figure 2 return the same thing.

    figure 1

    Dim MyAppDir As String = My.Computer.FileSystem.CurrentDirectory
    Dim FileName As String = "File.txt"
    Dim FullFileName As String = IO.Path.Combine(MyAppDir, FileName)
    MessageBox.Show(FullFileName)

    figure 2

    Dim MyAppDir As String = My.Computer.FileSystem.CurrentDirectory & "\"
    Dim FileName As String = "File.txt"
    Dim FullFileName As String = IO.Path.Combine(MyAppDir, FileName)
    MessageBox.Show(FullFileName)
    Lastly, if you need to append a directory separator use IO.Path.DirectorySeparatorChar.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Sunday, June 16, 2013 1:26 PM
    Moderator
  • Thanks Kevin for your note, yes your script is shorter ... and more professionality too
    Sunday, June 16, 2013 1:34 PM
  • Thank you all, I have already solved this problem and put it in my program. I marked on the answer ...

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim MyAppDir As String = My.Computer.FileSystem.CurrentDirectory
    Dim fName = MyAppDir & "\MainDict.txt"
    strInputString = UCase(My.Computer.FileSystem.ReadAllText(fName))
    astrSplitItems = Split(strInputString, vbCrLf)

        End Sub

            strInputString and astrSplitItems = Public variables...

    How to mark a post that we no longer need the help?

                           
    Sunday, June 16, 2013 1:49 PM
  • Thank you all, I have already solved this problem and put it in my program. I marked on the answer ...

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim MyAppDir As String = My.Computer.FileSystem.CurrentDirectory
    Dim fName = MyAppDir & "\MainDict.txt"
    strInputString = UCase(My.Computer.FileSystem.ReadAllText(fName))
    astrSplitItems = Split(strInputString, vbCrLf)

        End Sub

            strInputString and astrSplitItems = Public variables...

    How to mark a post that we no longer need the help?

                           

    In regards to marking a post we no longer need the help, you may not need more assistance but I believe it is prudent to show why a particular method is better than another. For instance, Shady AC solution is valid and can be used today yet the .NET Framework provides smarter ways to code, smarter in the sense that Combine method will put the directory separator in the path for you and if the directory separator happen to be / instead of \ the / would be used. Any ways good you have a solution :-)

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Sunday, June 16, 2013 1:57 PM
    Moderator
  • Thanks Kevin for your note, yes your script is shorter ... and more professionality too

    And your solution is valid for 99.95% of the time, in the end they both produce the same result.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Sunday, June 16, 2013 1:58 PM
    Moderator