i am uploading image using file upload control. But it is giving the error, The SaveAs method is configured to require a rooted path, and the path '~/Admin/ProductImages/images (5).jpg' is not rooted.
string strBigServerPath = "~/Admin/ProductImages/"; string strFileName = ""; string ImageName = "";
if (prodImg.HasFile)
{
strFileName = prodImg.PostedFile.FileName;
prodImg.PostedFile.SaveAs(imgPath + strFileName);
string[] ext = strFileName.Split('.');
string newProductFileName = ext[0] + "123";
ImageName = newProductFileName + "." + ext[1];
prodImg.PostedFile.SaveAs(imgPath + ImageName);
using (System.Drawing.Image Img =
System.Drawing.Image.FromFile(Server.MapPath(strBigServerPath) + newFileName))
{
if (Img.Width > 250 && Img.Height > 400)
{
Size MainSize = new Size(250, 300);
using (System.Drawing.Image ImgThnail =
new Bitmap(Img, MainSize.Width, MainSize.Height))
{
ImgThnail.Save(Server.MapPath(strBigServerPath) + ImageName);
}
}
Img.Dispose();
}