array of img tags passing to `initialPreview` property

Web Tips Q & ACategory: Krajee Pluginsarray of img tags passing to `initialPreview` property
kelumkp asked 2 years ago

In the following function’s initialPreview property I want load array of `<img>` tags . for that I’m creating

<input id="id" type="file" multiple="true" class="file">
<script>
$("#id").fileinput({ ......., initialPreview: getFiles(), });
</script>

I just created getFiles() method as follows

 function getFiles() {

var files = [];
$.ajax({
type: 'GET',
url: '@Url.Action("filesinfolder", "Home")',
dataType: "json",
success: function (data) {
$.getJSON(url, function (data) {
$.each(data, function (index, item) {
var img = $('<img>').attr('src', item);
files.push(img.get(0));
console.log(files);
})
return files;
})
},
error: function (xhr, status, err) {

}
})

}

then I wrote following server side method to get files

 public JsonResult filesinfolder()
{
string productid;

productid = "01";

string salesFTPPath = "C:/Users/user/Documents/Visual Studio 2015/Projects/rootProject/project_name/project_name/Content/Essential_Folder/marketing_materials_EN/01";
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" || f.Extension == ".PNG")
.OrderBy(f => f.Name)
.Select(f => f.Name);

// build urls
List<string> urls = new List<string>();
foreach (string name in files)
{
urls.Add(Url.Content("~/Content/Essential_Folder/marketing_materials_EN/" + productid) + "/" + name);
}
return Json(urls, JsonRequestBehavior.AllowGet);
}

But this is not preview any file in that relevant folder , 
 

Login or register to contribute or comment.

Login   Register