問題已經解決通過用控制一列例如創建數據表(與列數據類型文件上傳):
private DataTable CreateDtDocs(string name, string path, FileUpload FileUploader)
{
DataTable dt1 = new DataTable();
dt1.Columns.Add("SR_NO");
dt1.Columns.Add("Name");
dt1.Columns.Add("Path");
Type col_type = fubrowse.GetType();
DataColumn dt_col = new DataColumn("Control", col_type);
dt1.Columns.Add(dt_col);
DataRow dr = dt1.NewRow();
dr["SR_NO"] = "1";
dr["NAME"] = name;
dr["Path"] = path;
dr["Control"] = FileUploader;
dt1.Rows.Add(dr);
return dt1;
}
然後填充表象下面這樣:
private DataTable AddDtDocs(string name, string path, FileUpload FileUploader)
{
DataTable dt1 = (DataTable)Session["AttachFilesdt"];
int count = dt1.Rows.Count;
DataRow dr = dt1.NewRow();
dr["SR_NO"] = count + 1;
dr["NAME"] = name;
dr["Path"] = path;
dr["Control"] = FileUploader;
dt1.Rows.Add(dr);
return dt1;
}
然後我在Dictionary中添加路徑名和控件,並將它們傳遞給不同的函數以將它們保存在服務器上。
Dictionary<string, FileUpload> DocsPathAndControl = new Dictionary<string, FileUpload>();
if (Session["AttachFilesdt"] != null)
{
tempdt = (DataTable)Session["AttachFilesdt"];
for (int i = 0; i < tempdt.Rows.Count; i++)
{
DocsPathAndControl.Add(tempdt.Rows[i]["Path"].ToString(), (FileUpload)tempdt.Rows[i]["Control"]);
}
Session["AttachFilesdt"] = null;
}
功能保存文件
private void AddDocuments(int jurisdictionID, Dictionary<string,FileUpload> docPathsAndControl)
{
foreach (var item in docPathsAndControl)
{
string tempfilename = jurisdictionID + "_" + item.Key.ToString();
string path = Server.MapPath("Dir\\" + tempfilename);
FileUpload FileUploaderControl = (FileUpload)item.Value;
FileUploaderControl.PostedFile.SaveAs(path);
}
}
希望,它會幫。
其實我想要的東西像在asp.net客戶端上傳,我會上傳多個文件,並顯示在網格視圖(或在其他東西),使用戶可以看到文件被選中,並可以從列出的文件中刪除。 只有當用戶點擊其他按鈕時,纔會將文件保存到服務器,並說'更新'。你能幫助我,如何做到這一點? –