Location of applicationname.exe.config in C# - c#

Where I can find the applicationname.exe.config file in my Windows form application.
Where can I find the application exe... mentioned that config file should be placed in Release or Debug files. But I cannot see the file in those places.
Also, I manually copied the config file from project root directory and past it in Release directory. Still the changes are not effected.
Then, I renamed the config as applicationname.exe.config, still the not effected.
Anybody can tell me how can I overcome ?

It should be in the same folder as applicationname.exe. That is generally where the config files are for win forms applications.
If it is not there, you can create a new one, with the name applicationname.exe.config.

Try like this path. i.e, inside bin folder
C:\Documents and Settings\deepika\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\bin\Debug

Try,
string path = Environment.GetCommandLineArgs()[0] + ".config";

Related

C# File Disappeared after FileInfo.MoveTo with Local Path (Windows)

I Ran FileInfo.MoveTo("filename.txt") with just a name instead of passing a full path and the file just disappeared. I believe in linux this would make it go to the root directory "/", but on Windows I'm not sure if there is a such thing as a root directory beyond just C: Is there any way to locate my lost file?
It is likely in the working folder that your executable is running from. For example, MyApp\bin\Debug, depending on the configuration you are running in.
It should be in project folder. Usually files without specefying path are saved there. (in folder with .exe file)

How to deploy a C# (ClickOnce?) project that is a wrapper on a command line .exe

I have a C# project which is basically a GUI used to call other executable(s) with command line arguments. (The command line exe was actually built with cygwin and uses the cugwin DLL).
So the directory structure that needs to exist once the app is deployed (via setup.exe or whatever) is this:
install dir ---> MyApp.exe
MyApp.config
(dir) bin ---> cmd1.exe
cmd2.exe
cygwin.dll
Now this ought to be simple, but whatever I try, I cannot get the bin directory and its contents to be copied when I install on a second machine with setup.exe. I tried:
- adding them as resources
- setting "Build Action" to Content
- setting "Copy To Output Directory" to Always
But the bin directory was never copied across when I did this. I have tried searching here and elsewhere but I am still at a loss.
Should this be a "ClickOnce" project? (what does this even mean - are there also ClickTwice and ClickUntilYouCanClickNoMore projects - ok, excuse me ...)
Also do I get setup.exe to put this app somewhere sane like C://Program Files/MyOrg/Myapp - instead of being buried somewhere in the user's profile?
(Using VS 2019.)
Since I cannot add an image in a comment, I am adding them here. Here is how my folder structure looks like.
I have a .p12 file and have marked it as "Copy to Output Directory" to "Copy always"
When the project is built, the file gets copied inside bin folder with the file's folder structure which includes "keystore" folder as well.
As a curiosity, I just tried out renaming my folder "keystore" to "bin" (I had to delete existing bin folder), and then added the .p12 file to it. The project compiled, generated new exe file and also copied .p12 file with appropriate folder structure. I am not sure what means to building and generating a Setup.exe though. You can try and let us know if it worked for you.
To package the specified file into ClickOnce, you just need to add it to Application Files....
The following is the folder structure.
And then confirm it has been added into Application Files....
Last step, publish it. And you can access the image like this.
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + #"/img/a.jpg");
}
As to put this app somewhere sane, I am afraid the answer is no.
ClickOnce's installation path cannot be changed. You can find it at C:\Users\username\AppData\Local\Apps\2.0.

open file from folder in visual studio 2012

I had a folder on my desktop with files in it. I copied that into the folder of my solution and in the solution explorer I referenced that folder into the solution. However, Im not able to open files in that folder with a relative path.
The relative path from the cs-file would be "../FolderIAdded/blabla" as seen in the solution explorer. But in the windows explorer, the path is differen of course:
Solutionfolder
- SolutionFolder.sln
- Solutionfolder.v11.suo
- SolutionFolder
-- bin
-- obj
-- Properties
-- TheFolderIAdded
-- App.config
-- Form1.cs
-- etc.
Here, it would be "FolderIAdded/blabla"
Where do I have to put that folder?
My goal: I want to be able to open files from that folder in my c#-code with a relative path.
You're assuming that your program runs in the directory where your source code is located. That's not the case. Depending on your configuration, your program will execute from a directory inside Solutionfolder\bin.
One possible solution is to copy the file(s) to the output directory when you build your project.
Another alternative is to embed the files into your application's assembly at compile time, although this precludes editing of them after deployment. To do that, set Build Action to 'Embedded Resource', then you can access them using the GetManifestResourceStream method of the Assembly class. The filename you need to give it will be derived from the path within the project structure, so in your example it would be "TheFolderIAdded.Filename.ext".
Yes, that's a dot, not a backslash.
Assuming the files are embedded in the same assembly the code that wants to read them is in, the code will look something like
var assembly = Assembly.GetExecutingAssembly();
using (var stream =
assembly.GetManifestResourceStream("TheFolderIAdded.Filename.ext"))
using (var reader = new StreamReader(stream)) {
string fileContents = reader.ReadToEnd();
}
I don't think it's a good idea to write relative path from .cs file. Better build the path base on where the application is executed:
One example, there are plenty other on the web: How can I get the application's path in a .NET console application?
(Your application is not running in the solution's root folder but where the .exe file is locatated. For example when you debug a desktop application, it runs typically from [solution folder]/bin/debug/ )
Then make sure the file you want to open property Copy to Output Directory is set to Copy Always or Copy if newer. (Right click on the file in your Solution Explorer and click on "Properties" to be sure to access it.)

Application Executable Path C#

I've added an executable to my Visual Studio 2010 C# Solution. In the properties of this executable, the executable path is a full path ("C:\Test\MyProgram\MyProgram.exe")
When I deploy my solution (with installshield) on a new PC, the executable is part of the deployed solution together with some source files and the solution file. So far so good.
But when I open the installed solution file (in Visual Studio 2010),
I'm not able to build it because It can't find the executable in the specified path:
("C:\Test\MyProgram\").
Here is the question: How can change the full path of the executable, so it gets the path of where the solution is installed on the new PC. Something like :
"[InstallDir]\MyProgram.exe"
Thanks
Update: I found out that you can use relative path in Application's Executable path. Thanks for all your answers.
You could use TargetDir property
I am just thinking off the top of my head here. There may be a much simpler way. I'm thinking you might want to create a Custom Action that runs at the end of your installer that manually opens the .xxproj file, and manually edits the path of the reference. As another poster stated, you can get the new path from the TargetDir property: http://msdn.microsoft.com/en-us/library/aa372064%28VS.85%29.aspx
Example of creating Custom Actions: http://msdn.microsoft.com/en-us/library/9cdb5eda(v=vs.80).aspx
Add your Executable to your Project TO The Main Dir, right click-> Copy To OutPutDirectory -> Copy
this is easiest way to make your file to copy to your target dir, and have your SourceControl Visual studio plugin manage it.
Your executable should be be somewhere in your project source files structure, perhaps in a subfolder. When you add this executable file to project it should then be added on a relative path which is what you want. If this is not happening you should manually edit csprj file. To do this, right click on project, unload it, right click again and edit project file.
Of course, your executable file should have its property Build Action set to None and Copy to output Directory to what you want.
If for some reason you cannot add this executable directly into your project files structure I'd suggest to use pre-build event to copy it from where it exists into your project files.

c#: config file in bin\debug folder

I kept getting errors in my log file that messageconfig file not found. It turned out that my application was expecting it in the bin\debug folder. What causes the application to expect so? It seems that when project is built it should copy the config file in bin\debug folder. Am i missing a certain project setting?
App/web.Config files are expected to be in the same directory as the application/web root.
Other, referenced config files may be in other directories, as specified in the main configuration file.
If you right click on the .config file, then on properties there is a Copy to Ouput Directory entry.
This should be set to either Copy if Newer or Copy always, if this is set to Do not copy, the .config will not by copied to the debug/release folder where it is expected.
Config files are expected to be in the same location as the executing assembly.
Check out this SO question:
.NET 2.0 Application Settings (user.config) file location
You could set the files build action to "Copy always"..
usually you only need the .exe. Try to clean and rebuild your project..
Hope it helps

Categories

Resources