Saving images

Results 1 to 2 of 2

Thread: Saving images

  1. #1
    Join Date
    Dec 1969

    Default Saving images

    I would like to fetch an image from a website (using WebRequest) and then save it locally to hard disk. I can fetch the image and stream it to a variable, but how do I now save this to hard disk as an image?<BR><BR>Thanks

  2. #2
    Join Date
    Dec 1969

    Default RE: Check It

    May need tweaking, but here is the basc idea:<BR>_________________________________________ ________________________<BR><BR>using System;<BR>using System.Drawing;<BR>using System.Drawing.Imaging;<BR>using System.Web;<BR>using System.Web.SessionState;<BR>using System.Web.UI;<BR>using System.Web.UI.WebControls;<BR>using System.Web.UI.HtmlControls;<BR>using System.Net;<BR>using System.IO;<BR><BR>namespace CS_WebTest<BR>{<BR> /// &#060;summary&#062;<BR> /// Summary description for StealPic.<BR> /// &#060;/summary&#062;<BR> public class StealPic : System.Web.UI.Page<BR> {<BR> <BR> private System.Net.WebRequest m_webRequ;<BR> private System.Net.WebResponse m_webResp;<BR> private System.IO.Stream m_stream;<BR> private System.Drawing.Image m_image;<BR> <BR> private void Page_Load(object sender, System.EventArgs e)<BR> {<BR> stealIt("");<BR> }<BR><BR> private void stealIt(string url)<BR> {<BR> m_webRequ = WebRequest.Create(url);<BR> m_webResp = m_webRequ.GetResponse();<BR> m_stream = m_webResp.GetResponseStream();<BR> m_image = System.Drawing.Image.FromStream(m_stream);<BR> string fileName = "Images/" + System.Guid.NewGuid().ToString() + ".gif";<BR> m_image.Save(Server.MapPath(fileName));<BR> Response.Redirect(fileName);<BR> }<BR><BR> }<BR><BR>}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts