Telerik RadFileExplorer-使用SearchPattern限制文件类型

问题描述

我正在使用Telerik RadFileExplorer。我使用下面的代码行来允许所有文件类型上传,但是我想限制上传(.exe,.dll)等少数文件类型。我知道有一种方法可以在诸如( .pdf, .docx等)的搜索模式中提及文件类型,但是此列表很大且未知。我想限制我不想上传文件类型。是他们修改下面一行以限制某些文件类型的一种方法

fileExplorer.Configuration.SearchPatterns = new string[] { "*.*" };

我发现的另一种方法是可以在FileExplorer_itemcommand上执行以下操作,但是这种方法的问题是,如果我正在上传3个文件,并且第一个文件是受限扩展名(.exe),则其余两个文件都无法通过即使他们允许扩展名(.pdf)。我相信这种情况正在发生,因为在受限制的文件中我们执行e.cancel是正确的。我如何才能成功上传其余2个文件而忽略第一个文件

    private static HashSet<string> BlackListedFileTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase) {
              ".exe",".dll",};

  

   

 protected void FileExplorer_itemcommand(object sender,RadFileExplorerEventArgs e)
    {
       switch (e.Command)
          {
            case "UploadFile":
             {
                const string AlertStringForFileExtensionType = "A file with this extension is not allowed to upload!";
                 string path = e.Path;
                 if (BlackListedFileTypes.Contains(Path.GetExtension(path)))
                 {
                   e.Cancel = true;
                   ScriptManager.RegisterStartupScript(this,this.GetType(),"KEY",@"alert(" +
                                                       "'" + Path.GetFileName(path) +
                                                       " : " + AlertStringForFileExtensionType
                                                       + "');",true);
                }
             }
  break;  
 }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)