How to Choose Application Configuration File Save Location? - c#

In Visual Studio 2013/2015, when you compile your program exe it saves the config file to its \bin\ folder.
When you move your program exe to a location like C:\Program Files\ and run it, it saves the config file to %appdata% \AppData\Local\.
Using C# or Visual Studio settings, how do I tell the exe to always save the config file to its current folder and not %appdata%?
I want to make the program portable and not use %appdata%.
\bin\ Folder
AppData Folder

you can change the output path of your build ...
go to project properties >> build tab >> under output section you can change the output path of your build, so it will creates the build at one place with your all files and make it portable

Related

How should i do to reference one file in my project, so when i publish the application, the file is generated in a specific folder?

the problem that i have with my application is about how to reference some files, when i load and image, etc, i use Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..\\..\\..\\")); and this works fine for debugging and for some files, but doesn't work for some essential files, credentials.txt, config.ini, this files are searched in appdata when i run the published file and i don't know how i should reference them.
I try to generate some initial files so i am sure where they are and that they exists, but for folders that works great with
System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().Location);
with that i can make the folders where the app is run but you can't generate a file without load the content of the original file, and i don't know how to reference them.
Example:
Project.
Root of the project.
utils/key/credentials.txt
When the published file is executed i want to generate and store credentials.txt like this:
Executable (app.exe stored for example in "my documents")
"my documents"/utils/key/credentials.txt
how i do that? when i run the published application you just have the .exe, the dlls, and the resources are embebbed, so the uri doesn't works.
Assuming you have sufficient permissions, you could create a folder in the output folder of your compiled .exe at runtime using the Directory.CreateDirectory method.
If the utils/key/credentials.txt file is part of your deployment, you should set its Build Action to Content and the Copy to Output Directory property to Copy if newer in Visual Studio. This will add the utils and key folders to the output directory of the .exe, which is typically c:<project-folder\bin\Debug or \Release when you build from Visual Studio.
You can get the absolute path of the output directory like this:
string path = System.IO.Path.GetDirectoryName(
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
Depending on your requirements, you may then append the relative path of the file within your app to the absolute path.

Copy "Filesystem on Target Machine" to bin/Debug and bin/Release

I did a lot of googling, but didn't find any answer for this problem so far...
I defined the File System on the Target Machine for my program in Visual Studio 2010.
It includes all of the external Files (like XML's and batch files) which are needed to run the program. The files are stored in the Program Files folder.
The thing is now that if I try to debug my program, it says that it can't find the needed files in MyTool/MyStartProject/bin/Debug.
Is there any way to tell visual studio that it must copy these files to the Debug and Release folder to run the program?
I don't want to copy all files to the bin folder every time I want to run my program.
Thanks for any hint!
EDIT:
This is how my 'File System on Target Machine' looks like:
I created it using the built-in editor and Drag&Drop of the files and folders I need.
Add the needed files to your project, and for each file, open File Properties pane, select "Copy always" in the Copy to Output directory property.

How to copy a file to application folder in set up project during insatllation. File is in set up folder

I have a xml file in the setup folder of a windows application. Now during the installation how do i copy this file to my application's folder so that it can be copied to this path C:\Program Files (x86).......
I can not add the file to the application folder in the setup project because the content of file might change after build of setup project.
Its an external xml file in located inside set up folder. and I want to copy this file on installation path(C:/Program Files...) during installation. I will give this file with msi installer in side installer folder.
Please provide any idea if someone have....
If I'm understanding you correctly, this might solve your problem, or at least get you started:
Include the file in the main project (for instance in a folder called "resources"). Right click the file in VS, choose properties, and set Copy to output directory to Coppy Always.

Launch an Application After Installing using Visual Studio 2010 Setup Project

I followed this link http://www.codeproject.com/Articles/19560/Launching-Your-Application-After-Install-using-Vis
& it has given a good guid to my problem. But in my scenario, I also have a folder with the exe. after installation my exe starts running. but it is not properly linked with the conetent in my folder which is also in same location. How can I link that folder to my exe.
The problem is I added both folder & its contents to Application folder directory given by the setup project wizard. But I can add only the exe to the commit folder as I want my exe to run after after clicking on first initial exe. How ever after first installation both my exe & folder creates & when I click on exe manually it works. But in installation it only copies exe & folder & start running copied exe but could nt find the folder properly.
The working directory of your exe will be different when launched as a commit action.
You either need to change the working directory in your exe or build an absolute path to the folder you are trying to find.
You could pass the application path from the installer to your exe by setting CustomActionData to '[TARGETDIR]\', or extract it from the exe path at runtime, e.g.:
string exepath = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
string abspath = Path.Combine(exepath, "yoursubfolder");
I think this is what you want
http://blogs.msdn.com/b/astebner/archive/2006/08/12/696833.aspx

Embedding a PDF as a resource in WPF application

I want to embed a PDF file (which is basically have Product details, Release notes) and wants to open that file from menu bar. What would be the best approach. I need to use this file in installer also. So i'm looking for an approach in which file will be moved to BIN on compilation and from there installer can access that file.
IDEAS ...
Add the file to the project the builds the EXE (use Add existing file in visual studio). Then right click on the file in visual studio, go to properties, and verify that the build action is "Content" and the copy to output directory is "Always" or "If newer" (whichever suits you).
Then this file will always be copied to the same directory where the EXE resides and your application will be able to access it because it's always in the application's directory.
If the installer just takes the BIN directory then it will also be able to access it because the file will reside in the BIN directory.
Have fun!
Finally i did it in following way:
a. We've a folder which contains notes.pdf (used by installshield).
b. Created a pre build command to copy the pdf file from installshield folder to output directory.
c. use process.start("notes.pdf"); to open the file. As it would look in bin directory first for pdf file and we've already copied it there.
It worked for both Installer version and running application from code.

Categories