|
Those are two of the reasons I prefer the TryParse version. Unfortunately, it is only available in .NET 4.0 and above.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
hI,
This worked for me:
n1.n2.n3.enum = (n1.n2.n3.enum)Enum.Parse(typeof(n4.n5.n6.enum),stringval)
where n1..6 are name spaces where respective enums are defined.
Thanks for evryone's help.
|
|
|
|
|
You definitely shouldn't do that! If you have any differences between the two enums in the different namespaces, you will get bad results. The only reason it doesn't complain is that Enum.Parse returns an object, which can be cast to either type.
This is another reason why I prefer the TryParse method: It is strongly typed!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
It's actually simple enough to create one and put it in a utility class (or even an extension method, if you are in 3.5).
T TryParseEnum<T>(string s, T defaultValue){
try { return (T)Enum.Parse(typeof(T), s); }
catch(Exception) { return defaultValue; }
}
|
|
|
|
|
If the item list of the combobox is fixed and contains valid enum values only, then it is ok to do a direct cast of the SelectedItem.
enum Fruit { Quince, Gooseberry, Damson }
public void InitialiseControls() {
FruitComboBox.DataSource = Enum.GetValues(typeof(Fruit));
}
private void EatFruitBtn_Click(object sender, EventArgs e) {
Fruit yummy = (Fruit)FruitComboBox.SelectedItem;
}
Alan.
|
|
|
|
|
Hello experts,
I would like to ask how will I sync the data of 2 C# projects I created. I created a windows form application which use sql server 2005 express as its database and I also create an asp.net website that uses sql server 2005 express(The asp website and its database is uploaded to a hosting site).
Any comments or suggestions are kindly appreciated.
Thanks,
DAN
|
|
|
|
|
You best bet would be to create a WCF service that resides on your websites server. Then both Windows application and Website can access the same database, or the windows app could use it's own database, and only update the main database on the Webserver occasionally.
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
Hello,
Thanks for the immediate reply, I would like to ask again. If I create a wcf service in my asp.net website do I still need my windows form application database?
Thanks,
DAN
|
|
|
|
|
That would depend on your requirements. Personally, I like to use a separate database for the Windows application, which would be a local data cache, which can periodically update the main database. This way, if there are any connectivity problems with the Windows application, the users can still carry on.
Hope this helps.
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
Hello,
Thanks alot, got a big idea on what you said
I forgot that it might cause trouble if I use only the database of website.
Would you mine if you could give some link about wcf services for my asp.net website.
Thanks,
DAN
|
|
|
|
|
You could start with this MSDN article about Hosting and Consuming WCF Services[^]. I leave the rest to you. Good Luck.
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
I have created a class library called TestCOM.dll and build the solution successfully and even though I created the application in different directory, I just copied the dll and put it in C:\Meeram395\TestCOM.dll
Inorder to register the dll, I use the following command
regasm TestCom.dll /tlb:TestCom.tlb /codebase TestCom
I got the message that the dll registered successfully. When I tested in assembly folder, I couldn't see the assembly. So I used the following command again to register:
gacutil /i testCOM.dll
I got the message that "Assembly registered successfully in cache".
But still I am not able to see the same in assembly folder. Not sure what's happening.
When I try to unregister, I am getting an error message assembly file not found. But then, why it is giving successful message initially? Should i do something else.
Thanks in advance,
meeram395.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
Can you tell us what version of .Net the dll is compiled against, as .Net 4.0 assemblies get posted to C:\Windows\Microsoft.Net\assembly\GAC_MSIL, while earlier .Net dlls are still posted to assembly folder.
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
Ok. Thanks very much. I think I am using VS 2010, which is .Net 4.0. Let us confirm
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
Thanks a lot!!!! It's there in MSIL folder. A great help.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
It's a pleasure.
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
hello , read pst file and PST file and convert into DBX, Live, Thunderbird.
how I do this ,please help me
thanks in advance
modified on Thursday, April 14, 2011 6:39 AM
|
|
|
|
|
Well, you're going to have to understand the PST file format, completely. You can find the docs on it here[^].
Then you'll have to write your own object model to parse up and represent the parts of the PST file you want to handle. I figure, you've got about 6 months worth of work to do this.
No, there is no API to do this for you, that is, without installing Outlook.
Good Luck!
|
|
|
|
|
but how, give me some example
|
|
|
|
|
There's no way you're going to get an example. The project you've picked is HUGE. When I said you've got 6 months of work to do, I meant reading and understanding the file format. You haven't written a single line of code by then, other than small projects to test how you're going to do this.
If you can't write an object model to wrap a small binary file of you're own chosing and format, you've got not hope of completeing a project on the scale of an extremely complicated PST file.
There are no tutorials on this stuff and what you're asking would encompass entire books. That's FAR more information than you're ever going to receive in a few forum posts.
About the best information you're going to get that applies to what you want to do is by studying serialization and writing your own formatters. Google for "Binary Serialization" and start reading. Start experimenting with writing/reading binary files. Write you're own files, add information such as dates, times, data of your chosing, lists of things, whatever, ... Then write the code that's going to read that data and create objects out of it. If you can't do that, forget your requirement of not having Outlook installed.
|
|
|
|
|
If you're comfortable with C++, then have a review of this[^] and this[^]. And before you ask, no I can't convert this to C# for you - that would take me far too long.
|
|
|
|
|
And if i just find pst file and read it and also convert it into DBX, Live, Thunderbird.
how i do this . give me some example
|
|
|
|
|
situ21 wrote: how i do this
By writing code.
situ21 wrote: give me some example
No.
Did you even bother reading my reply where I told you I wasn't going to do it for you?
|
|
|
|
|
Instead of pleading for other people to tell you how to do it, you could have found these links[^] to get you started.
|
|
|
|
|
Hi,
I have a string 'Name' to be shown on auto-complete of Text-box, which is filled with company name from Data-Set. This field could be 5 characters long to 50 Characters long. I have do some string formatting, so that i could restrict its length to 20 characters.
so, as a result "Hello" will occupy 20 characters with rest as space:
"Hello "
Also, "ThereIsSomeTextHereInThisPost" will also occupy only 20 characters after trim as:
"ThereIsSomeTextHereI"
How do i achieve this in C# language.
Please reply. Thanks.
|
|
|
|
|