I am getting this 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());
}
}
What is wrong here?
You problem is your path being produce (possibly due to failure of MapPath):
Notice the 2
//betweenTestDoc2andsmall.You combine seems to be the issue that is probably causing the double slash.
What is the output of
image.SmallThumbFolderPathandPath.GetFileName(image.PostedFile.FileName)?The
SaveAsrequires a physical path (eg.c:/Thumbs/TestDoc2//small/ImageExtractStream.bmp).