How to Open a .csv file created & saved in the installation folder by clicking a Button in VB.Net ?

VKSB 196 Reputation points

Dear Friends,

In my VB.Net project, all the Planetary positions for certain number of days are computed, saved in .csv file and displayed in a ListView tool.

I want to give the option for the user to save the Planetary position that is displayed (ie: that is already saved in the installation folder of the software. I don't want the user to search in the Installation folder for the saved file but I want the user to click a Button Named "Save" & then the .csv file to be opened by MS Excel so that he can save the file wherever he wants using the MS Excel program.

I don't know how to do this; can any of you help me on this please.

Thank you


An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,599 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Duane Arnold 3,216 Reputation points

    Assuming this file is deployed to the same location as the program.exe, you can get the program.exe file path, strip off the program.exe from the path and replace it with your file name you're talking about.

    Note: If you have installed the progam.exe into the Program Files folder, which is a protected folder on the Windows O/S, then the user will not be able to save any file to the protected folder.

    You want to open the cvs file in Excel, then you should be able to give your formulated file path to the location of the cvs file and open the file in Excel.

  2. Jack J Jun 24,296 Reputation points Microsoft Vendor

    @VKSB ,

    Based on your description, you want to use open a csv file directly in the installation folder.

    I recommend that you use the clickonce to publish your app.

    First, please add a folder that contains the csv file.


    Second, please set the csv file Build Action to content.


    Third, please right click properties->Choose Publish->Choose Applications, and set the Data file for the csv file.


    Fourth, please write the following code in your program.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click  
            Dim path As String = ApplicationDeployment.CurrentDeployment.DataDirectory + "\Files\Test.csv"  
        End Sub  

    Finally, you can publish the program and install the app in the another computer to make a test. Based on my test, it works well.

    0 comments No comments