2017-09-29 56 views
0

嗨,如何检查用户文件夹或DNN中的任何其他文件夹是否为空?

我可以使用哪些代码来检查用户文件夹或DNN中的任何其他文件夹是否没有文件?我看过:Retrieve FileID from DotNetNuke using FileName ...但没有运气。

此代码是否正确用于检查文件是否存在?我不想指定一个特定的文件名。

FolderManager.Instance.GetFiles(); 

上面代码的括号里应该包含什么? ?可有人请提供一个例子

回答

0

你可以这样做:

FolderController controller = new FolderController(); 

Dictionary<string, FolderInfo> list = controller.GetFolders(PortalId); 
foreach (var folder in list) 
{ 
    List<IFileInfo> files = FolderManager.Instance.GetFiles(folder.Value).ToList(); 
    Label1.Text += folder.Key + ": " + files.Count(); 
} 
+0

不客气。不是有'FolderManager.Instance.GetFiles'的各种重载,其中许多已弃用。但其中大部分仍然有效。 – VDWWD

0

我发现这样做,以及使用System.IO.Directory的另一种方式。

var userfolderpath = FolderManager.Instance.GetUserFolder(UserInfo).FolderPath; 
    var userfolderpath_ = @"\" + userfolderpath; 
    var portalPath = Server.MapPath("~/Portals/" + this.PortalId); 
    var physicalPath = System.IO.Path.Combine(portalPath, userfolderpath); 

      var list = System.IO.Directory.GetFiles(physicalPath); 
      if (list?.Length > 0) 
      { 
       //sumbit_files.Attributes.Add("style", "display:block;"); 
       //message_container.Attributes.Add("style", "display:block;"); 

       if (userfolderpath != null) 
       { 
        dgrFileList.Columns[0].HeaderText = Localization.GetString("FileHeader", this.LocalResourceFile); 
        dgrFileList.Columns[1].HeaderText = Localization.GetString("FileWriteDate", this.LocalResourceFile); 
        dgrFileList.Columns[2].HeaderText = Localization.GetString("FileDownloadHeader", this.LocalResourceFile); 
        dgrFileList.DataSource = FileUtility.GetSafeFileList(string.Concat(portalPath, userfolderpath_), GetExcludedFiles(), GetSortOrder()); 
        dgrFileList.DataBind(); 
       } 
      } 
相关问题