Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MemoryStream memStream;
- using (Stream response = request.GetResponseStream()) {
- memStream = new MemoryStream();
- byte[] buffer = new byte[1024];
- int byteCount;
- do {
- byteCount = stream.Read(buffer, 0, buffer.Length);
- memStream.Write(buffer, 0, byteCount);
- } while (byteCount > 0);
- }
- // If you're going to be reading from the stream afterwords you're going to want to seek back to the beginning.
- memStream.Seek(0, SeekOrigin.Begin);
- // Use memStream as required
- //Load response stream into XMLReader
- objXMLReader = new XmlTextReader(objResponseStream);
- //Declare XMLDocument
- XmlDocument xmldoc = new XmlDocument();
- xmldoc.Load(objXMLReader);
- //Set XMLResponse object returned from XMLReader
- XMLResponse = xmldoc;
- //Close XMLReader
- objXMLReader.Close();
- }
- //Close HttpWebResponse
- objHttpWebResponse.Close();
- }
- Dim request As WebRequest
- Dim response As WebResponse = Nothing
- Dim s As Stream = Nothing
- Dim fs As FileStream = Nothing
- Dim file As MemoryStream = Nothing
- Dim uri As New Uri(String.Format("http://forums.microsoft.com/forums/ShowPost.aspx?PostID=2992978&SiteID=1"))
- request = WebRequest.Create(uri)
- request.Timeout = 10000
- response = request.GetResponse
- s = response.GetResponseStream
- '2 - Receive file as memorystream
- Dim read(256) As Byte
- Dim count As Int32 = s.Read(read, 0, read.Length)
- File = New MemoryStream
- Do While (count > 0)
- File.Write(read, 0, count)
- count = s.Read(read, 0, read.Length)
- Loop
- File.Position = 0
- 'Close responsestream
- s.Close()
- response.Close()
- '3 - Save file
- fs = New FileStream("c:test.html", FileMode.CreateNew)
- count = file.Read(read, 0, read.Length)
- Do While (count > 0)
- fs.Write(read, 0, count)
- count = file.Read(read, 0, read.Length)
- Loop
- fs.Close()
- File.Close()
Add Comment
Please, Sign In to add comment