|
You know... I completely overlooked using SerializableAttribute on the enums -- that's probably what the problem is. I'll try it and let you know.
Thank you for the suggestion.
- Clark
|
|
|
|
|
A dummy question,
How I could make a date difference, like VB's DateDiff???. There is a Compare method from DateTime, but don't allow specific the type of data, like years or months.
Anyone know how??
----
hxxbin
|
|
|
|
|
You mean:
DateTime.Now.Subtract(time1);
Mazy
"Improvisation is the touchstone of wit." - Molière
|
|
|
|
|
Peforming an operation on two DateTime values (like add and subtract) yield a TimeSpan , as well as using methods like Mazdak mentioned. See the documentation for TimeSpan in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi, I am not sure this is the right place to post my problem but I think
there are some people out there who can solve my newbie problem. I am
posting my source xml and the code file.
////////////////XML File///////////////
<?xml version="1.0"?>
<!-- a fragment of a book store inventory database -->
<bookstore xmlns:bk="urn:samples">
<book genre="novel" publicationdate="1992" bk:ISBN="1-861001-57-8">
<title>Pride And Prejudice</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>24.95</price>
</book>
<book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1">
<title>The Handmaid's Tale</title>
<author>
<first-name>Margaret</first-name>
<last-name>Atwood</last-name>
</author>
<price>29.95</price>
</book>
<book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6">
<title>Emma</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
<book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3">
<title>Sense and Sensibility</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
</bookstore>
////////////////Code File/////////////////
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
public class Sample
{
public static void Main()
{
XPathDocument doc = new XPathDocument("booksort2.xml");
XPathNavigator nav = doc.CreateNavigator();
//Select all books by Jane Austen.
XPathExpression expr;
expr = nav.Compile("descendant::book[@publicationdate='1992']");
//Sort the selected books by title.
expr.AddSort("@ISBN", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text);
//Display the selection.
XPathNodeIterator iterator = nav.Select(expr);
while (iterator.MoveNext())
{
XPathNavigator nav2 = iterator.Current.Clone();
nav2.MoveToFirstChild();
Console.WriteLine("Book ISBN: {0}", nav2.Value);
}
}
}
/*
I want an output like this:
//////////////////////////////////
Book ISBN: 1-861001-57-8
Book ISBN: 1-861002-30-1
//////////////////////////////////
But I get this???
//////////////////////////////////
Book ISBN: Pride And Prejudice
Book ISBN: The Handmaid's Tale
//////////////////////////////////
*/
Any help will be appreciated, Thanx
|
|
|
|
|
I'm not an expert on the XmlNavigator class (I usually just use SelectNodes and get a collection of XmlNodes), but I think I see your problem.
You're finding a bunch of book nodes, and then you're moving to the first child, expecting to find the ISBN. The first child (child node) of book is the title node. What you want is an attribute, and not a child (isbn is an attribute and not a child node).
Take a look at XmlNavigator.GetAttribute. I think that will allow you to get the ISBN.
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
|
|
|
|
|
Thank you it is because of my language I think I didn't know what the meaning of attribute... I changed the loop with the one below and it worked Thanx anyway...
while (iterator.MoveNext())
{
XPathNavigator nav2 = iterator.Current.Clone();
nav2.MoveToAttribute("ISBN", "urn:samples" );
Console.WriteLine("Book ISBN: {0}", nav2.Value);
}
|
|
|
|
|
Hello,
I remember the good old time with .rc files that the only thing that you have to do is a right click, an include of you resource and everything is visible and working for you project.
I read alot on resources in .NET but I cant beleave that this simplicity is gone! I have my .resources or .resX file created, everything work fine. The only think I need to do is compile my project with the:
/linkres:app.resources flag.
I never saw any place in VS where I can include this flag. Is this a joke that I need to do this in the command promp? I have a solution with 5 projects with 50 files, what a hell to do a working batch file for compilation. Any suggestion, help?
I can't beleave that at the .NET era we need to do this that way.
Thank alot for your time,
Salutations,
|
|
|
|
|
Maybe I'm not understanding your question, but I want to make sure you understand one thing.
From the VS IDE, you can add any type of files to your project and right click on it to bring up the properties. Normally a non-source file is set to "Content", but you can switch it to "Embedded Resource" to have it compiled into your assembly as a resource.
Is that what you're looking for?
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
|
|
|
|
|
Yes thank alot!!!
Salutations,
|
|
|
|
|
I have a prepackaged control that I must use on a project. The developers removed access to the double-click event and I need to add it back in without access to source code. Can I build some sort of wrapper function and enforce the double-click event there, or is there some hidden path that I must take to enable such an event? Thanks for any suggestions, and access to some sort of example would be doubly appreciated!
|
|
|
|
|
If it's not sealed, just extend it:
public class MyControl : PrePackagedControl
{
public event EventHandler DoubleClick;
protected virtual void OnDoubleClick(EventArgs e)
{
if (DoubleClick != null)
DoubleClick(this, e);
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath:
Thanks! This is so much simpler than everything I tried! No wonder I missed it, as I'm always making things harder than they need to be. Your help is greatly appreciated.
|
|
|
|
|
I would appreciate any help with the following situation:
I have a solution with two projects. The first project creates a .dll that is referenced by the second one, which contains some classes that derive from interfaces defined in the first .dll.
The problem is that in Visual Studio, when I try to compile the second project, I get an error saying that the first .dll does not have a strong name and because of this, I cannot derive my classes from its interfaces. In the real world, this .dll will be in the same directory than the executable, so there is no need to sign it. In Visual Studio, the first .dll is in a different directory and I cannot copy it to the /bin/debug folder because everything is removed from that directory when the second project is compiled...
Thanks in advance for your help.
|
|
|
|
|
A strong name assembly has a version and public key token, and you should always build assemblies as such in order to stick them in the GAC, enable assembly binding redirection (handle for upgrades), better code access security through simplified evidence, and much more!
Generate a key pair using
sn.exe -k KeyFile.snk Keep this somewhere safe. In your projects (presumably in the AssemblyInfo.cs file), add the path to that key file in the AssemblyKeyFileAttribute , or if you added it to a container using
sn.exe -i KeyFile.snk MyContainerName put that name in the AssemblyKeyNameAttribute .
Also make sure that the AssemblyVersionAttribute has a value, but I highly recommend both from lots of experience and from Microsoft's own recommendations not to use automatic versioning (via the asterisk) in multi-project solutions because versioning can get out of hand VERY quickly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have the following two code segments on different pages. On Page A (dlEvents) I get the following error "Object reference not set to an instance of an object." On Page B (dlCourseDetails) the code works fine. I have checked the control ID's to make sure they are correct. The data on the database is identical. Both pages have DataLists. In addition, I'm now having a similar problem casting a TextBox on another page. I'm stumped! Has anyone run into this? Does anyone know why it would work fine on one page and blow up on the other?
private void dlEvents_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)<br />
{<br />
Label lblPhone = (Label)(e.Item.FindControl("lblPhone"));<br />
if (lblPhone.Text.Length > 0) <br />
lblPhone.Text = string.Format("{0:(###)###-####}", double.Parse(lblPhone.Text));<br />
}
private void dlCourseDetails_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)<br />
{<br />
Label lblPhoneNumber = (Label)(e.Item.FindControl("lblCoursePhone"));<br />
if (lblPhoneNumber.Text.Length > 0) <br />
lblPhoneNumber.Text = string.Format("{0:(###)###-####}", double.Parse(lblPhoneNumber.Text));<br />
}
Thakns,
CDW
|
|
|
|
|
Typically means you are referencing an object that has not yet been created, was destroyed, is not (or no longer) accessible or is NULL ...
D.
|
|
|
|
|
However, the object is there. When are object bound to the page? Does this occur before the ItemDataBound or after? The binding should occur at the same time for both pages shouldn't it? I'm using the same code on both pages. It works fine on one page and not the other. Would binding work differently on the two pages?
Thanks
CDW
|
|
|
|
|
Unfortunately, I cannot give you that answer ... all I can suggest is to step through the debugger and look at the object you're trying to reference. You should be able to tell if it exists when you reference it.
I have discovered that often times, events are triggered when you least expect it, so you have to check for the existance of the object before you reference it.
D.
|
|
|
|
|
how do i set the install location for dll's in a merge module? the properties window does not contain a location. the dll's are installed in the application folder, when they should be installed in the windows\system32 directory.
|
|
|
|
|
If you are referring to an existing Merge Module (aka, one created for your use), then that information is already stored in the module itself.
In other words, if you're using the MSVCRT merge module in your installer, that merege module already contains the necessary pathing information to place the DLL in the correct location (in this case %windows%\System32).
D.
|
|
|
|
|
i am using the msvcrt merge module from c:\program files\common files\merge modules, but it is being installed in the application folder. any ideas?
|
|
|
|
|
No, since we cannot 'see' how the merge module is/was built. I suggest you just add the DLL to your installer and put it where you need/want it.
D.
|
|
|
|
|
Hi
I want to start programming in C#. I have access to the SharpDevelop tool but not Microsoft Visual Studio or anything like that. I come from a network admin background with very little coding experienece. I'm looking to develop a simple app that will help me with my day to day job, eg reboot server, scan access or check for old files etc... I know I could do this stuff with VB but just interested in learning C#. Taking into account the above does anyone have any books they can recommend?
Thanks
|
|
|
|
|
C# Unleashed is a good book. Covers the basics, Windows Forms, Controls, and Database access (including ADO and internet based development).
Also hit the C# code examples here on Code Project and read anything that's listed as "for a beginner" ... looking at code is one of the best ways to learn.
If you've not already, and I must assume you have, download the 1.1 .NET Framework SDK[^] from Microsoft and review all their C# code examples.
Hope that helps get you started ... Good-luck!
D.
|
|
|
|