I want to list all the files in folder once page loading . so
For that I just created like this
HTML code
<input id="idd" type="file" multiple="true" class="file" data-preview-file-type="text">
Script
@section scripts{
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
url: '/Home/filesinfolder',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$.each(data, function (index, val) {
$('#idd').append('<li><a href="http://'+ val.Url +'" target="_new">' + val.Url + '</a></li>');
});
},
error: function (xhr, status, err) {
console.log('Response code:' + xhr.status);
console.log('[Error:' + err + '] ' + status);
}
});
});
</script>
Controller method
public JsonResult filesinfolder()
{
DirectoryInfo salesFTPDirectory = null;
FileInfo[] files = null;
string salesFTPPath = "C:/filePath";
salesFTPDirectory = new DirectoryInfo(salesFTPPath);
files = salesFTPDirectory.GetFiles();
files = files.OrderBy(f => f.Name).ToArray();
var salesFiles = files.Where(f => f.Extension == ".xls" || f.Extension == ".xml" || f.Extension == ".jps" || f.Extension == ".jpg" || f.Extension == ".jpeg" || f.Extension == ".png");
return Json(salesFiles.ToList());
}
But this is isn't list down anything at all , but once I debug I can see this filesinfolder
method calling and finding files in folder.
` element and append them to it (and remove the `id` from the input)
` but same nothing listdown – kez Dec 14 '15 at 07:35