|
hpjchobbes wrote: Since there can be multiple elements in one document that have statusCodes, I would venture to say that I should use:
XmlNodeList myNodeList = myXMLDoc.SelectNodes("//@attributeIAmLookingFor");
foreach(XmlNode n in myNodeList)
{
// Check the value of the node 'n' to see if it != "0"
}
There you go my friend!
If your document uses XML namespaces, it can get hairy. In that case, you will have 2 choices:
1) Use the class XmlNamespaceManager in your calls to SelectNodes, if your XML document uses prefixes.
2) If it does not use prefixes, you will have to resort to fully-qualified XPath queries, like:
//@*[local-name()='attributeIAmLookingFor' and namespace-uri()='http://somenamespace.com']
This is an alternative XPath syntax. Also, from your example above, you could save some code:
//@*[local-name='attributeIAmLookingFor' and namespace-uri()='http://somenamespace.com' and number()!=0]
Have fun!
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
Evening guys,
Hopefully a quick question.
I am trying to iterate all sub directories within a folder using the DirectoryInfo.GetDirectories()
This isall fine until the search hits a directory that I do not have permisions for, unfortunately at this point an UnathorisedAccessException is thrown which is perfecty understandable.
What I would like to do is retrieve a list of directories that I do have permission for and ignore any that I don't.
Any ideas?
Many thanks
Paul
ps, what event is it thrown for the enter key on a text box??
Paul
|
|
|
|
|
Hi,
the only way that works for me is by using SearchOption.TopDirectoryOnly and performing the
recursion myself, with a try-catch inside the foreach that iterates over the subdirectories at
the current nesting level.
I see no real use for SearchOption.AllDirectories because of the possible exceptions it does
not handle well.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Sounds good, many thanks
Paul
|
|
|
|
|
pprice wrote: what event is it thrown for the enter key on a text box??
handle one of the text boxes Key Events and check the event args to see if the KeyCode is Keys.Enter
|
|
|
|
|
Kinda hoped there would be a more specific event that I did not know about, ho well, many thanks anyway
Paul
|
|
|
|
|
Hi,
I have a app that i want to embed in a ASP.net page but i dont know where to start. Does anyone have any articles or info on how to go about embedding a c# control on a asp page?
Regards,
Gareth.
|
|
|
|
|
Create it as a WebControl... Windows and the web don't use the same stuff, so you'll have to wrap the functional parts of the application with web stuff.
|
|
|
|
|
Jasmine2501,
Are you saying that i would need to re-create the whole app again using WebControls?, i dont quite understand what you mean by "wrap the functional parts".
I know this is possible, as a company i worked for used to embed c# windows controls in web pages, but i never worked on how they did it.
Regards,
Gareth.
|
|
|
|
|
I found this: http://aspnet.4guysfromrolla.com/articles/052604-1.aspx[^][^]
But am having trouble displaying the control, i just get a red x.
<object id="LoginControl" height="255" width="337" classid="http:UNet.Manager.dll#UNet.Manager.Login.LoginControl"><br />
<param name="LoginControl" value="LoginControl"><br />
</param></object>
Regards,
Gareth.
|
|
|
|
|
Solved it.
Regards,
Gareth.
|
|
|
|
|
FTA:
"Hosting a Windows Control in ASP.NET has several limitations worth discussing. First it requires both that the client machines have, at minimum, the .NET redistributable installed and be browsing with Internet Explorer 5.01 or later. While this may work for a corporate intranet, it is not feasible for a public Internet application."
That makes it worthless for me. I don't like to alienate the users smart enough to use Firefox.
|
|
|
|
|
Jasmine2501,
Well since i am developing a prototype which will only ever be used by 1 person, that point isn't valid.
Regards,
Gareth.
|
|
|
|
|
I want user to enter A-Z or 0-9 only. what's wrong with this
RegularExpressions.Regex reg = new RegularExpressions.Regex("[a-zA-Z0-9]");
if i enter :hello or _hello or !hello it says it's valid but its not
if (reg.IsMatch(textfield1.Text))
{
}
Thanks for helping me out in advance
|
|
|
|
|
You need to say that it must match at the begining and end with ^ and $ and you need to allow 1 or more matches with +
^[a-zA-Z0-9]+$
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I have a class class1, which has a constructor and one method:
public class1(TextReader tr)
{
InitFromTextReader(tr);
}
protected virtual bool InitFromTextReader(TextReader tr)
{
}
It has subclass class1_1 , which also has a subclass class1_1_1 .
These two classes both override InitFromTextReader .
The text stream I am reading has class names embedded in it, just before the data for the object. So I read the class name, get the Type object for it and ask for the constructor that takes a TextReader as it's one and only parameter.
GetConstructor is not finding that constructor for the subclasses. I used GetConstructors , and it just does not exist.
So, all that to ask:
Even though they do not do a dang thing, do I need to write constructors
public class1_1(TextReader tr)
: base(tr)
{
} and
public class1_1_1(TextReader tr)
: base(tr)
{
}
so that I can find them with GetConstructor ?
It this kind of thing wot causes unrest!
Learn to write self marginalizing code!
Call 1-888-BAD-CODE
|
|
|
|
|
Yes you would need to implement the constructors in your derived classes. The base constructor only constructs the base object. Really you don't need the InitFromTextReader because you should be able to perform the initialization in the constructors (which pass the TextReader to it's base class).
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thanks, I appreciate the quick response, but I was afraid of that.
I needed the InitFromTextReader anyway, as I do not just use it from the constructor.
So what it comes down to is you can not implicitly inherit a constructor's capabilities in c#:
To access the capability, you must override it to explicitly expose it, even if there is no other functionality added.
Learn to write self marginalizing code!
Call 1-888-BAD-CODE
|
|
|
|
|
Correct.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi,
I know how to resize one dimensional array,
Array.Resize(ref ArrayName, newSize)
But if my array is of 2 dimension, how can i resize to new 2 dimension ?
|
|
|
|
|
Is it a real two dimensional array or a jagged array?
two dimensional:
object [,] myArray = new object[X,Y];
jagged array
object [][] myArray = new object[X][];
foreach (object[] myObject in myArray)
{
myObject = new object[Y];
}
A two dimensional array is X * Y in size if you read the length, where an jagged array is just X with a Y value of each X.
|
|
|
|
|
thanks
My array is real two dimensional array.
string [,] = new string[2,4];
Now, I want to resize this array to new value of string[7,9] but I dont find any way to do this.
|
|
|
|
|
What you may need to do, ugly as it is, is create a new one of the new size, and copy it in.
Learn to write self marginalizing code!
Call 1-888-BAD-CODE
|
|
|
|
|
Oh, far as I'm aware that is what you HAVE to do for a multidimensional array.
Jagged array's are normally the "defacto" standard because of this...
I guess you could make something like this:
object[,] ResizeTwoDimArray(object[,] oldObject, uint x, uint y)
{
object[,] newObject = new object[x,y];
Array.Copy(oldObject,newObject,oldObject.Length);
return newObject;
}
|
|
|
|
|
You can't resize an array in .NET. The Array.Resize method creates a new array and copies the data to it.
That is what you have to do to resize a two dimensional array too, only there is no built in method for it so you have to do it yourself.
If you frequently resize the array, you should consider using a dynamic collection instead that actually supports resizing, like an list of arrays or a list of lists.
Experience is the sum of all the mistakes you have done.
|
|
|
|