0
votes
if (!Directory.Exists(Request.PhysicalApplicationPath + "Images//Products//" + ddlCategory.SelectedValue.ToString().Trim() + "//" + ProductMasterId.ToString().Trim() + "//OriginalImages"))
{
    Directory.CreateDirectory(Request.PhysicalApplicationPath + "Images//Products//" + ddlCategory.SelectedValue.ToString().Trim() + "//" + ProductMasterId.ToString().Trim() + "//OriginalImages");
}
if (File.Exists(Request.PhysicalApplicationPath + "Images//Products//" + ddlCategory.SelectedValue.ToString().Trim() + "//" + ProductMasterId.ToString().Trim() + "//" + fuImageName.FileName.ToString()))
{
    File.Delete(Request.PhysicalApplicationPath + "Images//Products//" + ddlCategory.SelectedValue.ToString().Trim() + "//" + ProductMasterId.ToString().Trim() + "//" + fuImageName.FileName.ToString());
}
if (File.Exists(Request.PhysicalApplicationPath + "Images//Products//" + ddlCategory.SelectedValue.ToString().Trim() + "//" + ProductMasterId.ToString().Trim() + "//OriginalImages//" + fuImageName.FileName.ToString()))
{
    File.Delete(Request.PhysicalApplicationPath + "Images//Products//" + ddlCategory.SelectedValue.ToString().Trim() + "//" + ProductMasterId.ToString().Trim() + "//OriginalImages//" + fuImageName.FileName.ToString());
}
fuImageName.SaveAs(Request.PhysicalApplicationPath + "Images//Products//" + ddlCategory.SelectedValue.ToString().Trim() + "//" + ProductMasterId.ToString().Trim() + "//" + fuImageName.FileName.ToString());

if (!Directory.Exists(Request.PhysicalApplicationPath + "Images//Products//" + ddlCategory.SelectedValue.ToString().Trim() + "//" + ProductMasterId.ToString().Trim() + "//ThumbNailImages"))
{
    Directory.CreateDirectory(Request.PhysicalApplicationPath + "Images//Products//" + ddlCategory.SelectedValue.ToString().Trim() + "//" + ProductMasterId.ToString().Trim() + "//ThumbNailImages");
}

string Path = Request.PhysicalApplicationPath + "Images//Products//" + ddlCategory.SelectedValue.ToString().Trim() + "//" + ProductMasterId.ToString().Trim() + "//" + fuImageName.FileName.ToString();
Bitmap bmp1 = CreateThumbnail(Path, 400, 500);

string OutputFilename1 = fuImageName.FileName.ToString();
bmp1.Save(Request.PhysicalApplicationPath + "Images//Products//" + ddlCategory.SelectedValue.ToString().Trim() + "//" + ProductMasterId.ToString().Trim() + "//OriginalImages//" + OutputFilename1.ToString(), System.Drawing.Imaging.ImageFormat.Jpeg);

bmp1.Dispose();

Bitmap bmp = CreateThumbnail(Path, 100, 100);

string OutputFilename = "Thumb_" + fuImageName.FileName.ToString();
bmp.Save(Request.PhysicalApplicationPath + "Images//Products//" + ddlCategory.SelectedValue.ToString().Trim() + "//" + ProductMasterId.ToString().Trim() + "//ThumbNailImages//" + OutputFilename.ToString(), System.Drawing.Imaging.ImageFormat.Jpeg);

bmp.Dispose();

ClearAll();

It's my code ..and I run on server getting me this error

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed....

Please solve this error......

2
Simple: you don't have the permission to access one of those files and/or directories. We can't solve this - you have to solve it yourself! Debug through your code - where exactly does this error happen, what line?? - marc_s
I would also refactor code, there's much duplicated code - Giedrius

2 Answers

1
votes

Check Your hosting panel and changes permission of IIS user on your upload image folder.

Happy Coding :)

1
votes

Check the windows identity of the IIS Application pool.

Check the security settings of the folders and files the application is accessing.

Check whether or not the web application is using impersonation.

Adjust the rights as needed.