Looking at the code you've posted, you've started with a virtual path (
~/AgentImages/
), and mapped it to the corresponding physical path. Then you try to convert the physical path back to a virtual path, before mapping the virtual path back to a physical path again.
You should be able to replace that with the following:
protected void btnSubmit_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(Session["AgentMasterID"]);
string temp = "";
if (fuProducImage.HasFile)
{
if (CheckFileType() == true)
{
string directoryPath = Server.MapPath("~/AgentImages/") + id;
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
temp = Path.Combine(directoryPath, fuProducImage.FileName);
fuProducImage.SaveAs(temp);
lblPimage.Visible = true;
lblPimage.Text = "Image Uploaded Sucesfully";
}
}
}