0

EXACT DUPLICATE of 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.

1 Answer 1

0

I answered your question before (How to read XML data from a URL by using vb.NET and save) - 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

Sign up to request clarification or add additional context in comments.

3 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.