0

So i am currently working with js ajax to try to get the user of my Application to upload a Directory and then send the Directory/Files to Server side with ajax.

This is in Visual Studio and im using Chrome, so far i got some Illegal Invocation exceptions or it works but i receive "null" on the Server Side

My Form

<div class="form-group">
    @Html.Label("Directory", "Directory", htmlAttributes: new { @class = "control-label col-xs-6" })
    <div class="col-xs-30">
        <input type="file" name="Directory" id="Directory" style="height: 1.7em; width:100%" webkitdirectory directory multiple />
        </div>
    <button onclick="myFunction()">Click me</button>
</div>

Javascript

<script>

    function myFunction() {

        let files = document.getElementById('Directory').files;

        $.ajax({
            url: "@Url.Action("RecursiveDirectory", "UploadDirectory")",
            cache: false,
            method: 'GET',
            data : { files},
            success : function(result) {
                alert(result.success); 
            }

        });
    }


</script>

Server side

public JsonResult RecursiveDirectory(string data)
        {
            ContentResult contentResult = new ContentResult()
            {
                //Content = JsonConvert.SerializeObject(s)
            };

            return Json(null, JsonRequestBehavior.AllowGet);
        }

Illegal Invocation is what i often got or just null on server side.

  • I don't know how to do that in ASP.net but in JavaScript with Chrome and Firefox it's pretty easy. You can't do that with simple jquery call, you need FormData object. I've written article on my blog how to process directories (it's in Polish but there is Google Translate widget on the right below search) [Directories and upload files via Drag & Drop](https://jcubic.pl/2019/06/upload-katalogow-javascript.html) – jcubic Aug 14 '19 at 07:33
  • Here you have SO question/answer [How to upload and list directories at firefox and chrome/chromium using change and drop events](https://stackoverflow.com/a/39665386/387194) – jcubic Aug 14 '19 at 07:37
  • Thanks a lot i kinda tried that and failed but if its the only possibility and this is what seems to be the Problem i shall try again. – Benjamin Stucki Aug 14 '19 at 08:28

0 Answers0