KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to use a local c# app to pull some images off a website to files on my local machine. I'm using the code listed below. I've tried both ASCII encoding and UTF8 encoding but the final file is not an correct. Does anyone see what I'm doing wrong? The url is active and correct and show the image just fine when I put the address in my browser. private void button1_Click(object sender, EventArgs e) { HttpWebRequest lxRequest = (HttpWebRequest)WebRequest.Create("http://www.productimageswebsite.com/images/stock_jpgs/34891.jpg"); // returned values are returned as a stream, then read into a string String lsResponse = string.Empty; HttpWebResponse lxResponse = (HttpWebResponse)lxRequest.GetResponse(); using (StreamReader lxResponseStream = new StreamReader(lxResponse.GetResponseStream())) { lsResponse = lxResponseStream.ReadToEnd(); lxResponseStream.Close(); } byte[] lnByte = System.Text.UTF8Encoding.UTF8.GetBytes(lsResponse); System.IO.FileStream lxFS = new FileStream("34891.jpg", FileMode.Create); lxFS.Write(lnByte, 0, lnByte.Length); lxFS.Close(); MessageBox.Show("done"); }
Tags (comma-separated)
Save Edits
Cancel