文件名不能为空错误时,抛出ajaxfileupload(第二控制我的网页上) [英] File name cannot be null error thrown ajaxfileupload (second control on my page)

查看:338
本文介绍了文件名不能为空错误时,抛出ajaxfileupload(第二控制我的网页上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ajaxFileUpload如下所述:<一href=\"http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AjaxFileUpload/AjaxFileUpload.aspx\" rel=\"nofollow\">http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AjaxFileUpload/AjaxFileUpload.aspx

I'm using ajaxFileUpload as described here: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AjaxFileUpload/AjaxFileUpload.aspx

我要在一个页面上使用三个ajaxFileUpload控制,上传和放大器;保存到不同的位置。
起初,所有上传控件调用先上传的UploadComplete事件(如:ajaxFileupload2随时拨打ajaxFileUpload1_UploadComplete)

I have to use three ajaxFileUpload controls on one page, to upload & save into different locations. At first, all uploader controls calling the UploadComplete event of first uploader (eg: ajaxFileupload2 always call ajaxFileUpload1_UploadComplete.)

然后我发现下面的职位和放大器;尝试最后的答案。
<一href=\"http://stackoverflow.com/questions/10760895/ajax-toolkit-file-upload-is-not-called/16987292#16987292\">Ajax工具包文件上传不叫

Then I found the below post & try the last answer. Ajax toolkit file upload is not called

在我尝试用最后的答案,3上传呼吁的是由anyUploader事件委托自己的事件。然而,面对另一个问题,就是消息:文件名不能为空的错误抛出的第二/第三控制,而第一个上传工作正常。

After I try with last answer, 3 uploaders are calling to their own event which is delegated by anyUploader event. However, facing another problem which is "Message: File name cannot be null" error thrown on second/third control, whereas first uploader is working fine.


Stack Trace:
Error found in FileUploadComplete2.
Message: File name cannot be null.
Parameter name: sourceFileName
Stack Trace:    at System.IO.File.Move(String sourceFileName, String destFileName)
   at AjaxControlToolkit.AjaxFileUpload.SaveAs(String fileName, Boolean deleteAzureBlob) in f:\TeamCity\buildAgent\work\80acd78aa4c25314\Server\AjaxControlToolkit\AjaxFileUpload\AjaxFileUpload.cs:line 473
   at AjaxControlToolkit.AjaxFileUpload.SaveAs(String fileName) in f:\TeamCity\buildAgent\work\80acd78aa4c25314\Server\AjaxControlToolkit\AjaxFileUpload\AjaxFileUpload.cs:line 441
   at FileUpload.AjaxFileUploadTwo_UploadComplete(Object sender, AjaxFileUploadEventArgs e) in c:\Projects\WebSite\FileUpload.aspx.cs:line 364

鸭preciate任何意见。

Appreciate any advice.

我的主要要求是,让用户可以同时上传和保存到这取决于他们使用的上传不同的位置。

My main requirement is to allow user to simultaneous upload and save into different locations depending on which uploader they use.

在此先感谢!

推荐答案

最后,我找到了变通的方式来解决我的问题。
由于目前没有与文件名不能为空从第二次开始上传抛出一个错误,下面是我的解决办法的方式来解决和放大器;履行我的项目要求。结果

Finally, I found the work around way to solve my problem. Since there is an error thrown with 'File name cannot be null' from second uploader onwards, below is my workaround way to solve & fulfil my project requirements.

1)我写这就是所谓的所有三个上传结果一个共同的功能
2)设置这是由客户端ID(参考定义每个上传不同的路径:<一href=\"http://stackoverflow.com/questions/10760895/ajax-toolkit-file-upload-is-not-called/16987292#16987292\">Ajax工具包文件上传不叫)结果
3)使用通过AjaxUploadOne(例如,所有的AJAX功能:对所有三种上传AjaxUploadOne.SaveAs功能)。 - 这条线解决​​我的问题。在此之前,我使用的每一个上传另存为功能,但预期它不能正常工作。结果

1) I write one common function which is called by all three uploaders
2) Set the different path for each uploader which is define by ClientID (reference:Ajax toolkit file upload is not called)
3) Use all the ajax function via AjaxUploadOne (Eg: AjaxUploadOne.SaveAs function for all three uploader). -- This line solved my problem. Before that, I'm using each uploader SaveAs function but it's not work as expected.

我的示例code是如下&放大器;所有ajaxfileupload控件调用相同的功能: -

My sample code would be as follow & all ajaxfileupload controls called the same function:-


protected void AnyUploader_FileUploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        try
        {
            string path = "";
            if (Request.QueryString["uplCtrlID"] != null)
            {
                //uplCtrlID (the query string param we injected with the overriden JS function)
                //contains the ID of the uploader.
                //We'll use that to fire the appropriate event handler...
                if (Request.QueryString["uplCtrlID"] == AjaxFileUploadOne.ClientID)
                {      
                    /** different path assignment for each uploader **/
                    path = @"C:\Temp\FileUploaderOne\";
                    if (!Directory.Exists(path))  Directory.CreateDirectory(path);
                    AjaxFileUploadOne.SaveAs(path + e.FileName);                   
                }
                else if (Request.QueryString["uplCtrlID"] == AjaxFileUploadTwo.ClientID)
                {
      /** different path assignment for each uploader **/
                    path = @"C:\Temp\FileUploaderTwo\";
                    if (!Directory.Exists(path)) Directory.CreateDirectory(path);
                    AjaxFileUploadOne.SaveAs(path + e.FileName);              
                }
                else if (Request.QueryString["uplCtrlID"] == AjaxFileUploadThree.ClientID)
                {
                    /** different path assignment for each uploader **/
                    path = @"C:\Temp\FileUploaderThree\";
                    if (!Directory.Exists(path)) Directory.CreateDirectory(path);
                    AjaxFileUploadOne.SaveAs(path + e.FileName);                                    
                }
            }            
        }
        catch (Exception ex)
        {
        }
    }

我会很高兴,如果它有助于谁面临着类似的问题,我这样的人。谢谢。

I would be happy if it's help to someone who facing similar problem with me. Thank you.

这篇关于文件名不能为空错误时,抛出ajaxfileupload(第二控制我的网页上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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