更新时间:2022-03-04 09:23:26
您可以通过这种方式将它们保存到会话对象中.列表中加载了会话数据,添加了新项目,会话使用列表进行了更新.这样,会话将始终在每次上传后保留数据,而不是替换现有的数据.
You can save them to a session object in this way. The list is loaded with the session data, new item is added, the session is updated with the list. By so doing the session will always retain data after every upload instead of replacing the existing one.
C#
//global declaration
private List<string> UploadList;
protected void AjaxFileUpload1_UploadComplete()
{
String fileName = IO.Path.GetFileName(e.FileName);
UploadList = Session["UploadedFiles"];
UploadList.Add(fileName);
Session["UploadedFiles"] = UploadList;
}
//retrieve the items from list
private void GetList()
{
UploadList = Session["UploadedFiles"];
//loop through the list or access each item by the index
}
VB
'global declaration
Dim UploadList as List(Of String)
Protected Sub AjaxFileUpload1.UploadComplete()
Dim fileName = IO.Path.GetFileName(e.FileName)
UploadList = Session("UploadedFiles")
UploadList.Add(fileName)
Session("UploadedFiles") = UploadList
End Sub
'retrieve the items from list
Private Sub GetList()
UploadList = Session("UploadedFiles")
'loop through the list or access each item by the index
End Sub