[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1135
  • Last Modified:

Save HttpWebResponse XML file to Local Computer

Hi,

I "get" (download) a XML file using the code listed below.

How can I save that to a local file? For the life of me I can't figure it out.

Thanks
Dim wr As HttpWebRequest = _
                CType(WebRequest.Create("http://thewebsite.com/thexmlfile.xml"), HttpWebRequest)
        Dim wrp As HttpWebResponse = CType(wr.GetResponse, HttpWebResponse)
        Dim s As Stream = wrp.GetResponseStream

Open in new window

0
ALawrence007
Asked:
ALawrence007
1 Solution
 
Snarf0001Commented:
Use streamreader and streamwriter objects
I use c# instead of VB, so forgive me if syntax is off a bit, but something like the following:

Dim wr as HttpWebRequest = HttpWebRequest.Create("http://thewebsite.com/thexmlfile.xml")
Dim wrp as HttpWebResponse = wr.GetResponse

Dim sr as StreamReader = new StreamReader(wrp.GetResponseStream)
Dim sw as StreamWriter = new StreamWriter("thelocalxmlfile.xml", false)
sw.Write(sr.ReadToEnd)
sr.Close
sw.Close
0
 
ALawrence007Author Commented:
Thanks Snarf0001!
Worked like a charm!
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Tackle projects and never again get stuck behind a technical roadblock.
Join Now