How can we access the files in the Data Folder when we publish the Vb.net application - vb.net

I have added some files that I need to be downloaded to the Application start up path. So I set Build Action as content now the files have been copied some where
C:\Documents and Settings\TestUser.ANNAM\Local Settings\Apps\2.0\Data\HVDRBMY5.8AA\858AT9VM.TNP\test..tion_2d7cfc137d9c2c74_0001.0013_432bd4561850d290\Data
How can access file from the application. My problem since it is a dynamic path will it be same folder count so that we can use like ..\..\Data\ Some think like this

Application.UserAppDataPath gets the path for the application data of a user.
Application.StartupPath gives you the path for the executable file that started the application, not including the executable name.
Starting with one of these, you should be able to use System.IO to manipulate the paths until you get the folder where your data files are.

Related

Move application extensions located in Debug folder to one folder

I have a WinForms application that uses 3 .dll Application Extensions. Two of them come from the KBCsv csv file parser extension, and the third is the MySQL Data extension.
Currently these files are automatically stored in the project's Debug folder along with the application itself. When I move the application to an external location, I have to keep these extensions in the same folder as the application or I get an error like:
Could not load file or assembly 'KBCsv, Version....' or one of its dependencies. The system cannot find the file specified.
It would tidy up the desired folder that the application is to be located in if I could store these extensions in one folder, inside that folder. Any guidance as to how I could achieve this would be greatly appreciated.

vb.net file paths causing crashing in published exe

i am making a 'simple' program that on button click does this:
Private Sub Button4_Click(sender As Object, e As EventArgs)
Dim proc As New System.Diagnostics.Process()
proc = Process.Start("resources\navcoder.exe", "")
proc.WaitForExit()
End Sub
all works fine when testing in visual studio but not once i publish and install, even if the resource folder is in the install directory.
if i change it to:
proc = Process.Start("c:\resources\navcoder.exe", "")
it works fine, but i obviuosly needs to have the folder there with the required files in it.
what am i doing wrong?
A lot of people seem not to realise what resources are. The whole point of adding a resource to your project is to have the data it contains compiled into your EXE. The Resources folder in your project is just a place to store the original source files. It doesn't exist as far as the application is concerned, just as your VB source code files don't exist. When you build your project, the data in those resources is compiled into your EXE so they are no longer files and can no longer be used as files.
That's why you don't embed other EXE files as resources. You could extract the resource and save it as a file first but I would recommend against that. Add a new folder to your project and add the EXE file and any dependencies to that folder and set their Build Action to Content. They will then be copied to your output folder as is. You can then execute the EXE file because it is an EXE file. You should also use Application.StartupPath as the root of the file path rather then relying on the current directory being what you think it will be.
You should always check for existance, if its a web app, would do this in the application start in the global asax. If you are running this under a different user account, check the account has permissions. Otherwise even if the directory exists, it will fail if it cant access it or does not have permissions to execute the file.
Might be able to tell you more if you give the actual exception. I.e Unauthorized or does not exist.

Where can I find the rootfolder for my VB.net project

I am making a project that will be put on a disc to use. This means that all of the files that I call upon have to be on that disc. How and where do I put my files to ensure that they will stay with the project? Does it go in the bin folder? And when I am calling on that file what file path do I use?
In general, the bin folder is not a place you should be storing anything that you want to persist with the project.
When you build, Visual Studio will copy the files needed to run the program into the bin folder, such as libraries and web.config or app.config files.
For other files you want included, add them to your project and set their build action property to Content:
Content - The file is not compiled, but is included in the Content output group.
For example, this setting is the default value for an .htm or other
kind of Web file.

How can we access the files in the Data Folder when we publish the Vb.net application

I have added some files that I need to be downloaded to the Application start up path. So I set Build Action as content now the files have been copied some where
C:\Documents and Settings\TestUser.ANNAM\Local Settings\Apps\2.0\Data\HVDRBMY5.8AA\858AT9VM.TNP\test..tion_2d7cfc137d9c2c74_0001.0013_432bd4561850d290\Data
How can access file from the application. My problem since it is a dynamic path will it be same folder count so that we can use like ....\Data\ Some think like this
You can use My.Application.Info.DirectoryPath this will return the directory where the application is stored.

Move files to a specific folder when run the setup file for VB.Net Application

I have created deployment package for VB.Net appolication and it runs fine. When setup is rnning, I want deployment package to move a file from bin folder to other specific folder.
Please suggest, how can I move this file to specific folder.
Any help would be appreciated.
Thanks, Yogi
In Visual Studio 2008 setup project,
Select File System on Target Machine and then from Action menu select Add Special folder and then Custom folder. A new folder will apear on left hand side under the "File System on Traget Machine". Add files, into this custom folder, which you want to copy into into specified location,
Now go into the property of this custom folder and set the DefaultLocation where you want to copy files under this custom folder.
Now when you run the setup this file under the custom folder will copy into the specified location which you set in DefaultLocation.
Yogi..