mercredi 16 décembre 2015

generate a list of URL links for files in folder [javascript]

I want to generate list for each file in folder.For example if I have following files in specific folder

  • sample_picture1.jpg
  • sample_picture2.jpg

I want to generate URL links as follows


Currently I created it as like this.

json method to find files in a folder

    public JsonResult filesinfolder()
    {
        string salesFTPPath = "folder_path";

        DirectoryInfo salesFTPDirectory = new DirectoryInfo(salesFTPPath);

        IEnumerable<string> files = salesFTPDirectory.GetFiles()
          .Where(f => f.Extension == ".xls" || f.Extension == ".xml" || f.Extension == ".jps" || f.Extension == ".jpg" || f.Extension == ".jpeg" || f.Extension == ".png")
          .OrderBy(f => f.Name)
          .Select(f => f.Name);

        return Json(files, JsonRequestBehavior.AllowGet);
    }

script to get files

$(document).ready(function () {
    $.ajax({
        type: 'GET',
        url: '@Url.Action("filesinfolder", "Home")',
        dataType: "json",
        success: function (data) { onSuccess(data); },
        error: function (xhr, status, err) {}
    });
});

var onSuccess = function (data) {

};

So I want to take the result to onSuccess as list of URLs (for files in a folder).

Aucun commentaire:

Enregistrer un commentaire