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)
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
If the xml file is not too large you can use a DataSet.
VB Code:
Dim ds As New DataSet()
ds.ReadXml("http://www.mysite.com/myfile.xml")
'do what you want with the data here
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.
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......