473,325 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Updating an XML file from a URL

Hi,

I have an XML file at http://localhost/test.xml that I want to read and then
update.
I can get and read the file no problem with GetResponseStream etc...

The code (see 2 examples below) I am using to write the new xml to that same
location does not give me any error but the file never updates. When I open
the file from XMLSPY with Open URL ... I can read and update it.

Thanks for your help.

First example

Dim myRequest As HttpWebRequest =
CType(WebRequest.Create("http://localhost/test.xml"), HttpWebRequest)

myRequest.Method = "POST"
myRequest.PreAuthenticate = True
Dim networkCredential As New NetworkCredential("myName", "MyPassword",
"MyDomain")

myRequest.Credentials = networkCredential

' this one doesn't work either myRequest.ContentType =
"application/x-www-form-urlencoded"
myRequest.ContentType = "text/xml"

Dim newStream As Stream = myRequest.GetRequestStream()
Dim sw As New StreamWriter(newStream)
sw.Write("<test></test>")
sw.Flush()
sw.Close()

Second example

Dim myRequest As WebRequest =
HttpWebRequest.Create("http://localhost/test.xml")
myRequest.Method = "POST"
myRequest.ContentType = "text/xml"
myRequest.PreAuthenticate = True
Dim networkCredential As New NetworkCredential("myName", "myPassword",
"MyDomain")

myRequest.Credentials = networkCredential

Dim postData As String = "<test></test>"
Dim encoder As New ASCIIEncoding
Dim byteArray As Byte() = encoder.GetBytes(postData)
myRequest.ContentLength = byteArray.Length

Dim readStream As Stream = myRequest.GetRequestStream()

readStream.Write(byteArray, 0, postData.Length)
readStream.Close()

Nov 19 '05 #1
3 1437
Try writing to a file location on the server instead of the RequestStream
coming from the browser.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Joel" <Jo**@discussions.microsoft.com> wrote in message
news:CA**********************************@microsof t.com...
Hi,

I have an XML file at http://localhost/test.xml that I want to read and
then
update.
I can get and read the file no problem with GetResponseStream etc...

The code (see 2 examples below) I am using to write the new xml to that
same
location does not give me any error but the file never updates. When I
open
the file from XMLSPY with Open URL ... I can read and update it.

Thanks for your help.

First example

Dim myRequest As HttpWebRequest =
CType(WebRequest.Create("http://localhost/test.xml"), HttpWebRequest)

myRequest.Method = "POST"
myRequest.PreAuthenticate = True
Dim networkCredential As New NetworkCredential("myName", "MyPassword",
"MyDomain")

myRequest.Credentials = networkCredential

' this one doesn't work either myRequest.ContentType =
"application/x-www-form-urlencoded"
myRequest.ContentType = "text/xml"

Dim newStream As Stream = myRequest.GetRequestStream()
Dim sw As New StreamWriter(newStream)
sw.Write("<test></test>")
sw.Flush()
sw.Close()

Second example

Dim myRequest As WebRequest =
HttpWebRequest.Create("http://localhost/test.xml")
myRequest.Method = "POST"
myRequest.ContentType = "text/xml"
myRequest.PreAuthenticate = True
Dim networkCredential As New NetworkCredential("myName", "myPassword",
"MyDomain")

myRequest.Credentials = networkCredential

Dim postData As String = "<test></test>"
Dim encoder As New ASCIIEncoding
Dim byteArray As Byte() = encoder.GetBytes(postData)
myRequest.ContentLength = byteArray.Length

Dim readStream As Stream = myRequest.GetRequestStream()

readStream.Write(byteArray, 0, postData.Length)
readStream.Close()

Nov 19 '05 #2
I can try but I was testing this because I'm planning to access xml files
stored in a sharepoint document library and the link to those isn't a file
location.

"Kevin Spencer" wrote:
Try writing to a file location on the server instead of the RequestStream
coming from the browser.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Joel" <Jo**@discussions.microsoft.com> wrote in message
news:CA**********************************@microsof t.com...
Hi,

I have an XML file at http://localhost/test.xml that I want to read and
then
update.
I can get and read the file no problem with GetResponseStream etc...

The code (see 2 examples below) I am using to write the new xml to that
same
location does not give me any error but the file never updates. When I
open
the file from XMLSPY with Open URL ... I can read and update it.

Thanks for your help.

First example

Dim myRequest As HttpWebRequest =
CType(WebRequest.Create("http://localhost/test.xml"), HttpWebRequest)

myRequest.Method = "POST"
myRequest.PreAuthenticate = True
Dim networkCredential As New NetworkCredential("myName", "MyPassword",
"MyDomain")

myRequest.Credentials = networkCredential

' this one doesn't work either myRequest.ContentType =
"application/x-www-form-urlencoded"
myRequest.ContentType = "text/xml"

Dim newStream As Stream = myRequest.GetRequestStream()
Dim sw As New StreamWriter(newStream)
sw.Write("<test></test>")
sw.Flush()
sw.Close()

Second example

Dim myRequest As WebRequest =
HttpWebRequest.Create("http://localhost/test.xml")
myRequest.Method = "POST"
myRequest.ContentType = "text/xml"
myRequest.PreAuthenticate = True
Dim networkCredential As New NetworkCredential("myName", "myPassword",
"MyDomain")

myRequest.Credentials = networkCredential

Dim postData As String = "<test></test>"
Dim encoder As New ASCIIEncoding
Dim byteArray As Byte() = encoder.GetBytes(postData)
myRequest.ContentLength = byteArray.Length

Dim readStream As Stream = myRequest.GetRequestStream()

readStream.Write(byteArray, 0, postData.Length)
readStream.Close()


Nov 19 '05 #3
Well, the Request Stream isn't a file location either. Worse, you can't
write to it. It's like an email that you receive. You can't write a reply to
an email by opening the email and writing into it. You have to send an email
reply. Request is one way. So is Response (the other way). If these files
are in a SharePoint document library, I suggest you use the SharePoint
services API to replace them. Otherwise, you'll be in worse trouble than you
are now, because you'll break your SharePoint Services.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Joel" <Jo**@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
I can try but I was testing this because I'm planning to access xml files
stored in a sharepoint document library and the link to those isn't a file
location.

"Kevin Spencer" wrote:
Try writing to a file location on the server instead of the RequestStream
coming from the browser.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Joel" <Jo**@discussions.microsoft.com> wrote in message
news:CA**********************************@microsof t.com...
> Hi,
>
> I have an XML file at http://localhost/test.xml that I want to read and
> then
> update.
> I can get and read the file no problem with GetResponseStream etc...
>
> The code (see 2 examples below) I am using to write the new xml to that
> same
> location does not give me any error but the file never updates. When I
> open
> the file from XMLSPY with Open URL ... I can read and update it.
>
> Thanks for your help.
>
> First example
>
> Dim myRequest As HttpWebRequest =
> CType(WebRequest.Create("http://localhost/test.xml"), HttpWebRequest)
>
> myRequest.Method = "POST"
> myRequest.PreAuthenticate = True
> Dim networkCredential As New NetworkCredential("myName",
> "MyPassword",
> "MyDomain")
>
> myRequest.Credentials = networkCredential
>
> ' this one doesn't work either myRequest.ContentType =
> "application/x-www-form-urlencoded"
> myRequest.ContentType = "text/xml"
>
> Dim newStream As Stream = myRequest.GetRequestStream()
> Dim sw As New StreamWriter(newStream)
> sw.Write("<test></test>")
> sw.Flush()
> sw.Close()
>
> Second example
>
> Dim myRequest As WebRequest =
> HttpWebRequest.Create("http://localhost/test.xml")
> myRequest.Method = "POST"
> myRequest.ContentType = "text/xml"
> myRequest.PreAuthenticate = True
> Dim networkCredential As New NetworkCredential("myName",
> "myPassword",
> "MyDomain")
>
> myRequest.Credentials = networkCredential
>
> Dim postData As String = "<test></test>"
> Dim encoder As New ASCIIEncoding
> Dim byteArray As Byte() = encoder.GetBytes(postData)
> myRequest.ContentLength = byteArray.Length
>
> Dim readStream As Stream = myRequest.GetRequestStream()
>
> readStream.Write(byteArray, 0, postData.Length)
> readStream.Close()
>


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
45
by: It's me | last post by:
I am new to the Python language. How do I do something like this: I know that a = 3 y = "a" print eval(y)
6
by: Hennie de Nooijer | last post by:
Hi, Currently we're a building a metadatadriven datawarehouse in SQL Server 2000. We're investigating the possibility of the updating tables with enormeous number of updates and insert and the...
1
by: Luis Esteban Valencia | last post by:
Hello Everyone, Iam an intermediate ASP.Net programmer and iam facing a challenging task. I have a table in MS-SQL server database called 'Members'. The table has following fields... ...
14
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
6
by: muttu2244 | last post by:
hi all am updating the same file in ftp, through multiple clients, but am scared that two clients may open the same file at a time, and try updating, then the data updated by one data will be...
2
by: Alexey.Murin | last post by:
The application we are developing uses MS Access 2003 database (with help of ADO). We have noticed that during massive records updating the size of the mdb file increases dramatically (from 3-4 to...
4
by: rdemyan via AccessMonster.com | last post by:
My application is calculation intensive and the servers are agonizingly slow. Administrators of my application only update the backends once a month (twice a month max). So, my launching program...
3
by: Evan | last post by:
Hello - My script use a DB file which is written by XML, and the user load this DB file (XML tree in memory), and then do some updating about this tree, such as delete element, generate new...
16
by: Stevo | last post by:
I'm guessing this is a laughably obvious answer to many here, but it's not to me (and I don't have a server or any knowledge of PHP to be able to try it). It's not strictly a PHP question, but...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.