2013-05-16 50 views
1

我對此很陌生,所以希望你們能忍受我。我試圖在btnDone上插入數據庫filePathImage的URL目錄。 部分代碼:c#試圖從另一種方法訪問的東西

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(); 
    } 

i的act.FileURL = AjaxFileUpload1.filePathImage得到了與filePathImage一個問題;任何意見或解決方案將不勝感激

+0

'AjaxFileUpload'沒有一個叫做'filePathImage'屬性:http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AjaxFileUpload/AjaxFileUpload.aspx#ctl00_SampleContent_Properties_HeaderPanel - 究竟是你想怎麼辦? –

+0

filePathImage是我給出的文件路徑名稱。 – user2376998

+0

我試了act.FileURL = filePathImage; ...不能工作 – user2376998

回答

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 ... 
    } 
} 
+0

感謝它的工作原理!但我還有另一個問題,如果適合在這裏問,duno。我將通過以下方式將URL目錄保存到數據庫: String filepathImage =(@「Images/Story /」+ txtTitle.Text +「/」+ e.FileName); 但是在數據庫中,它並沒有考慮到txtTitle.Text ...它看起來像是圖片/故事// Jellyfish.jpg在DB – user2376998

+0

啊啊好吧我解決了它:p謝謝 – user2376998

+0

@ user2376998你是歡迎 – Damith