mvc c# upload image after resize
===

So I have an action which processes the uploading of a file. What I do is I check if the file size is 100kb, if not I resize it to a certain width and height (altho im not sure that's the right way to go to the desired size, thoughts?)

And then I'm planning to save it to a subdomain of my website.

this is how the action looks like

    public ActionResult New(string account, int id, HttpPostedFileBase file)
            {
                if (file == null)
                {
                    ModelState.AddModelError("", "File not found.");
                    return View();
                }
    
                if (!ImageUpload.FileTypeValid(file.ContentType))
                {
                    ModelState.AddModelError("", "File type is invalid. Please choose a different file.");
                    return View();
                }
    
                if (file.ContentLength > 100)
                {
                    Image image = ImageUpload.ResizeFile(file, 100, 100);
                }
    
                try
                {
    
                    icdb.SaveChanges();
                    ModelState.AddModelError("", "Sucesfully saved Image.");
                    return RedirectToAction("Details", "OfAController", new { account = account, id= id});
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
    
                return View();
            }

this is the resize method

 

    static public Image ResizeFile(HttpPostedFileBase file, int targeWidth, int targetHeight)
            {
                Image originalImage = Image.FromStream(file.InputStream, true, true);
                var newImage = new MemoryStream();
                Rectangle origRect = new Rectangle(0, 0, originalImage.Width, originalImage.Height);
                // if targets are null, require scale. for specified sized images eg. Event Image, or Profile photos.
                int newWidth = targeWidth;
                int newHeight = targetHeight;
                var bitmap = new Bitmap(newWidth, newHeight);
    
                try
                {
                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                        g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        g.DrawImage(originalImage, new Rectangle(0, 0, newWidth, newHeight), origRect, GraphicsUnit.Pixel);
                        bitmap.Save(newImage, originalImage.RawFormat);
                    }
                    return (Image)bitmap;
                }
                catch
                {   // error before IDisposable ownership transfer
                    if (bitmap != null)
                        bitmap.Dispose();
                    throw new Exception("Error resizing file.");
                }
            }


so my problem is, im trying to find ways on how to save this resized file to my directory. And then I keep finding that I have to upload the image first before resizing? Is that right? Or is there a way where I can resize this before I save to my directory? 

Thoughts?

Thanks!