Configuration File in C# default location? - c#

I have just created a WPF application and just been wondering where is my app.config file?
I looked in the bin/Debug and bin/Release directories and there is just one file "WpfApplication1.vshost.exe" and could not find any app.config file.
All I can do is Add->New Configuratin File and this too, doesn't come in debug or Release folder.
Can anyone guide me whether I should manually copy and paste it in the debug or Release Folder?
So finally: the ANSWER
If app.config does not exist, then try creating a new one by "Add->New Item->Application Configuration File" and create a file named "App.config". After this, try rebuilding your application, the .config file specific to your project should appear in bin/Debug & bin/Release folder.

It should be getting copied into the Debug/Release folders automatically. However, you could try explicitly setting the "Copy to output directory" in the properties to Copy always and see if it appears.

After creating simple WPF project my solution look like this. App.config lies there, which is the configuration file itself
When you build your solution, which in my case is named as WpfApplication1, config file lies at WpfApplication1.exe.config in \WpfApplication1\bin\Debug\ folder.

When you build your application,it automatically gets copies to debug/Release Folder.just look for *.config file in those folders.

If you build your project you should have a file named foo.bar.exe.config in you binary directory. The app.config file itself should be visible within your solution directory.

Related

AppConfig file not found in bin directory

I have a App.Config file that users can go to and set some settings to run the program.
But when I go to bin\release folder of my program to copy and give them the exe,DLLs, etc I can't find the App.Config file.
What should I do?
It is a ConsoleApp.
your App.Config willbe converted to ApplicationName.exe.config
so if your application name is SampleApplication.exe then you need to check for the following filename
SampleApplication.exe.config.
FROM MSDN : App.Config
When you develop in Visual Studio, place the source configuration file
for your app in the project directory and set its Copy To Output
Directory property to Copy always or Copy if newer. The name of the
configuration file is the name of the app with a .config extension.
For example, an app called myApp.exe should have a source
configuration file called myApp.exe.config.
Is the App.config file set to copy on build? If you right-click on the App.config in VS, and go to Properties, it should be set to 'Content' and 'Copy Always'/'Copy if newer'.
Here is a screenshot of the Properties screen:

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.

C# dotnet web application: Dll's xml config file is lost when Publishing

I'm a bit lost!
I have a dll that uses an xml config file for some db connection info. The dll looks for the xml config file in it's own directory and I can't change the dll at all.
Every time I build the project, I must manually copy the config file into a folder way down somewhere in the Temporary ASP.NET Files folder. (I don't understand this but I can live with this manual change)
The problem is that when I publish the project, I can't figure out where to copy the config file to?
Could someone please point me in the right direction? Or maybe show me a way that I can 'bind' the xml config file to the bin folder???
Vauneen
The .NET config file can be confusing to manage. The way it works in a webapp is that the Web.config will supersede any dependencies' app.config files (which is what I assume you're talking about when you say "DLL".)
Basically, in .NET all config info is pulled from the main app project.
See:
App.config seems to be ignored
and
Configuration from App.config isn't being pulled correctly
and finally:
Does a web.config substitute app.config?
will probably help you figure out what you need to know.
Update: Doing some further searching on your problem, it's possible that the code you're incorporating into the .Net Solution is using the "obsolete" ConfigurationSettings which will require you to add a reference to System.Configuration in your references folder (right-click on the project -> "Add References" and go to the .NET tab and select System.Configuration).
Set "Copy to Output Directory" to "Copy always" in properties of the configuration. Then Visual Studio will copy the configuration file automatically after each build and it will be properly published as well.

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.

c# winapp add app.config to installer?

Okay I've got my app.config file that is containing my database settings.
All works well on my development machine. But when I install it on a test machine I'm getting a null reference on the following line:
ConnectionString = ConfigurationManager.ConnectionStrings["MyDBConn"].ToString();
Why is this happening? I guess that the app.config file isn't found. But isn't this included when you build the setup?
I'm using a very simple setup project in VS2008.
The file app.Config is your source, don't distribute it. When Visual Studio builds your project it copies the file to {AppName}.exe.config (in the same folder as {AppName}.exe ) and that is the file you need to include in your setup.
Select app.config in solution explorer and in the properties tab choose the copy action:
Copy to Output Directory -> Copy always
or
Copy to Output Directory -> Copy if newer
Remember to rename the app.config to the name of the exe.
ie.
myprogram.exe would have an app.config called myprogram.exe.config

Categories