Upload and resize an image with ASP.NET (VB.NET)

A while ago I needed to create a function to allow a user to upload an image and have the system resize it to a thumbnail – preserving the aspect ratio, while at the same time ensuring that neither of the maximum constraints of the thumbnail width or height where breached – and then save it to the server.The function had to be written for an ASP.NET server and ideally in VBScript to fit in with

24 Responses to “Upload and resize an image with ASP.NET (VB.NET)”

  1. Anonymous Says:

    This is an awesome script. However I cant get it to work in IE 6….but it works in firefox just fine. No errors just doesnt save the file to the server in IE 6????

  2. Rufan-Redi Says:

    hmmm. weird. I’ve tested the sample version (linked from the post) in IE6, IE7 and FF (and Safari as well) and not had any problem.<BR/>The version in the script is limited to 25kb uploads.<BR/>if you’re still stuck hop over to http://www.rufan-redi.com/contact.php and say Hi and I’ll see if we can track the problem down…

  3. Anonymous Says:

    Doesn’t work with animated gif’s😦

  4. Anonymous Says:

    Doesn’t work for me “Cant save file” error returned when I try to run example.<BR/><BR/>Regards,

  5. Rufan-Redi Says:

    @ previous comment… do you have write permissions on the server you’re trying to upload to? If the script isn’t allowed to write you’ll run into a problem😉

  6. Anonymous Says:

    Thank You! I’ve looked for over 5 hours for some nice code to only allow images to be uploaded. Thank you for your well thought out excellant code. You’re a star!

  7. Anonymous Says:

    I have a vb.net application accessing online DB and I need to upload an image thru vb.net(not to the DB). Is this possible and can anyone give me a sample code?

  8. Anonymous Says:

    Never worked for me.

  9. İstanbulgöz Hastanesi Says:

    This script is awesome.<BR/><BR/>But didnt work in update panel of ajax.<BR/><BR/>this script is work well in ie6 and ff and opera

  10. ??stanbulg??z Hastanesi Says:

    This script is awesome.&lt;BR/&gt;&lt;BR/&gt;But didnt work in update panel of ajax.&lt;BR/&gt;&lt;BR/&gt;this script is work well in ie6 and ff and opera

  11. otavio Says:

    Congratulations, great job!<BR/>But I think that this script has an error at line 33.<BR/><BR/>Current code:<BR/> If (originalImg.Width / Lx) > (originalImg.Width / Ly) Then<BR/><BR/>Revision:<BR/> If (originalImg.Width / Lx) > (originalImg.<B>Height</B> / Ly) Then<BR/><BR/>I hope it helps. See you!

  12. Anonymous Says:

    I agree with the previous posting…probably an error on line 33. Great job otherwise, will use it as a proof-of-concept that resizing a picture (either up or down) automatically can be done. Probably won’t end up as production code.

  13. Anonymous Says:

    Doesnt work for me…i get the following error:-<BR/><BR/>”Sorry, there was a problem saving the image.A generic error occurred in GDI+.”

  14. Anonymous Says:

    hey this is Manish<BR/>Thanks a ton for the script…. i seriously needed this script…. you have done a great job….<BR/><BR/>if there are other such codes using asp.net 2.0 vb i would love to go though it…..<BR/><BR/>i agree u r a star!!!

  15. bazeer Says:

    Fantasic code. Worked great. Thank you

  16. Anonymous Says:

    How about using a code-behind file instead of a script?

  17. Mitchy Says:

    i tried this but the file size of the resized images is still very large. i am resizing to 640×480 and most image file sizes are around 400k which is way too large. have you been able to resolve this?

  18. Mitchy Says:

    i resolved the problem by using the orignal images rawformat as you have done. this brought the file size down considerably. thanks for your help. great work.

  19. info Says:

    hi, nice script. could you pleaes explain how to get this working for multiple images? i have 15 image boxes. also, i need to keep the original filenames. is this possible? many thanks

  20. Anonymous Says:

    Amazing script. If you want to use within update panel you have to allow a full postback when you click the upload button; i.e., create a full postback trigger within the update panel using the upload button as the trigger.<BR/><BR/>Thanks again!<BR/><BR/>pcano@inducosoft.com

  21. darkform Says:

    hi.<BR/>Date of this post is September 07, 2005. And I’m writing on February 02, 2009. This script is fabulous. Thanks for sharing it. I’ll be using it in most of my projects. By the way, the only problem I got is the server mappath which is completely related with my own server/hosting. Check your mappath and directory permissions if you got any error. This should work for all using asp.net.

  22. Anonymous Says:

    I use this asp.net webcontrol:<BR/><BR/>http://i-load.radactive.com/en/<BR/><BR/>it saved me a lot of time.<BR/><BR/>Regards<BR/>Markus

  23. Hasan Says:

    I have an error:<br />A generic error occurred in GDI+.<br />System.Drawing<br />at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename, ImageFormat format) at ASP.at_ur_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in C:\WebSites\ur.aspx:line 65

  24. RRave Says:

    Invitation to new programming Resources Website<br /><br /><br /><br />Dear Sir,<br /><br />I hope you are doing well. I got this email address from one of your contribution web site. I have launched a web site http://www.codegain.com and it is basically aimed C#,JAVA,VB.NET,ASP.NET,AJAX,Sql Server,Oracle,WPF,WCF and etc resources, programming help, articles, code snippet, video demonstrations and

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: