question

VKSB-0116 avatar image
0 Votes"
VKSB-0116 asked VKSB-0116 edited

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

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

dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered VKSB-0116 commented

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi DuaneArnold-0443,

Thanks; I'll try this if I get any problems I'll come back here.

Thanks
VKSBK

0 Votes 0 ·
JackJJun-MSFT avatar image
0 Votes"
JackJJun-MSFT answered

@VKSB-0116 ,

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.





image.png (3.8 KiB)
image.png (4.3 KiB)
image.png (14.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.