Why does jQuery FileTree show files if they are not installed?

I am using the jqueryfiletree plugin and it seems to be installed and pretty smooth, but I have some problems:

Despite the fact that the parameters are set as follows:

$(function() {
    $("#sourceFileTree").fileTree({
        onlyFolders: true,
        root: "C%3a%5cProjects%5cBMW%5cCode%5cFileTransfers.Web",
        script: "/FileTree/Tree",
        multiFolder: false,
        multiSelect: false,
        preventLinkAction: true
    });
});
  • onlyFoldersseems to be ignored, and any open folder also shows the files that it contains.
  • The same goes for multiSelect: false. Although I can “select” (highlight in bold) only one file at a time, I can still check as many checkboxes with folders and files as possible.
  • It only multiFolder: falseseems to work as documented, but I don't know if this is because of the default behavior.

, , ?

+4
1

(, ) - , . / jQuery, , . , (https://github.com/jqueryfiletree/jqueryfiletree/blob/master/dist/connectors/Asp.Net-MVC/FileTreeController.cs) PHP, , , (https://github.com/jqueryfiletree/jqueryfiletree/blob/master/dist/connectors/jqueryFileTree.php), , .

. , , - . , , .NET, , 4.6 Core

[HttpPost]
//notice the added additional params to the expected request variables
//these appear to match the names of the jQuery options
public virtual ActionResult GetFiles(string dir, bool multiSelect, 
    bool onlyFolders, bool onlyFiles)
{
    const string baseDir = @"/App_Data/userfiles/";

    dir = Server.UrlDecode(dir);
    string realDir = Server.MapPath(baseDir + dir);

    //validate to not go above basedir
    if (! realDir.StartsWith(Server.MapPath(baseDir)))
    {
        realDir = Server.MapPath(baseDir);
        dir = "/";
    }

    List<FileTreeViewModel> files = new List<FileTreeViewModel>();

    DirectoryInfo di = new DirectoryInfo(realDir);

    foreach (DirectoryInfo dc in di.GetDirectories())
    {                
        files.Add(new FileTreeViewModel() { Name = dc.Name, Path = String.Format("{0}{1}\\", dir, dc.Name), IsDirectory = true });
    }

    foreach (FileInfo fi in di.GetFiles())
    {
        files.Add(new FileTreeViewModel() { Name = fi.Name, Ext = fi.Extension.Substring(1).ToLower(), Path = dir+fi.Name, IsDirectory = false });
    }
    //lets filter some results using the properties of 
    //the `FileTreeViewModel()` class
    //I have no idea how you are wanting to use multiSelect, so 
    //it has been left out of this example.
    if(onlyFolders){
        files = files.Where(x=>x.IsDirectory).ToList();
    }
    if(onlyFiles){
        files = files.Where(x=>!x.IsDirectory).ToList();
    }
    return PartialView(files);
}
+3

Source: https://habr.com/ru/post/1685901/


All Articles