1

我是新手,所以希望你们能忍受我。我正在尝试在 btnDone 时将 filePathImage 的 URL 目录插入数据库。部分代码:

  protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        EnsureDirectoriesExist();


        String filepathImage = (@"Images/Story/" +txtTitle.Text + "/" + e.FileName);


        AjaxFileUpload1.SaveAs(Server.MapPath(filepathImage));


    }

 protected void btnDone_Click(object sender, EventArgs e)
    {

        act.ActivityName = dropListActivity.SelectedItem.Text;
        act.Title = txtTitle.Text;

        act.FileURL = filepathImage;

        daoStory.Insert(act);
        daoStory.Save();
    }

我在 act.FileURL = AjaxFileUpload1.filePathImage 中遇到了 filePathImage 的问题;任何建议或解决方案将不胜感激

4

1 回答 1

1

在下面尝试,上传完成后,您可以将路径放入会话并在需要时采用该会话路径。

protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{

  // your Code 
  Session["filepathImage"] = filepathImage ; // put the path in session variable 

}

protected void btnDone_Click(object sender, EventArgs e)
{
    if(Session["filepathImage"]!=null)
    {
         string filepathImage = Session["filepathImage"] as string;
         // your code ...
    }
}
于 2013-05-16T03:48:36.353 回答