|
How can I circulate through all controls on the form, know which one has a dynamic property, and save all changes to app.config?
In fact, how do I write to app.config in code in the first place?
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
There is no support for writing to a .config file like you can read from it in .NET. Being that it is just an XML file, you can use the classes in System.Xml to write to it.
I recommend you DO NOT save your controls to a .config file, though. This is meant for application settings, not necessary serialized content. In order to use the ConfigurationSettings mechanism in .NET effectively, you should also implement the IConfigurationSectionHandler interface so that you can get the configuration object easily using ConfigurationSettings.GetConfig . For a good article on extending this type of behavior, see Nick's article, An extension for a Configuration Settings class in .NET[^].
If you want to do what you need, you'd be better off using serialization. See the System.Xml.Serialization namespace for simple XML serialization, or the System.Runtime.Serialization for more advanced serialization, which probably wouldn't be necessary in your case. For more information on serialization in .NET, see Serializing Objects[^] in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
See the System.Xml.Serialization namespace for simple XML serialization...
Thank you very much, that was so helpful.
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
Hi,
We have all strings that were not auto-generated stored in special resource files.
I notticed that if the code refers to a non-existent resource string the compiler will not let you know about it, and you will find out things are not right until run time.
Do you know of a way to make the compiler tell me about the resource problems?
Thanks,
Elena
|
|
|
|
|
elena12345 wrote:
Do you know of a way to make the compiler tell me about the resource problems?
Code better
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Yeah, thanks a lot
I am just moving a bunch of code.
And a bunch of resource strings have to move from one file to another.
So I want to make sure I didn't leave anything out.
Don't tell me to architect better. I didn't architect this thing
Elena
|
|
|
|
|
You could have an external application use reflection on your assembly to check for completeness.
You could do something like create string contants in a certain namespace and have this program use reflection on that namespace to get each string constant. It could then use reflection to make sure the resources contain something named the same thing.
You could then make this "check" part of your build.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
The compiler (csc.exe in this case) doesn't care about resource files, just like the resource compiler (resgen.exe) doesn't care about source code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am trying to add a control in a panel from another thread than the on who created the panel.
So in this case I have to use the invoke method on the panel control to do that : this.Controls.Add(...).
My code is working very well on the framework, but with the same code, I have an Argument exception on the Compact Framework.
If Smbd has an id.
Thanks
|
|
|
|
|
MobileLover wrote:
If Smbd has an id.
Make sure the method you are calling via invoke is infact available on the compact framwork.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Yes it is a method written by me !
|
|
|
|
|
I wrote a Form that acts as a slightly more sophisicated MessageBox. The only thing I cant do is make my application wait for the user to make his selection and hit OK before continuing (sp?).
Please let me know if there is an easy way of doing this. Hopefully without sitting in a while loop waiting for a flag.
Thanks,
Matt
|
|
|
|
|
myform frm = new myfrm();
if(frm.Showdialog()==DialogResult.OK)
{
}
Mazy
"Improvisation is the touchstone of wit." - Molière
|
|
|
|
|
Looks like you beat me to it this time Mazy.
- Nick Parker My Blog
|
|
|
|
|
Nick Parker wrote:
Looks like you beat me to it this time Mazy.
Yah, I exercise a lot to beat competitor.
Mazy
"Improvisation is the touchstone of wit." - Molière
|
|
|
|
|
spindar wrote:
Please let me know if there is an easy way of doing this. Hopefully without sitting in a while loop waiting for a flag.
Have you looked into the DialogResult enum? You can do things like this (similar to how the MessageBox works):
Form2 fr = new Form2();
if(fr.ShowDialog().Equals(DialogResult.OK))
{
MessageBox.Show("Hey");
}
- Nick Parker My Blog
|
|
|
|
|
Thanks for the help and the fast response
Matt
|
|
|
|
|
Sorry for the basic post, but I have looked everywhere and I can't figure out if this is possible or not. I am wondering if it is possible to check and variable to see if it is between certain ranges of numbers using a switch statement.
Ex:
switch (int){
case (between 1 and 10):
case (between 11 and 20:
and so on. Let me know if know.
Jason
|
|
|
|
|
you can preprocess the number a bit beforehand like switch(int/10)
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Another way is to combine (encode) 2 numbers into 1 eg:
Required range: 22-63
int range = (22 << 16) + (63 & 0xFFFF);
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
This is one of those features that VB has that I wish C# supported. You can just add case statements for each of the values adding the break statement to the last case in the range
switch (value)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
DoSomething ();
break;
}
not pretty but it works.
|
|
|
|
|
I am not sure if this is in the right board, but i'll post anyway. I am looking for suggestions as to the best way of implementing the system for my company. These systems are completely new so there are no backward compatibility considerations.
The company currently has 10 clients (which is likely to rise rapidly) that need to connect to a SQL Server database to get a record, edit it on screen and return the results. The connection needs to be made in such a way that no 2 clients can get the same record. What I really need are some suggestions as to the best way of implementing this. I am quite new to C# and .net as a whole, so my current solution is to use an asp.net application which uses a web service to access a stored procedure. The stored procedure has the logic in it such that it will stop multiple gets of the same record.
I have been doing a little bit of research and have found that the same desired effect may be achieved with COM+ and MTS or using .net remoting. As I have experience with neither of these technologies I would be grateful for some pointers. The web service route works in my test environment, but I need a system that will be suitable of an ever increasing client base.
Jason Pyke
|
|
|
|
|
Hey man, I can't understand why do you want to go for ASP.NEt,web service or remoting? You can easily have a windows application which connect to a databse and do what ever they want. You can isolate recored too. What do you exactly mean by 2 client get same record? You could change your databse/code design to doing something like this, not go for rmoting,WS or...
Mazy
"Improvisation is the touchstone of wit." - Molière
|
|
|
|
|
The only reason I am using ASP.net is that it is possible in the future that the application may need to span sites. When I say 2 clients can't get the same record I mean that there will be a table containing records A,B and C and if 2 clients request a record at the same time client 1 will get record A and client 2 will get record B (client 1 and 2 can't have record A at the same time). Do you think it's worth creating a winforms application on a shared directory for this type of application? My main worries with a winform approach (with no data tier) are scalability and bug fixing (I have had a situation with a previous company where I have had 50 people accessing an app I am trying to compile).
|
|
|
|
|
Unlike Mazdak, I think you'd be well-off if you went with .NET technologies. They're here to stay and are very easy to change and code (decreased development times when you have people that understand .NET already, otherwise factor in your learning curve).
As far as your design, think carefully about what you want to expose as Web Services and what you want to expose as .NET Remoting objects. Web Services provide data, where .NET Remoting provides objects. Web Services are especially handy when providing access for unknown clients (like someone using Java, .NET, or any other SOAP clients). .NET Remoting - though it can use SOAP - is a complex structure that deals with instances of objects rather than just data (even though Web Services can serialize objects into SOAP and vice versa, they don't represent instances of objects - merely copies).
As far as using a client, ASP.NET and Windows Forms are both viable technologies. It's not uncommon for ASP.NET to make use of the same Web Services that external client would, even though they might have direct access to the same data. In cases where scalability is a concern, though, you might consider abstracting that data access layer so that the ASP.NET application and the Web Service (even if hosted in the ASP.NET application) use that to access the data. If you access the Web Services from ASP.NET, you take a performance hit for the serialization and setting up the proxies.
There are plenty of examples about using COM+ (already includes transactions, which negates the need for MTS unless you're talking about something else) from Remoting, and even some topics are included in the .NET Framework SDK, which you should read through (at least the topics and familiarize yourself with what's available in the base class library). MSDN[^] also includes a lot of examples and articles on this. I believe the CodeProject even has a few as well.
This is fairly common in .NET Remoting objects, because it exposes these proprietary technologies (COM+, MSMQ, etc.) to SOAP-compatible clients.
When designed properly, this should be very scalable, especially when using ASP.NET over traditional approaches like ASP or PHP. ASP.NET uses compiled objects; even the .ASPX pages are compiled when used for the first time, and using code-behind source files that must be compiled before publishing speeds things up - including debugging - considerably.
If you use .NET Remoting and Web Services, you can also create smart client applications that can be installed or launch from a URL. We currently have an application that does the latter and uses .NET Remoting. This leads me to warn you though that exposing .NET Remoting objects using IIS as the host automatically exposes them as Web Services - thereby requiring the HttpChannel be used, though you can still use either the binary or SOAP formatter.
I hope this helps.
Microsoft MVP, Visual C#
My Articles
|
|
|
|