Edit App config file and then rebuild project to reflect changes - c#

Hi guys a project I'm working on has an app config file which determines what other dll's to load at runtime. I have been tasked with adding the functionality of taking the dll from our servers and then changing the app conifg to have the exe now load up with that file. The idea is the user at runtime will choose a file and then the app config will change and then restart the exe with the new dll loaded.
I couldnt seem to find exactly what I was looking for. We are using Visual Studio 2012 with .net 4.
How do you edit the app config file at runtime and then have the program close and rerun?

This might help with adding an exe file to your app.config file: http://msdn.microsoft.com/en-us/library/ms184658.aspx OR Add an EXE file to a project, so that it will be copied to the Bin/Debug folder just like a DLL?
As for closing and reopening the file: How do I restart my C# WinForm Application?
Should help in pointing you in the right direction anyway.

Related

Load Library From different Folder C#

I am new to C#, and I have a project which I have a built as a class library to check for updates before the app starts.
For the program to run this dll file should be in the same directory where the main app is, I want to change the directory of this dll file to be in a sub folder.
I have tried to change app.config file, but it started to cause runtime errors.
Is this possible?
If you import Updater Project into your main project, MsBuild compiles both of them together. And you won't need to deal with such complexities.
Honestly, ı couldn't understand what you tried to do. But above approach would solve your issue.

C# exe not working once installed to program files folder via Wix

I have a C# winforms application which will not work once installed to the C:/ProgramFiles folder. I use an MSI created with Wix to install. When either double clicking the exe or right clicking and running as admin this window pops up and then nothing happens:
Application Error Message:
The application works in Visual Studio and when accessed via the bin/Debug folder of my VS project (the exe in the Debug folder is the one I am using for the Wix install).
After the MSI installs, if I copy the exe out of
C:/ProgramFiles to one of my user folders (ex: C:/Users/User/Desktop) the exe works.
I am guessing this is some sort of UAC/permissions issue but I cannot find any documentation to confirm that theory. Any direction would be much appreciated.
EDIT:
Looking at the error log it is denying me access to my config file. Here is the error text:
Access to the path 'C:\Users\*username*\AppData\Roaming\Leer Copy\leerConfig.xml' is denied.
EDIT II:
This problem is getting more confusing (and frustrating). It will allow me to write to the AppData folder but not read from it (shouldn't it technically behave the other way around?)... Would really appreciate some help. I am reading the contents of my XML file via XDocument.
Originally had hid the config file so people do not mess with it/accidentally delete it. Making the file not hidden fixed the access denial and everything works how it should now.

How to set the current\working directory of a WPF application to the installation path

In my C# WPF application I need to access some configuration files via a 3rd party library. This library requires to have the configuration file located in the same folder as the executable of my application. So i have no chance to change this behaviour.
While running my application in Visual Studio 2013 it works fine. I can access the configuration file since I have just copied it to the relevant folder.
But if I install my application an run it it cant locate my configuration files because it tries to find it under: Windows\system32.
No my approach is to make it happen that my application looks for the configuration file in the applications install folder.
How can I do that? How can I set the current\working directory of my application to a specific (installation) path in Visual Studio 2013?
try this
string path = AppDomain.CurrentDomain.BaseDirectory.ToString();
This will give path like "c:\\program...\\installdir\\" where your .exe is located.

Where can i find an executable program once i have finished writing c# code

In visual basic class I learned where I could find the .exe file once the program was done and run at least once. Basically we could take the icon for the .exe file and place it on the desktop so that a user could just double click on the icon to run the program without needing to open the IDE or look at any code.
Where/how can i find this kind of file for c# code?
Go to the bin/Debug folder in the project. (or bin/Release if you're using the release build).
You can also go to your project settings, then to the build tab, and in the "Output" heading read/change the "Output Path" setting. This will let you output the exe to some other location, or just see where it is currently outputting in the event that it has already been changed on your machine.
Assuming you're using a web application project you'll use the .aspx file that is generated to access your silverlight application.
The "application" so to speak is actually a file ending in ".xap" that can be found in your web project's ClientBin directory.
The .xap file can also be found in the silvelright project's Bin
If you're wanting to install the silverlight application to a desktop you'll have to enable the ability to run the application "Out of Browser" and it'll have to be installed. More information on Out of Browser apps...

a Problem with Windows Help Button (EDIT-New problem)

a strange behavior happens when install the application and then run the exe file.
first let me explain my steps:
1) i added HelpProvidor and i set HelpNameSpace property to the chm file path.
2) in the form properties i set HelpNavigator on helpProvidor property to : KeywordIndex
and HelpString on HelpProvidor to Use ASGATech Quran Sound Downloder Help
3) i created an installation pkg. and it runs successfuly.
My problem is when i debug the application and presses on "?" (which is the help button) it displays the chm file.
but when i run the sortcut on the desktop which has been created from the installation package it doesn't.
why is that the HelpNamespce is the same. and the exe which is in the Application folder is that same so why is that.
the exe file is the same and also when i created a new item in start -> program menu the exe file that created runs the chm file but the shortcut doesn't.
i put the chm with the application folder which throws the application folder on:
c:\program Files\Manufacturer\ProductName
and it put the file on this path successfuly so why he can't see it.
EDIT:
i found that the problem is when i uninstall the application it keeps the product folder
it only removes the icon ans chm and so when u reinstall the application he dont feel the new state (that he has chm file)
now how could i remove the product file from programFiles.
Are you sure the exe file is the same?
It seems that either the help file is not found by your application or that the current security settings of IE prevent it from being loaded.
Use a tool like Procmon to see where your application is looking for the help file.
If it is not found make sure that it is included within your installer package.
If it is found make sure that it is on the local disc and that the default security settings for your local machine have not been changed within IE.

Categories