Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Small XML/C# problem...

Small XML/C# problem...

Scheduled Pinned Locked Moved XML / XSL
csharphelpquestionasp-netxml
13 Posts 4 Posters 23 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eggie5
    wrote on last edited by
    #1

    Ok, so I've got this little C# app that updates my asp.net weblog. I plan on passing it on to other people I know, but then I came across a problem... The files are outputted to the "entries" folder (name by the year, month, day, hour, minute, but thats irrelivant...) located on my hard drive in... (the location is in bold below). So, my problem was that, what if they wanted to change the location of the entries folder... you know... export the files somewhere else on the hard drive. string fileName = DateTime.Now.ToString("yyyyMMdd_hhmm") + ".xml"; XmlTextWriter writer = new XmlTextWriter("**C:/inetpub/wwwroot/weblog/entries**/"+ fileName, null); SO, then I put togeather a little options form (options.cs) with a text box to enter the location on the drive, and then you click 'OK' and then it is saved to "options.xml". (see the code below...) private void buttonOK_Click(object sender, System.EventArgs e) { XmlTextWriter writer=new XmlTextWriter("options.xml", null); writer.Formatting=Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement("Options"); { string entryFile=textBoxEntryFile.Text; writer.WriteStartElement("entryFile"); writer.WriteString(entryFile); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); Form.ActiveForm.Close(); } This is what the options.xml file looks like.... ?xml version="1.0"?> C:\inetpub\wwwroot\weblog\entrys\ Now, I need this... XmlTextWriter writer = new XmlTextWriter("**C:/inetpub/wwwroot/weblog/entries**/"+ fileName, null); ...instead of saveing it evertime.... unconfigurable.... to "C:/inetpub/wwwroot/weblog/entries", but rather save the entries to what ever file it says in the "options.xml" file. WHEW!... i hope that made sense... im not familar with the XmlTextReader (assuming that what is to be used...) stuff... thanks for all the help possible. /\ |_ E X E GG

    J 1 Reply Last reply
    0
    • E eggie5

      Ok, so I've got this little C# app that updates my asp.net weblog. I plan on passing it on to other people I know, but then I came across a problem... The files are outputted to the "entries" folder (name by the year, month, day, hour, minute, but thats irrelivant...) located on my hard drive in... (the location is in bold below). So, my problem was that, what if they wanted to change the location of the entries folder... you know... export the files somewhere else on the hard drive. string fileName = DateTime.Now.ToString("yyyyMMdd_hhmm") + ".xml"; XmlTextWriter writer = new XmlTextWriter("**C:/inetpub/wwwroot/weblog/entries**/"+ fileName, null); SO, then I put togeather a little options form (options.cs) with a text box to enter the location on the drive, and then you click 'OK' and then it is saved to "options.xml". (see the code below...) private void buttonOK_Click(object sender, System.EventArgs e) { XmlTextWriter writer=new XmlTextWriter("options.xml", null); writer.Formatting=Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement("Options"); { string entryFile=textBoxEntryFile.Text; writer.WriteStartElement("entryFile"); writer.WriteString(entryFile); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); Form.ActiveForm.Close(); } This is what the options.xml file looks like.... ?xml version="1.0"?> C:\inetpub\wwwroot\weblog\entrys\ Now, I need this... XmlTextWriter writer = new XmlTextWriter("**C:/inetpub/wwwroot/weblog/entries**/"+ fileName, null); ...instead of saveing it evertime.... unconfigurable.... to "C:/inetpub/wwwroot/weblog/entries", but rather save the entries to what ever file it says in the "options.xml" file. WHEW!... i hope that made sense... im not familar with the XmlTextReader (assuming that what is to be used...) stuff... thanks for all the help possible. /\ |_ E X E GG

      J Offline
      J Offline
      J Dunlap
      wrote on last edited by
      #2

      So what do you not know about this? How to write it to XML?

      "Do unto others as you would have them do unto you." - Jesus
      "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

      E 1 Reply Last reply
      0
      • J J Dunlap

        So what do you not know about this? How to write it to XML?

        "Do unto others as you would have them do unto you." - Jesus
        "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

        E Offline
        E Offline
        eggie5
        wrote on last edited by
        #3

        uh... i want change the following code... XmlTextWriter writer = new XmlTextWriter("C:/inetpub/wwwroot/weblog/entries/"+ fileName, null); you see.... the bolded path... that's static... you can't change it, unless you edit the code in vs.net... Now, I want it to get the path from an xml file, I already made(options.xml)... it looks like this... <path>_path goes here_</path> do you think you can help? /\ |_ E X E GG

        J P 2 Replies Last reply
        0
        • E eggie5

          uh... i want change the following code... XmlTextWriter writer = new XmlTextWriter("C:/inetpub/wwwroot/weblog/entries/"+ fileName, null); you see.... the bolded path... that's static... you can't change it, unless you edit the code in vs.net... Now, I want it to get the path from an xml file, I already made(options.xml)... it looks like this... <path>_path goes here_</path> do you think you can help? /\ |_ E X E GG

          J Offline
          J Offline
          J Dunlap
          wrote on last edited by
          #4

          //load the doc
          //where url is the options.xml url
          private System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
          xml.Load("url");

          //get the xml path
          //where root is the root element
          System.Xml.XmlNode xmlnode = xml.SelectSingleNode("descendant::root/path");

          //open the file to write it
          XmlTextWriter writer = new XmlTextWriter(xmlnode.InnerText + fileName, null);

          "Do unto others as you would have them do unto you." - Jesus
          "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

          E 2 Replies Last reply
          0
          • J J Dunlap

            //load the doc
            //where url is the options.xml url
            private System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
            xml.Load("url");

            //get the xml path
            //where root is the root element
            System.Xml.XmlNode xmlnode = xml.SelectSingleNode("descendant::root/path");

            //open the file to write it
            XmlTextWriter writer = new XmlTextWriter(xmlnode.InnerText + fileName, null);

            "Do unto others as you would have them do unto you." - Jesus
            "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

            E Offline
            E Offline
            eggie5
            wrote on last edited by
            #5

            Is this right? //load the doc //where url is the options.xml url System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); xml.Load("C:/Documents and Settings/Alex Egg/Desktop/Visual Studio Projects/RecordTimesheets/bin/Debug/options.xml"); //get the xml path //where root is the root element System.Xml.XmlNode xmlnode = xml.SelectSingleNode("descendant::root/path"); //open the file to write it string fileName = DateTime.Now.ToString("yyyyMMdd_hhmm") + ".xml"; XmlTextWriter writer = new XmlTextWriter(xmlnode.InnerText + fileName, null); isim not sure what this is about ("descendant::root/path"); /\ |_ E X E GG

            J 1 Reply Last reply
            0
            • J J Dunlap

              //load the doc
              //where url is the options.xml url
              private System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
              xml.Load("url");

              //get the xml path
              //where root is the root element
              System.Xml.XmlNode xmlnode = xml.SelectSingleNode("descendant::root/path");

              //open the file to write it
              XmlTextWriter writer = new XmlTextWriter(xmlnode.InnerText + fileName, null);

              "Do unto others as you would have them do unto you." - Jesus
              "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

              E Offline
              E Offline
              eggie5
              wrote on last edited by
              #6

              I don't get this part.... //get the xml path //where root is the root element System.Xml.XmlNode xmlnode = xml.SelectSingleNode("descendant::root/path"); I don't know what to do with this... Would you elaborate on it more? Thanks. /\ |_ E X E GG

              1 Reply Last reply
              0
              • E eggie5

                Is this right? //load the doc //where url is the options.xml url System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); xml.Load("C:/Documents and Settings/Alex Egg/Desktop/Visual Studio Projects/RecordTimesheets/bin/Debug/options.xml"); //get the xml path //where root is the root element System.Xml.XmlNode xmlnode = xml.SelectSingleNode("descendant::root/path"); //open the file to write it string fileName = DateTime.Now.ToString("yyyyMMdd_hhmm") + ".xml"; XmlTextWriter writer = new XmlTextWriter(xmlnode.InnerText + fileName, null); isim not sure what this is about ("descendant::root/path"); /\ |_ E X E GG

                J Offline
                J Offline
                J Dunlap
                wrote on last edited by
                #7

                eggie5 wrote: xml.Load("C:/Documents and Settings/Alex Egg/Desktop/Visual Studio Projects/RecordTimesheets/bin/Debug/options.xml"); But then you are hard-coding this path. Maybe you can keep the XML file in the assembly path. eggie5 wrote: I don't get this part.... //get the xml path //where root is the root element System.Xml.XmlNode xmlnode = xml.SelectSingleNode("descendant::root/path"); here you are getting a node named "path" which is a child of the node named "root". The "descendant::" means you're starting from the top, and the path after "descendant::" specifies the path of the node you want to get.

                ***************[XML file section]*********************
                <root>
                <path>c:\somefolder\…</path> //<---we're getting this node
                </root>
                ***************[/XML file section]*********************

                "Do unto others as you would have them do unto you." - Jesus
                "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

                E P 2 Replies Last reply
                0
                • J J Dunlap

                  eggie5 wrote: xml.Load("C:/Documents and Settings/Alex Egg/Desktop/Visual Studio Projects/RecordTimesheets/bin/Debug/options.xml"); But then you are hard-coding this path. Maybe you can keep the XML file in the assembly path. eggie5 wrote: I don't get this part.... //get the xml path //where root is the root element System.Xml.XmlNode xmlnode = xml.SelectSingleNode("descendant::root/path"); here you are getting a node named "path" which is a child of the node named "root". The "descendant::" means you're starting from the top, and the path after "descendant::" specifies the path of the node you want to get.

                  ***************[XML file section]*********************
                  <root>
                  <path>c:\somefolder\…</path> //<---we're getting this node
                  </root>
                  ***************[/XML file section]*********************

                  "Do unto others as you would have them do unto you." - Jesus
                  "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

                  E Offline
                  E Offline
                  eggie5
                  wrote on last edited by
                  #8

                  For this.... xml.Load("C:/Documents and Settings/Alex Egg/Desktop/Visual Studio Projects/RecordTimesheets/bin/Debug/options.xml"); ...is what your saying, is that I should go like this... xml.Load("C:/Documents and Settings/Alex Egg/Desktop/Visual Studio Projects/RecordTimesheets/bin/Debug/"); Also, im confused about this still... //get the xml path //where root is the root element System.Xml.XmlNode xmlnode = xml.SelectSingleNode("descendant::root/path"); ... im confused as if im sopposed to fill something in here? Or do I just leave it as it is... my xml file looks like this.... <?xml version="1.0"?> <Options> <entryFile>C:\inetpub\wwwroot\weblog\entrys\</entryFile> </Options> uh... please feel free to fill in the info for me;P /\ |_ E X E GG

                  J 1 Reply Last reply
                  0
                  • E eggie5

                    For this.... xml.Load("C:/Documents and Settings/Alex Egg/Desktop/Visual Studio Projects/RecordTimesheets/bin/Debug/options.xml"); ...is what your saying, is that I should go like this... xml.Load("C:/Documents and Settings/Alex Egg/Desktop/Visual Studio Projects/RecordTimesheets/bin/Debug/"); Also, im confused about this still... //get the xml path //where root is the root element System.Xml.XmlNode xmlnode = xml.SelectSingleNode("descendant::root/path"); ... im confused as if im sopposed to fill something in here? Or do I just leave it as it is... my xml file looks like this.... <?xml version="1.0"?> <Options> <entryFile>C:\inetpub\wwwroot\weblog\entrys\</entryFile> </Options> uh... please feel free to fill in the info for me;P /\ |_ E X E GG

                    J Offline
                    J Offline
                    J Dunlap
                    wrote on last edited by
                    #9

                    //get the xml path
                    //where root is the root element
                    System.Xml.XmlNode xmlnode = xml.SelectSingleNode("descendant::Options/entryFile");

                    eggie5 wrote: ...is what your saying, is that I should go like this... I mean this:

                    xml.Load(Assembly.Location + @"\options.xml");

                    I'm off to bed - it's 'way late.

                    "Do unto others as you would have them do unto you." - Jesus
                    "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

                    1 Reply Last reply
                    0
                    • E eggie5

                      uh... i want change the following code... XmlTextWriter writer = new XmlTextWriter("C:/inetpub/wwwroot/weblog/entries/"+ fileName, null); you see.... the bolded path... that's static... you can't change it, unless you edit the code in vs.net... Now, I want it to get the path from an xml file, I already made(options.xml)... it looks like this... <path>_path goes here_</path> do you think you can help? /\ |_ E X E GG

                      P Offline
                      P Offline
                      Paul Watson
                      wrote on last edited by
                      #10

                      eggie5 wrote: you can't change it, unless you edit the code in vs.net... Now, I want it to get the path from an xml file, I already made(options.xml)... it looks like this... path goes here do you think you can help? Use App.config or web.config. That is what they are there for. If you users can edit an options.xml file then they are capable of editing a web.config file. Put an appkey into your .config file and then in your code use the AppSettings class to retrieve the value. You do not need to use the XmlTextReader or anything else as the AppSettings class encapsulates that for you already. Very handy. Don't re-invent the wheel with your own options.xml file, use what .NET provides :)

                      Paul Watson
                      Bluegrass
                      Cape Town, South Africa

                      brianwelsch wrote: I find my day goes by more smoothly if I never question other peoples fantasies. My own disturb me enough.

                      E 1 Reply Last reply
                      0
                      • P Paul Watson

                        eggie5 wrote: you can't change it, unless you edit the code in vs.net... Now, I want it to get the path from an xml file, I already made(options.xml)... it looks like this... path goes here do you think you can help? Use App.config or web.config. That is what they are there for. If you users can edit an options.xml file then they are capable of editing a web.config file. Put an appkey into your .config file and then in your code use the AppSettings class to retrieve the value. You do not need to use the XmlTextReader or anything else as the AppSettings class encapsulates that for you already. Very handy. Don't re-invent the wheel with your own options.xml file, use what .NET provides :)

                        Paul Watson
                        Bluegrass
                        Cape Town, South Africa

                        brianwelsch wrote: I find my day goes by more smoothly if I never question other peoples fantasies. My own disturb me enough.

                        E Offline
                        E Offline
                        eggie5
                        wrote on last edited by
                        #11

                        Are you the guy who lost you windows XP CD? I saw your post somewhere, where someone told you where to download the ISO from MSDN... where is it? /\ |_ E X E GG

                        P 1 Reply Last reply
                        0
                        • E eggie5

                          Are you the guy who lost you windows XP CD? I saw your post somewhere, where someone told you where to download the ISO from MSDN... where is it? /\ |_ E X E GG

                          P Offline
                          P Offline
                          Paul Watson
                          wrote on last edited by
                          #12

                          eggie5 wrote: Are you the guy who lost you windows XP CD? I saw your post somewhere, where someone told you where to download the ISO from MSDN... where is it? I sure am that guy :-D You know that horrible tree-nav on the left? You have to wait until it is fully loaded, you can tell it is fully loaded when it closes up and not everything is expanded. I generally leave the MSDN Subscribers Download page open in the background for about 10 minutes before I try and find what I want in that tree-nav. It is there, under Platforms.

                          Paul Watson
                          Bluegrass
                          Cape Town, South Africa

                          brianwelsch wrote: I find my day goes by more smoothly if I never question other peoples fantasies. My own disturb me enough.

                          1 Reply Last reply
                          0
                          • J J Dunlap

                            eggie5 wrote: xml.Load("C:/Documents and Settings/Alex Egg/Desktop/Visual Studio Projects/RecordTimesheets/bin/Debug/options.xml"); But then you are hard-coding this path. Maybe you can keep the XML file in the assembly path. eggie5 wrote: I don't get this part.... //get the xml path //where root is the root element System.Xml.XmlNode xmlnode = xml.SelectSingleNode("descendant::root/path"); here you are getting a node named "path" which is a child of the node named "root". The "descendant::" means you're starting from the top, and the path after "descendant::" specifies the path of the node you want to get.

                            ***************[XML file section]*********************
                            <root>
                            <path>c:\somefolder\…</path> //<---we're getting this node
                            </root>
                            ***************[/XML file section]*********************

                            "Do unto others as you would have them do unto you." - Jesus
                            "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

                            P Offline
                            P Offline
                            Philip Fitzsimons
                            wrote on last edited by
                            #13

                            you don't need System.Xml.XmlNode xmlnode = xml.SelectSingleNode("descendant::root/path"); use: System.Xml.XmlNode xmlnode = xml.SelectSingleNode("/options");


                            "When the only tool you have is a hammer, a sore thumb you will have."

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups