tags:

views:

104

answers:

1

EXACT DUPLICATE of http://stackoverflow.com/questions/1576534/how-to-read-xml-data-from-a-url-by-using-vb-net-and-save/


Hi friends hope all r doing well. Regarding this question i got some suggestions, but how to implement is confusion. Can any one help to implement so that the problem can solve.

Try 
    Dim strUrl As String = "http://xyz" 
    Dim wr As HttpWebRequest = CType(WebRequest.Create(strUrl), HttpWebRequest) 
    Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse) 
    ws.ContentType = "UTF-8" 
    Dim str As Stream = ws.GetResponseStream() 
    Dim inBuf(100000) As Byte 
    Dim bytesToRead As Integer = CInt(inBuf.Length) 
    Dim bytesRead As Integer = 0 
    While bytesToRead > 0 
        Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead) 
        If n = 0 Then 
            Exit While 
        End If 
        bytesRead += n 
        bytesToRead -= n 
    End While 
    Dim fstr As New FileStream("c:/GetXml.xml", FileMode.OpenOrCreate, FileAccess.Write) 
    fstr.Write(inBuf, 0, bytesRead) 
    str.Close() 
    fstr.Close() 
Catch ex As WebException 
    Response.Write(ex.Message) 
End Try

I got following suggestion

public static void CopyStream(Stream input, Stream output) 
{ 
    byte[] buffer = new byte[8192]; 
    int bytesRead; 
    while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0) 
    { 
        output.Write(buffer, 0, bytesRead); 
    } 
}

Thanks in advance.

A: 

I answered your question before (http://stackoverflow.com/questions/1576534/how-to-read-xml-data-from-a-url-by-using-vb-net-and-save/1576729#1576729) - what is not good about this suggested approach??

This is in C#, but you should have no trouble converting that to VB.NET:

WebClient wc = new WebClient();
wc.DownloadFile("http://xyz", @"C:\getxml.xml");

and you're done!

Please don't ask the same question over and over and over again - wait for answers, read the answers.

Marc

marc_s
Thanks sir, but i went for another solution which is given in stream input and output.
pravakar
@marc_s, so can you ask for close this question, so we keep answering on previous one?
Rubens Farias
Yes sir with webclient file is downloading thanks a lot, yes we can go for previous one.
pravakar