Hello Friends ...
How To Change Image extensions When User Uploading Image In Mvc....
I am Using ImageReSizer nuget Package Manage.
Given Below Is My Code:-
public static string UploadFile(HttpPostedFileBase file,string file_Name,int height,int width)
{
var path = Path.Combine(HttpContext.Current.Request.MapPath(UploadPath), file_Name);
file.SaveAs(path);
ResizeSettings resizeSetting = new ResizeSettings
{
Width = width,
Height = height,
Format = "."
};
ImageBuilder.Current.Build(file, path, resizeSetting);
return file_Name;
}
10 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Mohammed Deeb HammoudehPosted Dec 19, 2016, 7:16 AM
Dr.Ajay KashyapPosted Dec 15, 2016, 11:43 PM
Maen BadwanPosted Dec 15, 2016, 9:08 AM
If you want to change the actual image data from JPG to PNG (not only the extension), you can use LEADTOOLS programming SDK which supports loading and saving many image file formats including JPEG and PNG.
For example, the following code shows how you can load any supported image format (JPEG image) and save it to PNG file format on disk or in memory:
+-------------------+
using (Leadtools.Codecs.RasterCodecs _leadCodecs = new Leadtools.Codecs.RasterCodecs())
{
//Load the original JPEG image to a RasterImage object
Leadtools.RasterImage JPEGImage = _leadCodecs.Load(file.FileName);
//Save the RasterImage object to a temp PNG file on disk
_leadCodecs.Save(JPEGImage, "TempFile.png", RasterImageFormat.Png, 24);
//the following code saves the RasterImage object to a MemoryStream
System.IO.MemoryStream Memstream = new System.IO.MemoryStream();
_leadCodecs.Save(destinationImage, Memstream, RasterImageFormat.Png, 24);
Memstream.Seek(0, SeekOrigin.Begin);
}
+-------------------+
More details can be found here:
https://www.leadtools.com/sdk/formats
Note that you can add the above code in a web-service and call it from inside your ASP.NET MVC application, or you can use the code directly in your ASP.NET server side code
Disclaimer: I am an employee of this library.
Fabio Silva LimaPosted Dec 12, 2016, 7:30 PM
Bikesh SrivastavaPosted Dec 12, 2016, 7:17 AM
MayankPosted Dec 12, 2016, 6:43 AM
{
var file = Request.Files[0];
actualFileName = file.FileName;
fileName = Guid.NewGuid() + ".png";
//fileName = Guid.NewGuid() + Path.GetExtension(file.FileName);
int size = file.ContentLength;
try
{
file.SaveAs(Path.Combine(Server.MapPath("~/FileUpload"), fileName));
}
catch (Exception)
{
Message = "File upload failed! Please try again";
}
Dr.Ajay KashyapPosted Dec 12, 2016, 5:47 AM
Mangesh Gaherwar sir ..system web httppostedfilebase to string convert Error
Mangesh GPosted Dec 12, 2016, 3:55 AM
Dr.Ajay KashyapPosted Dec 12, 2016, 3:46 AM
Nitin SontakkePosted Dec 12, 2016, 3:29 AM