asp.net root paths

Posted by dejavu on Stack Overflow See other posts from Stack Overflow or by dejavu
Published on 2010-05-14T20:14:28Z Indexed on 2010/05/14 20:24 UTC
Read the original article Hit count: 366

Filed under:

I am getting the exception when trying to save a file:

System.Web.HttpException: The SaveAs method is configured to require a rooted path, and the path '~/Thumbs/TestDoc2//small/ImageExtractStream.bmp' is not rooted.
at System.Web.HttpPostedFile.SaveAs(String filename)
at System.Web.HttpPostedFileWrapper.SaveAs(String filename)
at PitchPortal.Core.Extensions.ThumbExtensions.SaveSmallThumb(Thumb image) in C:\Users\Bich Vu\Documents\Visual Studio 2008\Projects\PitchPortal\PitchPortal.Core\Extensions\ThumbExenstions.cs:line 23

the code is below:

public static void SaveSmallThumb(this  Thumb image)
    {
        var logger = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance<ILoggingService>();

        string savedFileName = HttpContext.Current.Server.MapPath(Path.Combine(
          image.SmallThumbFolderPath,
          Path.GetFileName(image.PostedFile.FileName)));
        try
        {
            image.PostedFile.SaveAs(savedFileName);
        }
        catch (Exception ex)
        {
            logger.Log(ex.ToString());
        }
    }

I cant see what is wrong here, any tips?

© Stack Overflow or respective owner

Related posts about ASP.NET