asp.net mvc - MVC4 - Uploading Image - Generic GDI+ Error -


i'm trying upload image , when try image.save(), "generic gdi+" error. great.

    // action handles form post , upload     [httppost]     public actionresult index(httppostedfilebase file, string filename)     {         // verify user selected file         if (file != null && file.contentlength > 0)         {                             string location = "~/content/images/specials/" + "rttest" + ".jpg";             bitmap bitmap = new bitmap(file.inputstream);             image image = (image)bitmap;             image.save(stream, system.drawing.imaging.imageformat.jpeg);             image.save(location);                     }         // redirect index action show form once again         return redirecttoaction("index");     } 

the location of "~/content/images/specials/..." inaccessible gdi+ because isn't physical path. need use server.mappath() map virtual path physical path.

 string location = server.mappath("~/content/images/specials/" + "rttest" + ".jpg"); 

also, it's weird you're concatenating part of path, "rrest" ".jpg". may want before putting production aren't overwriting images on , over.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -