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

asked 2021-04-29T22:00:39.927+00:00
VKSB 136 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

regards
VKSBK

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

2 answers

Sort by: Most helpful
  1. answered 2021-04-30T06:56:41.057+00:00
    Duane Arnold 3,211 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.

    http://www.thescarms.com/dotnet/apppath.aspx

    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.

    https://www.vbforums.com/showthread.php?305393-vb-net-Open-csv-file-thru-excel-and-save


  2. answered 2021-04-30T07:02:14.413+00:00
    Jack J Jun 19,031 Reputation points Microsoft Employee

    @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.

    92871-image.png

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

    92834-image.png

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

    92784-image.png

    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"  
            Process.Start(path)  
      
        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.

    No comments