|
public void RenameSetting(string xPath, string newNode, string oldNode, string bladeName)
{
XmlDocument xmlDocument = new XmlDocument();
string documentPath = Application.StartupPath + "\\groupSettings.xml";
xmlDocument.Load(documentPath);
XmlNode xmlNode = xmlDocument.SelectSingleNode("settings/" + xPath);
XmlNode oldChild = xmlDocument.SelectSingleNode("settings/Groups/" + xmlNode.Name + "/" + oldNode);
XmlNode newChild = xmlDocument.SelectSingleNode("settings/Groups/" + xmlNode.Name + "/" + newNode);
PutSetting("Groups/" + xmlNode.Name + "/" + newNode + "/Name", bladeName);
PutSetting("Groups/" + xmlNode.Name + "/" + newNode + "/User", GetSetting(xPath + "/" + oldNode + "/User", ""));
PutSetting("Groups/" + xmlNode.Name + "/" + newNode + "/Host", GetSetting(xPath + "/" + oldNode + "/Host", ""));
xmlNode.RemoveChild(oldChild);
xmlDocument.Save(documentPath);
}
public void PutSetting(string xPath, string value)
{
XmlNode xmlNode = xmlDocument.SelectSingleNode("settings/" + xPath);
if (xmlNode == null) { xmlNode = createMissingNode("settings/" + xPath); }
xmlNode.InnerText = value;
xmlDocument.Save(documentPath);
}
I call RenameSettings like this:
RenameSetting("Groups/Group2", "Blade5", "Blade4", "Blade 5");
Here is my xmlDocument:
<settings>
<Groups>
<Group2>
<Blade4>
<Name>Blade 4</Name>
<User>k</User>
<Host>7</Host>
</Blade4>
</Group2>
</Groups>
</settings>
In short, I am trying to create a method that can rename my "settings/Groups/Group2/Blade4" to "settings/Groups/Group2/Blade5", my current method should copy everything from Blade4 to Blade5, then delete Blade4, but it throws the error:
the node to be removed is not a child of this node on
xmlNode.RemoveChild(oldChild); and as you can clearly see in the XML, Blade4 (which is oldChild) is most definitely a child of Group2. I assume I am defining oldChild wrong, but how else do you define it so it properly sees oldChild as a child of xmlNode?
modified 22-Sep-11 17:11pm.
|
|
|
|
|
I think your RenameSetting call should be:
RenameSetting("Group2", "Blade5", "Blade4", "Blade 5");
0100000101101110011001000111001011101001
modified 22-Sep-11 17:11pm.
|
|
|
|
|
Actually, wouldn't it be:
RenameSetting("Groups/Group2", "Blade5", "Blade4", "Blade 5");
?
That was just a slight error in my post of so....if you look at my XML though, the full path to Blade4 is: "settings/Groups/Group2/Blade4", if I call RenameSetting like you say I should, then wouldn't every instance of ("settings/" + xPath) resolve to "settings/Group2" which currently doesn't exist in my XML?
|
|
|
|
|
You are right of course.
Did you try debugging the code to see what the value of xmlNode.Name is?
You could also try replacing
XmlNode oldChild = xmlDocument.SelectSingleNode("settings/Groups/" + xmlNode.Name + "/" + oldNode);
with
XmlNode oldChild = xmlDocument.SelectSingleNode("settings/" + xPath + "/" + oldNode);
and see what happens.
0100000101101110011001000111001011101001
|
|
|
|
|
Yes, xmlNode.Name = Group2, exactly what you would expect it to be.
I tried replacing that line with your suggestion, but it didn't change anything....
An interesting thing through, if I break at the "XmlNode newChild" line, and examine "oldChild", it shows the ParentNode as "{Element, Name="Group2"}", which is exactly what you would expect, but then if I break again at "xmlNode.RemoveChild(oldChild);", "oldChild" shows a ParentNode of "null".....so somewhere between line 7 (initialize/define oldChild) and 12 (remove oldChild), oldChild loses its ParentNode attribute......which causes xmlNode to not see oldChild as a child node.
edit: oddly enough, if I examine xmlNode however, oldNode (which is equivilent to "Blade4") IS shown as a child node of xmlNode....yet if I define an XmlNode using my oldNode variable as part of the SelectSingleNode string, xmlNode does NOT see "Blade4" as a valid child node.
|
|
|
|
|
Seems like your PutSetting calls might be causing a problem.
If you comment out the RemoveChild statement, how does the xml file look?
0100000101101110011001000111001011101001
|
|
|
|
|
<settings>
<Groups>
<Group2>
<Blade4>
<Name>Blade 4</Name>
<User>k</User>
<Host>7</Host>
</Blade4>
<Blade5>
<Name>Blade 5</Name>
<User>k</User>
<Host>7</Host>
</Blade5>
</Group2>
</Groups>
</settings>
Exactly how you would expect it to look, Blade5 is added as an exact duplicate of Blade4, with the exception of the Name innertext changed to match the name change.
|
|
|
|
|
One more thing I can think of is to try is to get the setting of the old node and store them in variables and then first remove the old node and before finally creating the new node.
See what happens when you try it that way?
Also did you step through the code to find out at which point the oldChild node losses its parent?
0100000101101110011001000111001011101001
|
|
|
|
|
oldChild loses its parent as soon as I make the first call to PutSetting. I added a breakpoint to "XmlNode newChild", and all three PutSetting lines, the first breakpoint of PutSettings (breaks after XmlNode newChild is defined), oldChild still has its parent value, the second breakpoint of PutSettings (breaks after the first PutSettings line is called), and oldChild loses its parent.
So something with this line:
PutSetting("Groups/" + xmlNode.Name + "/" + newNode + "/Name", bladeName);
causes oldChild to lose its parent.
After trying your suggestion of assigning variables of the values in oldChild first, then deleting it before assigning the new node, and it seems to work fine, my XML after running it is:
<settings>
<Groups>
<Group2>
<Blade5>
<Name>Blade 5</Name>
<User>k</User>
<Host>7</Host>
</Blade5>
</Group2>
</Groups>
</settings>
Which is what I expected from the beginning. Still not sure why the PutSettings function causes a node that isn't even touched (oldChild) to lose its parent. Maybe its because it adds another child node to Group2, or more likely because it calls xmlDocument.save, which somehow causes oldChild to lose its parent (because now xmlNode and/or oldChild are no longer the latest value contained in xmlDocument?).
Meh, oh well......I don't like adding variables where I don't really need them, but it works fine for what I'm doing and they're only temporary anyway.
|
|
|
|
|
I am trying to add text to an existing pdf. I know that I can use a paragraph, phrase, or chunk, but I want to be able to specify a location on the pdf. I haven't been able to find any examples on how to do this. I'm trying to add a timestamp to the bottom of the first page when the new pdf is created.
|
|
|
|
|
|
|
On C#.net 2010 new in asp.net and desktop applications, I am suppose to have a 'type ahead' feature. Basically a user 'starts' to type a 'company name' in a text box, and then the application comes up with options on what the user is trying to enter. This way the user does not have to enter the entire company.
I do not know what this option occurs in C#.net 2010. Can you explain this to me and/or point me to a url that would explain this option to me?
|
|
|
|
|
googling Autocomplete textbox would yield a lot, including this[^]. HTH.
|
|
|
|
|
In a desktop application you can just set the AutoCompleteMode of the TextBox and then set the AutoCompleteSource to Custom and then set up the AutoCompleteCustom collection.
There is an ASP.Net AJAX control that will allow you to do this in ASP.Net: click[^]
|
|
|
|
|
Hello,
My aim is to show an animated loading icon beside the dropdownbox. When dropdownbox performs a postback the icon should appear and when it gets loaded completely, the icon should disappear. How can I succeed it in client side instead of in server side.
Would you please let me know how I can accomplish this.
Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
The easiest would be to display an animated gif[^] and then hid it once the load is completed. That way you will never need to worry about the animation, just that it is visible or not.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
First download animated gif:
- http://www.preloaders.net/[^]
- http://www.ajaxload.info/[^]
html:
<div id="divLoader" style="display:none;"><img alt="loading..." src="/images/loader.gif"/></div>
<asp:DropDownList ID="DropDownList1" runat="server" onclick="ShowHideLoader($('#divLoader'));">
</asp:DropDownList>
javascript/jQuery:
function ShowHideLoader( divLoader )
{
if($( divLoader ).is(':visible'))
$( divLoader ).hide();
else
$( divLoader ).show();
}
Hope that helps,
Morgs
|
|
|
|
|
This seems to be only a partial answer; how do you hide it again when the server acknowledges the postback? I'm not really sure how the ASP.net partial postback actually works, and although it's obviously using AJAX underneath, whether there is somewhere you can hang a JS event handler from that will tell you when the response comes back.
|
|
|
|
|
Hi there,
I made the function clever enough to do one of the possible two things.
I call the function "ShowHide" meaning it can show or hide the animated gif.
The function checks if the gif is visible and hides it otherwise shows it.
So, just call the same function to show or hide it, safe and sound.
Goodluck,
Morgs
|
|
|
|
|
Yes, but you only show how to call it on postback, not on postback response.
|
|
|
|
|
Hi,
I have a treeview with one root node. This node has some children.
The root not is a "TreeViewItemViewModel". This class contains : "ObservableCollection<TreeViewItemViewModel> Items" which are Children nodes.
At beginning, the root node is not expanded and "Children" is empty.
When I expand root node, I load data from DataBase in Children collection :
public override void LoadChildren()
{
this.Items.Clear();
List<Operation> lstOp = DataBAse.GetAllOperations();
foreach (Operation op in lstOp)
{
this.Items.Add(new TreeViewItemViewModel(op));
}
}
If I "unexpand" and expand the root node, I reload children...
public bool IsExpanded
{
get
{
return _isExpanded;
}
set
{
if (value != this._isExpanded)
{
this._isExpanded = value;
RaisePropertyChanged("IsExpanded");
if (this._isExpanded)
{
this.LoadChildren();
}
}
}
}
My issue : when I call "LoadChildren", Items list is cleared but viewmodel are always in memory...
Can someone help me ?
|
|
|
|
|
Of course the VM is in memory. It's the active object - that's what the this. reference indicates - it's the current instance. I'm not sure what you are expecting here.
|
|
|
|
|
My guess is that he refers to the TreeviewItemViewModels he adds to this.Items. That said, I still do not understand what he actually means with they being in memory. They will be garbage collected by the GC when no more references exists and when a the GC is triggered.
|
|
|
|
|
Gotcha. It was the singular of ViewModel that threw me there.
|
|
|
|