Click here to Skip to main content
16,004,944 members
Home / Discussions / C#
   

C#

 
AnswerRe: C sharp GUI help needed! Pin
BillWoodruff23-Sep-11 0:43
professionalBillWoodruff23-Sep-11 0:43 
AnswerRe: C sharp GUI help needed! Pin
Bernhard Hiller26-Sep-11 1:07
Bernhard Hiller26-Sep-11 1:07 
QuestionHow can we restrict a user from changing the download path url's fine name. Pin
Member 825992122-Sep-11 11:21
Member 825992122-Sep-11 11:21 
AnswerRe: How can we restrict a user from changing the download path url's fine name. Pin
André Kraak22-Sep-11 11:47
André Kraak22-Sep-11 11:47 
AnswerRe: How can we restrict a user from changing the download path url's fine name. Pin
ScottM122-Sep-11 21:08
ScottM122-Sep-11 21:08 
AnswerRe: How can we restrict a user from changing the download path url's fine name. Pin
Pete O'Hanlon22-Sep-11 22:26
mvePete O'Hanlon22-Sep-11 22:26 
AnswerRe: How can we restrict a user from changing the download path url's fine name. Pin
Matt Meyer23-Sep-11 3:06
Matt Meyer23-Sep-11 3:06 
QuestionXML node is not a child of this node.... Pin
mwpeck22-Sep-11 10:46
mwpeck22-Sep-11 10:46 
C#
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:
C#
RenameSetting("Groups/Group2", "Blade5", "Blade4", "Blade 5");


Here is my xmlDocument:
XML
<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.

AnswerRe: XML node is not a child of this node.... Pin
André Kraak22-Sep-11 11:05
André Kraak22-Sep-11 11:05 
GeneralRe: XML node is not a child of this node.... Pin
mwpeck22-Sep-11 11:14
mwpeck22-Sep-11 11:14 
GeneralRe: XML node is not a child of this node.... Pin
André Kraak22-Sep-11 11:32
André Kraak22-Sep-11 11:32 
GeneralRe: XML node is not a child of this node.... Pin
mwpeck22-Sep-11 11:51
mwpeck22-Sep-11 11:51 
GeneralRe: XML node is not a child of this node.... Pin
André Kraak22-Sep-11 12:12
André Kraak22-Sep-11 12:12 
GeneralRe: XML node is not a child of this node.... Pin
mwpeck22-Sep-11 12:18
mwpeck22-Sep-11 12:18 
GeneralRe: XML node is not a child of this node.... Pin
André Kraak22-Sep-11 12:32
André Kraak22-Sep-11 12:32 
GeneralRe: XML node is not a child of this node.... Pin
mwpeck22-Sep-11 12:50
mwpeck22-Sep-11 12:50 
QuestioniTextSharp specify text location Pin
kruegs3522-Sep-11 5:24
kruegs3522-Sep-11 5:24 
AnswerRe: iTextSharp specify text location Pin
André Kraak22-Sep-11 11:20
André Kraak22-Sep-11 11:20 
GeneralRe: iTextSharp specify text location Pin
kruegs3523-Sep-11 2:32
kruegs3523-Sep-11 2:32 
QuestionC#.net 2010 textbox Pin
dcof22-Sep-11 4:49
dcof22-Sep-11 4:49 
AnswerRe: C#.net 2010 textbox Pin
Luc Pattyn22-Sep-11 5:10
sitebuilderLuc Pattyn22-Sep-11 5:10 
AnswerRe: C#.net 2010 textbox Pin
ScottM122-Sep-11 21:23
ScottM122-Sep-11 21:23 
QuestionHow can I show an animated loding icon beside teh dropdown box when postback occurs. Pin
JUNEYT22-Sep-11 2:52
JUNEYT22-Sep-11 2:52 
AnswerRe: How can I show an animated loding icon beside teh dropdown box when postback occurs. Pin
Nagy Vilmos22-Sep-11 3:12
professionalNagy Vilmos22-Sep-11 3:12 
AnswerRe: How can I show an animated loding icon beside teh dropdown box when postback occurs. Pin
Morgs Morgan22-Sep-11 4:21
Morgs Morgan22-Sep-11 4:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.