Whenever I get one file name in UploadComplete(), it will be lost when it loads next file since every file loading will cause auto post back. I tried to stop it, but it doesn't work. I also tried ViewState to save the file name which still doesn't work. How to keep the list of uploaded file names?
Asked
Active
Viewed 1,261 times
0
-
u tried e.fileName? – Vivek Nuna Nov 04 '16 at 20:43
-
@viveknuna Yeah, I tried. I can just get one file' name, and the file's name is lost when it reads another file (assume loading multiple files). I have no way to keep it. – Yunfeng Zhao Nov 04 '16 at 20:46
1 Answers
1
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

Prince Tegaton
- 222
- 1
- 4
- 14
-
-
If I speak English, you reply me in French. It would be a great conversation. – Vivek Nuna Nov 04 '16 at 21:03
-
Thank you vivek, lets make it a good conversation. I've update the answer with c# code – Prince Tegaton Nov 04 '16 at 21:17
-
@PrinceTegaton Thank you! I never know session can store a list. That works. – Yunfeng Zhao Nov 08 '16 at 17:49
-
Session stores objects, so you read and convert to the matched data its holding. You should mark this solution as answer for future reference. – Prince Tegaton Nov 09 '16 at 11:40