Convert images to Jpeg format

K

Kenneth Keeley

Hi,
I am creating a news and events page on my Intranet site and I wish to
allow people to upload an image with there news to my site. The text and
image are all stored in an SQL database. I have been successful in uploading
Jpeg files and downsampling them to a size that fits the web site. My next
challange is to convert other common file types (BMP, GIF, TIF) to jpegs as
well. Can this be done using the image object in ASP.net, if so could
somebody show me some sample code. Is it better if I just stop people from
uploading formats other than JPGs. If so can some body show me sample code
of how to stop the unwanted files from being uploaded.

Thanks
Kenneth
 
K

Kevin Spencer

Hi Kenneth,

Once you put any supported image type into an Image or Bitmap object, it is
easily converted to any other supported format, by using the parameters of
the Save method of the Image class.

To prevent files other than JPEGs from being uploaded, use some JavaScript
validation on the client to check the value attribute of the File Upload
element in the form. It will be a string containing the full path of the
file to be uploaded Use Path.GetExtension() to get the extension, and if it
isn't "jpg" don't allow the form to submit.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top