.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

how to auto resize image then upload ?

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :Windows Application

how to auto resize image then upload??

any1 can help me?


below is my code:

 If FileUpload1.HasFile Then
                filename1 = FileUpload1.FileName
                savePath1 += filename1

                sSQL1 = "SELECT * from news order by PicID desc"
                conn1 = New SqlConnection(ConnStr)
                cmd1 = New SqlCommand(sSQL1, conn1)
                rd1 = cmd1.ExecuteReader()
                Dim n As Integer
                n = rd1.Item("PicID") + 1
                sSQL = "select * from news"
                conn = New SqlConnection(ConnStr)
                cmd = New SqlCommand(sSQL, conn)
                da = New SqlDataAdapter(cmd)
                cb = New SqlCommandBuilder(da)
                ds = New DataSet
                da.Fill(ds, "news")

                nrow = ds.Tables("news").NewRow()
                nrow("PicID") = n
                nrow("ImagePath") = "~/new/news_images/" + filename1
                nrow("Tittle") = tittle
                da.Update(ds, "news")

                FileUpload1.SaveAs(Server.MapPath("/new/news_images/" & filename1))
                lblmsg1.Text = "Image Upload Successful!"

View Complete Post

More Related Resource Links

Auto resize image width only


I have a question regarding the resizing of images.

My problem is that I would like to resize files that are being uploaded automatically. But I only want to resize the width.

Regarding the height of the file, this should auto adjust it self. Forexample; If I'm uploading a file that is 1000 px in width and 2000px in height and then resize it to 500px in width, then I want the height to be auto resized to 1000px. In other words the height and width has to be proportional. 

Could someone help me out on this. 

Thanks for reading. 

DetailsView Image Resize on Upload


I am using a details view to add a name and image path to a database. I have a template with a fileupload control and a dropdown list (landscape and portrait), that is used to get the file name. My question is: How can I resize the image based upon whether the image is landscape or portrait? This is my code so far:

<%@ Page Title="" Language="VB" MasterPageFile="~/Admin.master" AutoEventWireup="false" CodeFile="UploadGallery.aspx.vb" Inherits="Admin_UploadGallery" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<h1>NTTC Administration: Upload Pictures to Gallery</h1>
    <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="318px" 
        AutoGenerateRows="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" 
        DefaultMode="Insert" GridLines="None">
            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                ReadOnly="True" Sor

ASP.Net Upload Image to MS Access Database

As you learnt from the previous articles to upload image to the SQL Database in ASP.Net 2.0 and stream that image into the memory to retrieve it from the database and display it on the web page. In this article you will learn how to upload images to the MS Access database in ASP.Net 2.0

First of all create an Access Database and place it in the App_Data folder of ASP.Net web site project. Then create a table "tblImg" with the following fields:

Upload transparent PNG image


Hi everybody

I'm creating a website where it must  be able to upload, crop and resize images. This works until I use transparent PNG images. When I upload a transparent PNG, the transparency becomes black. I've searched the whole internet, but found no solution so far. Can someone help me? This is my code. I'm working with MVC 2.

			try {
				HttpPostedFileBase file = Request.Files["image"];
				file.SaveAs(Server.MapPath("/Uploads/" + file.FileName));

				ViewData["ImageLocation"] = "/Uploads/" + file.FileName;
				return View();
			catch (Exception exc) {
				return RedirectToAction("UploadImage");

Easy image processing(grayscale, sepia, negative, resize, brightness, contrast and opacity)

Howdie y'all,

I see a lot of questions in this forum about resizing images. Recently I created a code sample(with downloadable webapp), right here.

The class (downloaded or created) allows for very fast and easy processing of your images. And a lot of problems over here can be solved by simply using that class. I thought it might help to mention the code sample in this forum as well.



How to upload image in Mobile Application?


I have requirement to upload the image in mobile Web application using asp.net. For this I have add mobile templates but regarding to image there is no any file upload control. Then I see one article and use the below code:

<mobile:DeviceSpecific ID="DeviceSpecific1" Runat="server">
                <input style="width: 389px; height: 22px" type="file" size="45" runat="server" id="FileUpload1">

Need to upload images with data, but image url's are in separate db table

Hello, I'm making a simple homes classifieds section and when a home ad is created, a HomeID is automatically created for it in the db.  I need the images to upload and enter the associated HomeID with each image automatically.  What I tried isn't working, because it looks like it's looking for the HomeID in the codebehind before it gets entered into the db.ASPX CODE<asp:SqlDataSource ID="SqlDataSource1" runat="server"         ConnectionString="<%$ ConnectionStrings:ConnectionString %>"         InsertCommand="INSERT INTO [Homes] ([UserName], [Street], [Details], [Contact], [Phone], , [Thumb], [Price], [Approved], [Posted]) VALUES (@UserName, @Street, @Details, @Contact, @Phone, @Email, @Thumb, @Price, @Approved, @Posted)"         SelectCommand="SELECT [HomeID], [UserName], [Street], [Details], [Contact], [Phone], , [Thumb], [Price], [Approved], [Posted] FROM [Homes]" >        <InsertParameters>            <asp:Parameter Name="UserName" Type="String" />            <asp:Parameter Name="Street" Type="Str

Image upload not working in updatepanel

Hi, in my update panel i need to upload a image.my Fileupload control within update panel.so when i check is it correct format or not in following code then it always take else part. Dim fileUpload1 As FileUpload = CType(Me.FindControl("FileUpload1"), FileUpload)            'Make sure a file has been successfully uploaded            If fileUpload1.PostedFile Is Nothing OrElse String.IsNullOrEmpty(fileUpload1.PostedFile.FileName) OrElse fileUpload1.PostedFile.InputStream Is Nothing Then                Label1.Text = "Please Upload Valid picture file"                Exit Sub            End If            'Make sure we are dealing with a JPG or GIF file            Dim extension As String = System.IO.Path.GetExtension(fileUpload1.PostedFile.FileName).ToLower()            Dim MIMEType As String = Nothing            Select Case exte

Upload image to database - couldn't find file path

I'm trying to display images in a GridView (yes, still this...). [edit] Before I can come to that I have to upload some images to the database.I've followed this tutorial for the "upload image to database" code (this worked fine for uploading images, but I don't know if the images were converted to byte):http://aspsnippets.com/Articles/Save-Files-to-SQL-Server-Database-using-FileUpload-Control.aspxand I've followed this tutorial for the "display images in gridview" code (and "retrieve file" from the tutorial below).http://www.aspsnippets.com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspxIt doesn't quite work, the GridView shows but without imagesNow I'm trying to change the "save file" code according to this tutorial:http://aspsnippets.com/Articles/Save-and-Retrieve-Files-from-SQL-Server-Database-using-ASP.Net.aspxbut I don't understand everything in it. When I try to upload an image I get an error on this line:FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); //couldn't find file (path to image I tried to upload) What should I do about it?

rezise image on upload

Hi have the following method to upload images but I want to resize every image uploaded to 90x40 can anyone help me to edit this code so this will happen cheers   private string UploadFile(string pathToSave, FileUpload uploadfile)        {            string strFileName;            string strFilePath;            string strFolder;            string file_version = "";            strFolder = Server.MapPath("~/images/" + pathToSave);             // Retrieve the name of the file that is posted.            strFileName = uploadfile.PostedFile.FileName;            strFileName = Path.GetFileName(strFileName);             if (uploadfile.HasFile)            {                // Create the folder if it does no

Resize image

Hello, am writing code for upload image file and save it into disc ,,, during this and before save it to disc I want to resize the image into specified width and Heigh  am trying to use this code if (this.IsValid && this.FileUpload1.HasFile) { //Create an ImageElement to wrap up the uploaded image Neodynamic.WebControls.ImageDraw.ImageElement uploadedImage; uploadedImage = Neodynamic.WebControls.ImageDraw.ImageElement.FromBinary(this.FileUpload1.FileBytes); //Create Resize imaging action to apply on the uploaded image //NOTE: You may apply any of the ImageDraw built-in imaging actions Neodynamic.WebControls.ImageDraw.Resize actResize = new Neodynamic.WebControls.ImageDraw.Resize(); actResize.Width = 150; actResize.LockAspectRatio = Neodynamic.WebControls.ImageDraw.LockAspectRatio.WidthBased; uploadedImage.Actions.Add(actResize); //Composite the output image by using ImageDraw class Neodynamic.WebControls.ImageDraw.ImageDraw imgDraw = new Neodynamic.WebControls.ImageDraw.ImageDraw(); //Add uploaded image imgDraw.Elements.Add(uploadedImage); //Now, save the output image on disk string fileName = @"../images/" + System.IO

image resize according to user options

i want to provide user to select images to upload, maximum images is 4.the overall size is 1024px width and 500px height.within this 4 or 3 or 2 images will have to fit.if the user upload 4 images it has to calculate the overall width and height and resize the 4 images as equal width and height for each.if the user upload 2 images it has to calculate the overall width & height and fits.i want to do through code. iam using c# asp.netif any samples plz provide me.

Auto-generating Name When Saving an Image

hi guys, I have a toolbar on my chart:  <Toolbar Enabled="True"> <Items> <dcwc:CommandUIItem CommandName="PrintPreview" /> <dcwc:CommandUIItem CommandName="Print" /> <dcwc:CommandUIItem CommandName="Separator"/> <dcwc:CommandUIItem CommandName="SaveImage" /> <dcwc:CommandUIItem CommandName="Separator" /> <dcwc:CommandUIItem CommandName="UserDefined_1" /> </Items> </Toolbar>     For the SaveImage, I want to be able to set my image name with its own name. the name can be found using:   string fileName = Request.PhysicalApplicationPath + @"graphs\"+User.Identity.Name+graphID+".jpg"; Right now, when I click save, it always show chart.png And also, I want to download the chart as jpg.   thanks guys.

image upload????

in my project the client will upload his image that image should apper in the image box how can i do this???

resize image

Image img = Image.FromFile(this.tbPic1.Text.ToString()); Clipboard.SetImage(img); richtextbox1.SelectionStart = 0; rtbrichtextbox1Paste(); Clipboard.Clear(); i can insert picture to richtextbox,but how can i set the width and heigh of the picture before paste into richtextbox. one more question i would like to ask about image in MS Access Database how can i store the image into database using ODBC

Show image after upload at same time

I want to show uploaded image at same moment. I use this code: protected void FileUploadLaptop_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "size", "top.$get(\"" + lblErrorMessage.ClientID + "\").innerHTML = 'Uploaded size: " + FileUploadLaptop.FileBytes.Length.ToString() + "';", true); string savePath = MapPath("~/Uploads/" + System.IO.Path.GetFileName(e.filename)); FileUploadLaptop.SaveAs(savePath); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "image", "top.$get(\"" + imgLaptop.ClientID + "\").src = 'Uploads/" + System.IO.Path.GetFileName(e.filename) + "';", true); imgLaptop.ImageUrl = savePath; imgLaptop.DataBind(); } *** Picture upload to path but image control doesn't show it. what is wrong?

Rebind datalist after upload an image using jquery


Hi, I'm having a problem with using jquery to trigger a datalist rebind here, hope people here could help me with it. 

I'm using a jquery plugin called uploadify to upload images to my database. I'd like my datalist to be auto-rebind after the images' been uploaded so people could see the changes immediately. Also because this is a feature for admin there is a delete button in the datalist. I used updatePanel for this.  

I put __doPostBack('" + upnlUploaded.ClientID + "','') to the javascript so when Images have been uploaded the update panel will postback. 

I also have the following two lines to make it working... 

<asp:UpdatePanel ID="upnlUploaded" runat="server" UpdateMode="Conditional" OnLoad="upnlUploaded_Load"> <%--upnlUploaded_Load   --%>

       <asp:UpdatePanel ID="upnlUploaded" runat="server" UpdateMode="Conditional" OnLoad="upnlUploaded_Load"

        protected void upnlUploaded_Load(object sender, EventArgs e)
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend