尝试使用ajaxfileupload获取所有上传的文件名 [英] Try to get all the uploaded file names using ajaxfileupload

查看:89
本文介绍了尝试使用ajaxfileupload获取所有上传的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我在UploadComplete()中获得一个文件名时,它在加载下一个文件时就会丢失,因为每次加载文件都会导致自动回发.我试图阻止它,但是它不起作用.我还尝试了ViewState来保存仍然不起作用的文件名.如何保留上传文件名列表?

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?

推荐答案

您可以通过这种方式将它们保存到会话对象中.列表中加载了会话数据,添加了新项目,会话使用列表进行了更新.这样,会话将始终在每次上传后保留数据,而不是替换现有的数据.

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

这篇关于尝试使用ajaxfileupload获取所有上传的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆