Results 1 to 6 of 6

Thread: XML File Access

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Canada
    Posts
    106

    XML File Access

    Hi there;

    I'm writing an application and I need to modify an XML file on my web server. I have read through previous posts, and in one of them somebody suggested that the only way to do this is to download the XML file and then re-upload it. This is fine with me, except I have absolutely no idea how to re-upload it.

    I found this code earlier:
    Imports System.Net
    Imports System.Diagnostics
    ~~~
    Dim w As WebClient = New WebClient
    Dim p As Process = New Process
    Addy = source
    filen = target
    w.DownloadFile(Addy, filen)
    Which lets me download a file. I have also modified the code from http://vbforums.com/showthread.php?s=&threadid=251962 to let me load an XML file into a combo box.

    So... I can download the XML file into a combo box. That is easy. The reason I mentioned the first code snippet is because I am wondering whether it is easier to use the w.DownloadFile (or w.DownloadData?) and download the XML file to a directory, and then use the w.UploadFile or w.UploadData to put the updated XML file back on the server?

    Or:

    As long as I set write permissions oin the server, can I write directly back to the XML file?


    Thanks! (I hope I made sense! LOL)

    Sean

    P.S. My web server is Windows 2003, development environment is MS VS .NET Enterprise Architect

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    If the xml file is not too large you can use a DataSet.
    VB Code:
    1. Dim ds As New DataSet()
    2. ds.ReadXml("http://www.mysite.com/myfile.xml")
    3. 'do what you want with the data here
    4. ds.WriteXml(Server.MapPath(mypath))
    As long as I set write permissions oin the server, can I write directly back to the XML file?
    Yes. I did a similar app to track the visitors coming to my website with the .net framework installed. I used a xml file to store all the values that I wanted to know about, then a I used the code above to load it in a datagrid.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Canada
    Posts
    106
    Hi there.

    Thanks for the reply. I'm quite new to working with XML (literally just started using it last night!). Could you possible provide some example code?

    My XML file looks like this:

    <?xml version="1.0" ?>
    <chimaera>
    <servers>
    <host ip="172.16.1.30">0.99</host>
    </servers>
    </chimaera>
    I (obviously) want to modify the information currently set as 0.99. I'd like to do this (as I said) by the user typing a new value (i.e. 0.98 or 1.00 or etc.) into a textbox on a form and then click a button, and have it post the new value.

    Just so you know, I did try other methods. I found an ASP page which I put on my server which updates a value. But it caused me two problems; one, I had to generate an HTML page, which is just extra work (but I did do it...) and it also requires user interaction in a form before it will POST the data. So I'd obviously like a quicker method. I say all that because I don't want to seem like I haven't tried... I know I hate it when people come to ask me how to do something and they haven't even attempted to figure out how to do it......


    Thanks!

    Sean

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Here try this.
    Attached Files Attached Files

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Canada
    Posts
    106
    Thanks a bunch, DevGrp!!

  6. #6
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    No prob.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width