I am having no luck when trying to use a FileUpload dialog to upload an image, resize while keepin the aspect ratio and then saving it to my file system using c# and ASP.NET Does anyone have a solution that works or a link to somewhere that can show me a working example? A lot of the solutions I've looked and tried only work with C# but not with ASP.NET
Asked
Active
Viewed 2,633 times
0
-
I can give you a VB.NET version that runs on my ASP.NET server. You might be able to convert it? – Rick Calder Oct 09 '12 at 03:40
-
1why not use the c# code as an external dll to your ASP.NET project ? and just call the required functions... – Mortalus Oct 09 '12 at 03:43
-
Could you please send me you've vb version. I'll give it a shot – Pacobart Oct 09 '12 at 06:33
1 Answers
0
ImageResizer will give you everything you want:
string fileExt = System.IO.Path.GetExtension(imageUpload.FileName);
if (string.Equals(fileExt, ".jpg", StringComparison.OrdinalIgnoreCase))
{
foreach (string fileKey in HttpContext.Current.Request.Files.Keys)
{
HttpPostedFile file = HttpContext.Current.Request.Files[fileKey];
if (file.ContentLength <= 0) continue; //Skip unused file controls.
try
{
ImageJob i = new ImageJob(file, "~/eventimages/<guid>_<filename:A-Za-z0-9>.<ext>",
new ResizeSettings("width=60&height=60&format=jpg&crop=auto"));
i.Build();
ImageJob j = new ImageJob(file, "~/eventimages/<guid>_<filename:A-Za-z0-9>.<ext>",
new ResizeSettings("width=250&height=250&format=jpg&crop=auto"));
j.Build();
string sitePath = MapPath(@"~");
thumbImagePath = i.FinalPath.Replace(sitePath, "~\\");
mainImagePath = j.FinalPath.Replace(sitePath, "~\\");
}
catch
{
// Had to swallow the exception here:
// http://stackoverflow.com/questions/7533845/system-argumentexception-parameter-is-not-valid
}
}
}

IrishChieftain
- 15,108
- 7
- 50
- 91