473,385 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Save Image From URL

Hey all I'm pretty new to .NET so this question may seem relatively
ignorant.
My question is that I have an Image Web Form object on my page that is
displaying an image from a URL.
I am having trouble figuring out how to convert it and saving it to disk.

Any directions/suggestions would be greatly appreciated. Thanks
Nov 15 '05 #1
2 50615
Hi, Josh!

Use this code to get the array of bytes of the image.

static public byte[] GetBytesFromUrl(string url)
{
byte[] b;
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
WebResponse myResp = myReq.GetResponse();

Stream stream = myResp.GetResponseStream();
//int i;
using (BinaryReader br = new BinaryReader(stream))
{
//i = (int)(stream.Length);
b = br.ReadBytes(500000);
br.Close();
}
myResp.Close();
return b;
}

And use the following code to save it to disk.

static public void WriteBytesToFile(string fileName, byte[] content)
{
FileStream fs = new FileStream(fileName, FileMode.Create);
BinaryWriter w = new BinaryWriter(fs);
try
{
w.Write(content);
}
finally
{
fs.Close();
w.Close();
}

}

Hope this helps.

Sam

"Josh Turpen" <jo*@nospam.com> wrote in message
news:Op**************@tk2msftngp13.phx.gbl...
Hey all I'm pretty new to .NET so this question may seem relatively
ignorant.
My question is that I have an Image Web Form object on my page that is
displaying an image from a URL.
I am having trouble figuring out how to convert it and saving it to disk.

Any directions/suggestions would be greatly appreciated. Thanks

Nov 15 '05 #2
Awsome Thanks It works like a charm!
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jack | last post by:
Hi. I wanted to save image from the form in my accss database. there is one picture box on form which loads the picture from the harddisk . i want this picture to store in my database .. thanks...
4
by: Hrvoje Vrbanc | last post by:
I would like to know the most efficient way to copy an image from an Internet URL to the local hard disk by means of using an ASP.NET page. So, I would like to click the button on the ASP.NET...
1
by: chandan | last post by:
Hi, I am in search of a control that can save image form my webpage. On that web page I am using my own context menu and I disabled the default context menu of IE. Now I want the same...
0
by: hnpatel | last post by:
hello friends, i m making application in vb.NET. i m using MY SQL 5.0 and vs 2005 for this application. Now I want to save image file in sql database. i m using blob datatype of image field. i...
6
by: Jerry Spence1 | last post by:
I am using a network camera that saves the image in a byte array in memory (via their ocx component, and in the OnNewImage event I can get the pointer to the image and the byte length as...
1
ranjana1980
by: ranjana1980 | last post by:
In my project of desktop application using c#.net save image in database during registration of student But it is not mandatory.Without Browse the image i click on insert button it gives error "Empty...
2
by: rajeshkumarswain | last post by:
hi friends, I am new in php and i am trying to save image to database. Please provide a sample.
3
by: regan2007 | last post by:
How are you going to save image in database using php?Please explain it if you do kno
1
by: sushant191 | last post by:
Hi Everyone , can any one tell me, how to save image url path in variable using fckeditor built-in image browser for ex.(~/userfiles/image1.jpg). I m not uploading image from outside fckeditor. Pls...
2
by: aznimah | last post by:
Hi, i need help on how to save the image that return from picturebox? basically the program works, 1)Read image (.png)--> load into pictureBox1 2)Fire button save to save the image from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.