0

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?

Yunfeng Zhao
  • 27
  • 1
  • 6

1 Answers1

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