Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6651779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:03:06+00:00 2026-05-26T01:03:06+00:00

I am using asp.net fileupload control for uploading image but here i want to

  • 0

I am using asp.net fileupload control for uploading image but here i want to automatically re size to 250*200px.
please suggest me what to add in my code.
I am a novice to asp.net.

protected void Button1_Click(object sender, EventArgs e)
        {   string s =@"~\img\"+FileUpload1.FileName;
            FileUpload1.PostedFile.SaveAs(Server.MapPath(s));


          }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:03:07+00:00Added an answer on May 26, 2026 at 1:03 am

    i also find this code useful for resizing

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.IO;
    using System.Data.SqlClient;
    using System.Drawing.Imaging;
    using System.Drawing.Drawing2D;
    using System.Drawing;
    
    public partial class ImageUpload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void btnUpload_Click(object sender, EventArgs e)
        {
    
            string ImageName = txtName.Text;
            if (FileUpLoad1.PostedFile != null && FileUpLoad1.PostedFile.FileName != null)
            {
    
                string strExtension = System.IO.Path.GetExtension(FileUpLoad1.FileName);
                if ((strExtension.ToUpper() == ".JPG") | (strExtension.ToUpper() == ".GIF"))
                {
                    // Resize Image Before Uploading to DataBase
                    FileUpload fi = new FileUpload();
                    fi = FileUpLoad1;
    
                    System.Drawing.Image imageToBeResized = System.Drawing.Image.FromStream( fi.PostedFile.InputStream);
                    int imageHeight = imageToBeResized.Height;
                    int imageWidth = imageToBeResized.Width;
                    int maxHeight = 120;
                    int maxWidth = 160;
                    imageHeight = (imageHeight * maxWidth) / imageWidth;
                    imageWidth = maxWidth;
    
                    if (imageHeight > maxHeight)
                    {
                        imageWidth = (imageWidth * maxHeight) / imageHeight;
                        imageHeight = maxHeight;
                    }
    
                    Bitmap bitmap = new Bitmap(imageToBeResized, imageWidth, imageHeight);
                    System.IO.MemoryStream stream = new MemoryStream();
                    bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    stream.Position = 0;
                    byte[] image = new byte[stream.Length + 1];
                    stream.Read(image, 0, image.Length);
    
                    // Create SQL Connection 
                    SqlConnection con = new SqlConnection();
                    con.ConnectionString = ConfigurationManager.ConnectionStrings["Return_AuthorizationsConnectionString"].ConnectionString;
    
                     SqlCommand cmd = new SqlCommand();
                    cmd.CommandText = "INSERT INTO Images(ImageName,Image) VALUES (@ImageName,@Image)";
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = con;
    
                    SqlParameter ImageName1 = new SqlParameter("@ImageName", SqlDbType.VarChar, 50);
                    ImageName1.Value = ImageName.ToString();
                    cmd.Parameters.Add(ImageName1);
    
                    SqlParameter UploadedImage = new SqlParameter("@Image", SqlDbType.Image, image.Length);
                    UploadedImage.Value = image;
                    cmd.Parameters.Add(UploadedImage);
                    con.Open();
                    int result = cmd.ExecuteNonQuery();
                    con.Close();
                    if (result > 0)
                        lblMessage.Text = "File Uploaded";
                   GridView1.DataBind();
                }
    
                }
    
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the type of file uploaded using the ASP.NET FileUpload control.
I want to validate asp FileUpload Control using in asp.net. That should accept only
I am using the fileupload control in asp.net. I want the browser to only
I am uploading a file using a simple FileUpload control named theFile (ASP.NET). I'm
I want to upload a file using FileUpload Control in asp.net and i'm using
I m using asp.net 2.0 without AJAX. The file path in the fileupload control
Greetings! I am using the ASP.NET FileUpload control to allow users to upload text
I know how to upload with ASP.net's FileUpload control. What I want to do
I have tried using the FileUpload control in ASP.net and found some strange problems.
I'm trying to use the FileUpload control in ASP.NET Here's my current namespace setup:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.