我需要这方面的帮助,我将文件目录插入数据库,但它没有考虑数据库中的 txtStoryTitle.Text,例如,如果我在 txtStoryTitle 中键入 HelloWorld。它在数据库中显示为 Images/Story//(filename) 而不是 Images/Story/HelloWorld/(filename)。我正在使用 MySQL(工作台)。
请给我一个建议/解决方案,提前谢谢!
以下是部分代码:
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
EnsureDirectoriesExist();
String filepathImage = (@"Images/Story/" + txtStoryTitle.Text + "/" + e.FileName);
AjaxFileUpload1.SaveAs(Server.MapPath(filepathImage));
Session["filepathImage"] = filepathImage;
}
public void EnsureDirectoriesExist()
{
if (!System.IO.Directory.Exists(Server.MapPath(@"Images/Story/" + txtStoryTitle.Text + "/")))
{
System.IO.Directory.CreateDirectory(Server.MapPath(@"Images/Story/" + txtStoryTitle.Text + "/"));
}
}
protected void btnDone_Click(object sender, EventArgs e)
{
if (Session["filepathImage"] != null)
{
string filepathImage = Session["filepathImage"] as string;
act.ActivityName = dropListActivity.SelectedItem.Text;
act.Title = txtStoryTitle.Text;
act.FileURL = filepathImage;
daoStory.Insert(act);
daoStory.Save();
}