难以将图像存储在我项目的图像文件夹中

时间:2013-07-20 07:20:49

标签: asp.net

我想将图像存储在项目的根文件夹中..但图像存储在admin文件夹 - >图像中。这是我的 C#代码:此代码是在管理面板中编写的 - > AddProducts文件..

protected void Button3_Click(object sender, EventArgs e)
{
    FileUpload FileUpload1 = FileImage;
    string virtualFolder = "images/";
    string img = "images/";
    string f = (DateTime.Now.GetHashCode()).ToString(); ;
    string physicalFolder = Server.MapPath(virtualFolder);
    FileUpload1.SaveAs(physicalFolder + f + FileUpload1.FileName);        
    Image1.Visible = true;
    Image1.ImageUrl = virtualFolder + f + FileUpload1.FileName;
    string path = img + f + FileUpload1.FileName;
    TextBox4.Text = path;   
}

1 个答案:

答案 0 :(得分:0)

每当使用Server.mappath

时,请始终使用~符号
  protected void Button3_Click(object sender, EventArgs e)
    {
        FileUpload FileUpload1 = FileImage;
        string virtualFolder = "~/images/";
        string img = "~/images/";
        string f = (DateTime.Now.GetHashCode()).ToString(); ;
        string physicalFolder = Server.MapPath(virtualFolder);
        FileUpload1.SaveAs(physicalFolder + f + FileUpload1.FileName);
        Image1.Visible = true;
        Image1.ImageUrl = virtualFolder + f + FileUpload1.FileName;
        string path = img + f + FileUpload1.FileName;
        TextBox4.Text = path;
    }