This question already has answers here:
Changing App.config at Runtime
(4 answers)
Closed 9 years ago.
So I was looking at the solution here to figure out how to do it. And, it works for when I run my project multiple times. However, from my understanding, the save only occurs when the project closes. What I would like to do is to save it when I need to during my code, so that during the same run time, I can accessed the previously saved files. Does anybody know how to approach this problem?
This is what I'm using to save my app settings at run time:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["CurrentPromoId"].Value = promo_id.ToString();
config.AppSettings.Settings["Date"].Value = DateTime.Today.ToString("yyyyMMdd");
config.Save(ConfigurationSaveMode.Modified, true);
What about RefreshSection?
ConfigurationManager.RefreshSection("appSettings");
Related
This question already has answers here:
Check if an executable exists in the Windows path
(8 answers)
Closed 3 years ago.
I am working on a WPF app, and I would like to include a button that directs it to another app. I would like it to have the following functionality:
If the app is installed on the user's computer, it opens the app for them.
If the app is not yet installed, it sends them to a link where they can download the app.
I know I will need to use Process.Start to open the app, but I am stuck on how to check if the app exists. If anyone could point me in the right direction it would be appreciated!
Two things you can use:
File.Exists(string) - Checks if the file exists.
try-catch - Simply try to open it, and handle any exceptions.
I would probably opt for the first solution...
This question already has answers here:
Why are persisted user settings not loaded?
(2 answers)
Closed 7 years ago.
I am working on a project and I need a kind of variable that save the value and after restarting the program, the value won't get refresh.
For example:
Home Page of a web browser that when you change it, it will save and after restarting the application, it won't reset to the first Home Page Address.
I thought that I can do it using application properties settings
Properties.Settings.Default.
But it didn't work.
If the setting is application wide, and not per user, you can use the AppConfig to store the value. A similiar question was asked here.
Sample code copied from Amol M Kulkarni:
Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
config.AppSettings.Settings.Add("YourKey", "YourValue");
config.Save(ConfigurationSaveMode.Minimal);
This question already has answers here:
Notification when a file changes?
(3 answers)
Closed 8 years ago.
I have inherited application that, among many other things, has to watch if user writes/deletes text file into specific folder.
Currently, the application uses timer and polls after 5 seconds. I find this ineffective, and wish to improve this part of code.
My question is about existence of the .NET function that monitors changes in directory. Is there such function I can use to detect when a file is written/deleted in a specified folder?
Thank you.
Yes, you have the FileSystemWatcher class. It does exactly what you're looking for
Yes there is. I would suggest you take a look at the FileSystemWatcher class:
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher%28v=vs.110%29.aspx
It's quite easy to set up, and it monitors for Win32 events, so is relatively inexpensive to use.
This question already has answers here:
Where does Windows store its "Open With" settings?
(3 answers)
Closed 9 years ago.
I have a little bit confusing problem. I'm not a beginner but I don't know how to do it..
For example I've written a program like notepad from which you can open files, save and etc. But when I set any custom format like ".blabla" to be opened by my app it is not working, so how can I make it to be opened by my app?
It is in WinForms
You need an entry in the registry for custom file extensions. You can try inserting a key in the registry as follows:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Prevent multiple instances of a given app in .NET?
How can I enforce a single instance of my application?
I have a source then complie to App.exe file. I want if App.exe is running, then a person open it again, it know that it is running and close automaticly. Is there any way to do this?
**Edit: I want a code that insert to source of App.exe
Window Form**
You want to use a Mutex, like so:
bool bIsSingleInstance;
using (new Mutex(true, Assembly.GetExecutingAssembly().GetName().Name, out bIsSingleInstance)) {
if (bIsSingleInstance) {
// START APP HERE.
}
}
Note that you must NOT use 'using' if your winforms isn't blocking in the comment block.