[英]How to Update Database Table after AjaxFileUpload ASP.NET
文件正在上傳到相應的路徑,但是表(fileinfo)沒有更新。.在文件上傳到服務器后如何實現表更新
protected void UploadComplete(Object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string str = RadioButton1.Text;
string path = Server.MapPath("~/" + str +"/") + e.FileName;
AjaxFileUpload1.SaveAs(path);
SqlConnection con = new SqlConnection("Data Source=localhost\\sqlexpress; Initial Catalog=example;user ID=sa;password=*******;");
con.Open();
string command1 = "insert into fileinfo(fileid,filename,date1) values(@fileid,@filename,@date1)";
SqlCommand command = new SqlCommand(command1, con);
command.Parameters.AddWithValue("@fileid", "101");
command.Parameters.AddWithValue("@filename", e.FileName);
command.Parameters.AddWithValue("@date1", DateTime.Now);
command.ExecuteNonQuery();
}
您可以檢索存儲在str文件夾中的所有文件,也可以使用數組進行存儲,我已經使用字符串jst向您展示了如何從文件夾中獲取所有文件
string getfile="";
foeach(string f in Directory.GetFiles(Server.MapPath("~/"+str+"/"))
{
getfiles= getfiles + f + ",";
}
現在,您可以將getfiles存儲在數據庫中,希望對您有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.