Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

Updating an XML file from a URL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joel - 21 Oct 2005 14:14 GMT
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()
Kevin Spencer - 21 Oct 2005 16:51 GMT
Try writing to a file location on the server instead of the RequestStream
coming from the browser.

Signature

HTH,

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

> Hi,
>
[quoted text clipped - 54 lines]
>    readStream.Write(byteArray, 0, postData.Length)
>    readStream.Close()
Joel - 21 Oct 2005 17:03 GMT
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.

> Try writing to a file location on the server instead of the RequestStream
> coming from the browser.
[quoted text clipped - 57 lines]
> >    readStream.Write(byteArray, 0, postData.Length)
> >    readStream.Close()
Kevin Spencer - 21 Oct 2005 19:41 GMT
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.

Signature

HTH,

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

>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
[quoted text clipped - 63 lines]
>> >    readStream.Write(byteArray, 0, postData.Length)
>> >    readStream.Close()

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.