1

I have previously successfully managed to upload a file using the webimage helper, but i am now trying to combine that with creating a directory, and failing miserably. here is my code:

    if(IsPost){
    //Create Directory using PropertyID
    var imageroot = Server.MapPath("~/Images/Property/");
    var foldername =  rPropertyId.ToString();
    var path = Path.Combine(imageroot, foldername);
    if(!Directory.Exists(path)){
    Directory.CreateDirectory(path);
    }

    photo = WebImage.GetImageFromRequest();
    if(photo != null){
         MediumFileName = rPropertyId + "_" + gooid + "_" + "Medium";
         imagePath = path + MediumFileName;
         photo.Save(@"~\" + imagePath);}
}

First, i create a directory with the name of the propertyID. This works fine. I then try and upload new photo's into that path, and i get an error saying that "The given path's format is not supported".

Any ideas?

Gavin5511
  • 791
  • 5
  • 31
  • You might be needing "path" to have `Server.MapPath(path)`. I'm not sure, as I just glanced at this, but anytime I've created a directory in this environment, I have needed the `Server.MapPath()` method. – VoidKing Nov 26 '13 at 14:08

1 Answers1

2

You correctly use Path.Combine() when creating the directory path, you should do the same when making the image path.

imagePath = Path.Combine(path, MediumFileName);

Other than that, the error message suggests that perhaps it is the omission of a file extension that is causing issues? Perhaps use Path.GetFileName(photo.FileName) or similar and use that as the end of your constructed pathname.

Polynomial
  • 3,656
  • 23
  • 36
  • PS, i'm working on the standardization of image types, so the file extension piece will come into play a bit later :p – Gavin5511 Nov 26 '13 at 17:27