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 7502471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:53:07+00:00 2026-05-29T20:53:07+00:00

I use following code to resize the image after i upload it. function re-sizes

  • 0

I use following code to resize the image after i upload it. function re-sizes the images
and save them with new name without changing the file extension and image are displayed perfectly on all major browsers.

Problem is only when some one download the image and try’s opens it with any image editor like Fireworks or Photoshop it will then give following error

ERROR: *Could not open the file. Unknown file type.*

I am not sure why it give that error.

Function to resize image.

    public static void ResizeImageInput(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
    {
        System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile);
        // Prevent using images internal thumbnail
        FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
        FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
        if (OnlyResizeIfWider)
        {
            if (FullsizeImage.Width <= NewWidth)
            {
                NewWidth = FullsizeImage.Width;
            }
        }
        System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, MaxHeight, null, IntPtr.Zero);
        // Clear handle to original file so that we can overwrite it if necessary
        FullsizeImage.Dispose();
        // Save resized picture
        NewImage.Save(NewFile);
    }

Function to upload image

protected void btnArticlePageImage_Click(object sender, EventArgs e)
{

    try
    {
        String filePath = string.Empty;
        String CurrentGUID = Guid.NewGuid().ToString();

        if (FileUpload2.HasFile)
        {
            string filename = System.IO.Path.GetFileName(FileUpload2.FileName);
            System.IO.FileInfo f = new System.IO.FileInfo(FileUpload2.PostedFile.FileName);
            double fileSize = (double)FileUpload2.FileBytes.Length;
            if (fileSize < 1024000) // 1 MB current size size in bytes 102400=100kb  512000 = 500kb
            {
                if ((f.Extension.ToLower() == ".jpg") || (f.Extension.ToLower() == ".png") || (f.Extension.ToLower() == ".gif") || (f.Extension.ToLower() == ".jpeg"))
                {
                    filename = CurrentGUID + f.Extension;
                    //string productGUID 
                    filePath = Server.MapPath("../ImagesArticles/") + filename;
                    if (System.IO.File.Exists(filePath))
                    {
                        return;
                    }
                    else
                    {
                        //Upload files
                        FileUpload2.PostedFile.SaveAs(Server.MapPath("../ImagesArticles/") + filename);
                        //objPages.PageBannerImageEn = filename;
                        Session["ArticleLargeImage"] = filename.ToString();
                        string errMsg = "File Uploaded Successfully";
                        lblImageUploadMessage1.Text = errMsg;
                        // ResizeImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
                        Helper.ResizeImage(filePath, filePath, 150, 80, true);
                    }
                    return;
                }
                else
                {
                    string errMsg = "File must be an Image type of .jpg, .png, .gif, .jpeg";
                    //client-side error
                    lblImageUploadMessage1.Text = errMsg;
                    return;
                }
            }
            else
            {
                string errMsg = "File size is greater the 1MB";
                //client-side error
                lblImageUploadMessage1.Text = errMsg;
                return;
            }
        }
        else
        {
            //lblMesg.Text = "Only type .jpg, .png, .gif are allow";
            string errMsg = "Cant Upload File due to some error";
            //client-side error
            lblImageUploadMessage1.Text = errMsg;
            return;
        }
    }
    catch (Exception ex)
    {
        Response.Write("ERROR MESSAGE : " + ex.Message.ToString());
    }

}

Sequence: User can upload image type JPG, GIF, PNG etc. i only rename the image with GUID and keep the image extension same and then save it on the web server. After that i re size the image for later use.

These re sized images work fine in all browsers but only issue is if someone downloads these image for editing it wont open in any graphics editor tools.

It gives a common error message as mentioned in the first part of question.

  • 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-29T20:53:09+00:00Added an answer on May 29, 2026 at 8:53 pm

    Try adding the imageformat to save, this is for a gif image

    NewImage.Save(NewFile, System.Drawing.Imaging.ImageFormat.Gif);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that I use to resize some images on my
I use the following code: Calendar calendar = new GregorianCalendar(0,0,0); calendar.set(Calendar.YEAR, 1942); calendar.set(Calendar.MONTH, 3);
I Use the following code to load png image: UIImage *imageBack1 = [UIImage imageNamed:@Bar1.png];
I use the following code to load an image into an scroll view. The
I use the following code to retrieve image from the phone or SDCard and
How to resize the categories images in Magento? I used the following code to
I'm using the following code to resize an image so it fits inside a
I use the following code to create countdowns in Javascript. n is the number
I use the following code to compile a cpp file to object file. g++
I use the following code try to create an array of string vectors, I

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.