|
This is the C# forum. You may want to ask this question in the C++/MFC forum, although I don't think you'll find anyone willing to do your homework. If you ask a specific question, you're likely to get a helpful reply.
/ravi
|
|
|
|
|
Hello,
1st, sorry for such a simple question...well maybe simple
I'm new to c# and especially xml.
I'm using an XmlTextReader to loop through an xml document,
using if statements to "stop" at certain nodes.
once I stop at certain nodes, I need to update one of the attributes.
How can I update a single attribute
while (CashReader.Read())
{
// Move to first element
CashReader.MoveToElement();
if (CashReader.Name == "Shopper")
{
CashReader.MoveToAttribute(i);
if (CTFReader.Value == frmLogin.vID)
{
i=2
CashReader.MoveToAttribute(i);
//I NEED TO UPDATE SHOPPER HERE
if (CashReader.Value == "")
{
//THIS IS WHERE I WANT TO INSERT THE CODE TO UPDATE THE ATTRIBUTE
CTFReader.Close();
thank you in advance for the help
JC
|
|
|
|
|
I suggest using an XmlDocument and its .Load method instead.
|
|
|
|
|
ok, but if I load the document then I
need to go to a certain location depending on the information a user enters in a textbox
I tried the below code, but I get an error
"The process cannot access the file 'file.xml' because it is being used by another process."
XmlDocument upd = new XmlDocument();
upd.Load("file.xml");
XmlAttribute AttrUpd = upd.CreateAttribute("value");
AttrUpd.Value = "35.00";
upd.Save(file.xml);
thanks
|
|
|
|
|
nyjcr wrote: XmlDocument upd = new XmlDocument();
upd.Load("file.xml");
XmlAttribute AttrUpd = upd.CreateAttribute("value");
AttrUpd.Value = "35.00";
upd.Save(file.xml); //THIS IS WHERE I GET THE ERROR
It works fine at my end. But your code won't add attribute. You are not appending the attribute to any of the node. So you don't find this attribute in the file. Use XPath or upd.GetElementsByTagName() to get node, and use node.Attributes.Apped() . Call Save() then.
|
|
|
|
|
Hello everyone, I'm new here, so I'll be making very dumb questions...but in a couple of months I will definitely be answering questions xD.
I have an issue with some code, but i don't know how to:
a) verify that the Request object is not null
b) then make sure that the length of the ServerVariables collection is greater than zero
I got the following error:
Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
Request information:
Request URL: http:
Request path: /Default.aspx
User host address: x.x.x.x
User:
Is authenticated: False
Authentication Type:
Thread account name: x\aspsqlhost
Thread information:
Thread ID: 4
Thread account name: x\aspsqlhost
Is impersonating: False
Stack trace: at _Default.Page_Load(Object sender, EventArgs e) in x:\x\x\x\Default.aspx.cs:line 40
And they recommend me this:
You could verify that the Request object is not null, then make sure that the length of the ServerVariables collection is greater than zero before trying to access a specific element of the collection.
here's the code:
if (!User.Identity.IsAuthenticated)<br />
{<br />
if (Request.ServerVariables["HTTPS"] == "on"
|| (Request.ServerVariables["HTTP_HOST"].Contains("localhost")))<br />
{<br />
bla bla bla;<br />
}<br />
}
|
|
|
|
|
Member 1850006 wrote: if (!User.Identity.IsAuthenticated)
{
if (Request.ServerVariables["HTTPS"] == "on" //LINE 40
|| (Request.ServerVariables["HTTP_HOST"].Contains("localhost")))
{
bla bla bla;
}
}
ServerVariables is null, check for it (I doubt this is the problem)
if(Request.ServerVariables != null &&
(Request.ServerVariables["HTTPS"] == "on"
|| (Request.ServerVariables["HTTP_HOST"].Contains("localhost"))))
What are you trying todo? We might need to see more of your code than just the few lines near the error
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
Basically that is the login page.
if the user has the certificate installed the page displays the login screen over https, if not, he is over http and asked to go to https.
|
|
|
|
|
|
I am trying to implement some UDP based network communication protocol.
It's error prone a a network sniffer will greatly help me understand wha't going on (sometimes I don't get any messages...)
I found this one which (unfortunately) works only on XP:
http://www.codeproject.com/KB/IP/CSNetworkSniffer.aspx
Thanks to it I was able to make my project go as far as receiving meaningfull server answer on XP.
However on Vista the server doesn't seems to answer me
(UDP being disconnected it's hard to know what's going on...)
Anyway, any tips on how to do packet sniffing on Vista???
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
|
Indeed:
http://www.wireshark.org[^]
Awesome product, thanks!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Super Lloyd wrote: Anyway, any tips on how to do packet sniffing on Vista???
I dont think you can run a sniffer in promiscuous mode under Vista. I had similar issues.
|
|
|
|
|
Churchill is right, http://www.wireshark.org do it all, and awesomely well!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
|
I am trying to separate my printing model into 3 classes. Each class knows how to print its own contents and I am passing a PrintDocument references to these 3 classes. It works fine if am going to print one page only but how can i define that i have more pages to print. I know I got to use e.HasMorePages but where can i define in my context of this model
public class Print
{
PrintDocument pd = new PrintDocument
DocumentHeader header = new DocumentHeader(pd, "header");
PrintContents pc = new PrintContents(pd, "Body, numberOfPages);
DocumentFooter footer= new DocumentFooter(pd,"Footer);
}
|
|
|
|
|
Hi
Please accept my apologies if this sound silly but I cannot find a solution to this.
I have a project I am converting to C# from VB. In VB I would do this.
Select Case Asc(UCase(Mid(strName, intPos, 1)))
Case 48 To 57
Let strNameSearch = strNameSearch & UCase(Mid(strName, intPos, 1))
Case 65 To 90, 193, 201, 205, 211, 218, 225, 233, 237, 243, 250
'some other code here
End Select
I have looked on the interweb and the only solution I have found is to use the switch statement like this
switch (statement that returns the ASCII value of the text)
{
case 48:
case 49:
case 50:
}
This does seem a bit convoluted so is there an easy way like with the To statement in vb? (a link to some advanced switching will be greatly received) How do I get the ASC value of a character. Alot of people are saying to do Convert.ToInt32(....) but this brings me back errors as I am using a for loop to iterate through a substring .
Your help is greatly appreciated.
The FoZ
|
|
|
|
|
Yes, there is no C# equivalent of VB's
Case 48 To 57 Best you can do inside a switch statement is
case 48:
case 49:
case 50:
etc.
But that sounds really ugly. (In fact, the VB solution sounds like an ugly hackery.)
A better option may be to utilize a table (such as a Dictionary<int, string> ) to map integer keys to string values or functions that produce string values. Tell us what you want to do, and we'll tell you a good way to do it.
TheFoZ wrote: Alot of people are saying to do Convert.ToInt32(....) but this brings me back errors as I am using a for loop to iterate through a substring.
char someChar = 'A';
int charValue = (int)someChar;
Life, family, faith: Give me a visit.
From my latest post: "A lot of Christians struggle, perhaps at a subconscious level, about the phrase "God of Israel". After all, Israel's God is the God of Judaism, is He not? And the God of Christianity is not the God of Judaism, right?"
Judah Himango
|
|
|
|
|
Thanks for the response. Do you have an example at all. What the function basically does is convert a string to an Upper Case string without any punctuation.
e.g
"This is a c# program!"
converts to
"THISISACPROGRAM"
Many thanks
The FoZ
|
|
|
|
|
Way easier way to do that using the latest version of C#:
string input = "This is a c# program!";
var newChars = from character in input
where !char.IsPunctuation(character) && !char.IsWhiteSpace(character)
select char.ToUpper(character);
string result = new string(newChars.ToArray());
Life, family, faith: Give me a visit.
From my latest post: "A lot of Christians struggle, perhaps at a subconscious level, about the phrase "God of Israel". After all, Israel's God is the God of Judaism, is He not? And the God of Christianity is not the God of Judaism, right?"
Judah Himango
|
|
|
|
|
Thanks for that.
As you said, the code is for the latest version of C# and I am using 2005. I came up with this that seems to do the job
public static string CVNameSearch(string inputStr)
{
int x;
string returnStr;
returnStr = "";
for (x = 0; x<= inputStr.Length -1; ++x)
{
if (char.IsLetter(inputStr, x))
{
returnStr += inputStr.Substring(x, 1).ToUpper();
}
}
return returnStr;
}
Thanks for your help today
The FoZ
|
|
|
|
|
Why not something simple, like this?
str = Regex.Replace(str, "[^A-Za-z]+", string.Empty).ToUpper();
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Nice cheers.
Don't suppose you could explain the syntax for me. I gather from the help that str is the input string, "[^A-Za-z]+" is the match but I'm not sure how it works. What is the string.Empty for?
Thanks for your help
The FoZ
|
|
|
|
|
[^A-Za-z]+<br /> Basically this is a regular expression pattern which matches:
[^]+ ==> any character that is not included inside the brackets
A-Z ==> matches any character in the range A to Z
a-z ==> matches any character in the range a to z
So basically it replaces an non-alphabetic character with string.Empty . string.Empty (or String.Empty or System.String.Empty ) are essentially the same as "" however when you reference them it does not create a new object but utilises one that's already been created, thus more memory efficient. A small difference but sometimes it matters.
|
|
|
|
|
Ed.Poore wrote: string.Empty (or String.Empty or System.String.Empty) are essentially the same as "" however when you reference them it does not create a new object but utilises one that's already been created, thus more memory efficient. A small difference but sometimes it matters.
The performance difference is really minimal, but there is another difference.
If you always use string.Empty when you want an empty string, the code gets clearer. If you happen to stumble upon a "" in the code, you know that there is supposed to be something between the quotation marks, that perhaps got erased or left out by mistake.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|