|
Hi guys
can any body tell me how can i write into app.config file through c# code, when i try to write through configurationmanager so it throws an exception saying that
"configuration is read only" why is that?
how can i do that?
thanks in advance
hello
|
|
|
|
|
The app.config file is just where things start. When you compile your application it becomes Exename.exe.config. You have to use something like this:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
To access your app config file and make changes to it. If you try to write to it directly you get the readonly error since the application is using it.
Hope that helps.
Ben
|
|
|
|
|
1) You can write only to "yourApplication.exe.config"
OR
2) Create a separate config file and write into it with
a) System.Configuration namespace members,
b) EnterpriseLibrary April 2007 edition (FileConfigurationSource...)
c) Raw XML code ( don't prefer )
3) Create a separate ApplicationSettingsProvider which overrides the current one and uses a file as a storage which implements SettingsProvider abstract class ( for example, LocalFileSettingsProvider )
Hope this helps...
|
|
|
|
|
Hi,
I'm building an app which has panels in both right and left side. For this i'm using splitcontainers.
The document of that app is then opened inside one panel of one of the splitcontainers. I open that form in a maximized form. But if i move the splitters (the one from the left, or the one from the right), the form doesnt get maximized.
What can i do to make it adapt automaticly to the new conditions?
Thx,
Nuno
|
|
|
|
|
Is the control that shows the document (fully) docked in the panel?
|
|
|
|
|
Yes.
In the form that will be the MDI i have the option WindowState = Maximized
Thx,
Nuno
|
|
|
|
|
Yes, but is the control docked in the panel?
|
|
|
|
|
I am writing automated tests for my project. As part of this I bring up a FolderBrowserDialog and need to close it programatically. But since the dialog is not derived from Windows.Forms and it is modal, I cant capture and close it.
Is there a way to do this?
|
|
|
|
|
Try P/Invoking.. FindWindow() and then do SendMessage()..
Cheers,
Suresh
|
|
|
|
|
I used the FindWindow and SendMessage combo and it worked.
Thanks a lot!!
|
|
|
|
|
Launch it from a thread and Abort the thread?
|
|
|
|
|
The following have either returned null or returned the Windows\System32 directory:
System.Windows.Forms.Application.ExecutablePath;
System.Reflection.GetExecutingAssembly();
System.Reflection.GetExecutingAssembly().CodePath;
Environment.CurrentDirectory;
Does anyone know anything that actually works?
|
|
|
|
|
I used AppDomain.CurrentDomain.BaseDirectory
|
|
|
|
|
System.Windows.Forms.Application.ExecutablePath; works for me.
Two other methods that may work:
System.Reflection.Assembly.GetCallingAssembly().Location <br />
System.Reflection.Assembly.GetExecutingAssembly().Location
|
|
|
|
|
Does it work for you when running a service??? Running a service is a unique situation because of how it is started and the context that it runs. I also listed all the ways that I succeed in getting null which includes your "other two methods".
|
|
|
|
|
Yes, I write services too, and I tested these within a service.
Actually two different services.
One is simple, with all the code in one executable.
The other is much more complex, with pieces in various DLLs, the actual service code is in a DLL that gets loaded dynamically through System.Reflection.Assembly.LoadFrom .
I don't know how much more complex yours could be.
|
|
|
|
|
Hi,
I wanted to catch two different types of exceptions in custom log file code. When the second instance of log file is trying to write while the first instance is still writing some message, C# is throwing IOException when the file is opened in Append and Share None mode.
When I try to access a folder which does not exists, in that case also compiler is throwing the same exception.
I tried with the following code:
try
{
FileStream fileWriter = File.Open(@"C:\Test\Test.log", FileMode.Append, FileAccess.Write, FileShare.None);
FileStream fileWriter1 = File.Open(@"C:\Test\Test.log", FileMode.Append, FileAccess.Write, FileShare.None);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Is there any way to catch those two scenarios with some unique identity?
Please advise in email to rajesh_a_kumar@dell.com
Thanks,
Rajesh
rajesh_a_kumar@dell.com
|
|
|
|
|
rajesh_kumar_24 wrote: When I try to access a folder which does not exists, in that case also compiler is throwing the same exception.
Why not check if the folder exists [System.IO.Directory.Exists(strPath);] rather than throwing an exception. If the folder doesn't exist, you can write to a log file to log the error.
rajesh_kumar_24 wrote: When the second instance of log file is trying to write while the first instance is still writing some message, C# is throwing IOException when the file is opened in Append and Share None mode.
Why not write a function to pass the string to be logged and the function will look after reading and writing to the file. Is there a reason you want to open 2 different filestreams?
|
|
|
|
|
Actually, I have 5 different components trying to use the log class. All 5 instances can try to write the message to log file at the same time. So, I want to keep rest of the 4 in waiting (loop) till 5th one completes its logging. I can control this loop and with the help of a static variable.
Can you please advise how to achieve this?
|
|
|
|
|
You should put a separate class for logging. The class will look after writing to the log file, every component/class in your code can create an instance of this class and log the details to it. I am actually writing an article on this and should be out in 2-3 days time. You can have a look at this article by Ravi Bhavnani[^]
|
|
|
|
|
Catch DirectoryNotFoundException and IOException.
---
single minded; short sighted; long gone;
|
|
|
|
|
Try:
catching (IOException ioex)
{
// Then do what Microsoft says as below for the IOException message class:
//The constructor initializes the Message property of the new instance to a system-supplied
// message that describes the error, such as "An I/O error occurred while performing the
// requested operation." This message takes into account the current system culture.
}
|
|
|
|
|
Does anyone know of a good tutorial for setting up a website for HIPAA compliance?
I'm developing a simple c# website for a friend who owns a small company based in the medical field. Now that his company is growing, he wants to allow his doctors to log into his website to view their patients' test results rather than having to snail mail out the test results every day.
This brings us to a rather delicate issue because even though it's just a few simple pages on the website to view this test result data, I think we're now into HIPAA compliance territory. Meaning we'll have to look at more secure (and expensive) measures than what is currently being performed. For example, I was looking at a web hosting service that provides .net hosting & shared sql server for $15/month. Will I now need to look into a $199/month dedicated server (which probably would cancel the project since, as I said, it's just a simple website with a few small simple features).
Thanks for any help on this.
-Goalie35
|
|
|
|
|
Goalie35 wrote: Will I now need to look into a $199/month dedicated server (which probably would cancel the project since, as I said, it's just a simple website with a few small simple features).
Yes, this will most like cancel the project. You're now getting into patient privacy and security issues that will make this "little" website prohibitively expensive to run. You may want to talk to an actual HIPPA consultant/lawyer, instead of a developer, to cover the legal issues of patient data privacy and what your requirements for compliance are.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Dave is spot on - HIPPA is no joke. If you don't have a few lawyers and compliance consultants looking over your stuff, you're asking for serious federal trouble.
It's not just protection of data in transit either - it's on-disk protection, display protection, portable-media protection, and view/modify/delete audit trails for all protected info. Giant insurance companies are spending millions just figuring out what they've got to do to be compliant - and they've got to follow the same rules your web site does.
"I hope he can see this, because I'm doing it as hard as I can" - Ignignot
|
|
|
|