How to upload files programmatically in ASP.NET Core File Upload

24 Aug 20262 minutes to read

You can upload a file programmatically using the upload method. The selected files data is obtained from the public getFilesData method of the Uploader.

The upload method behaves differently based on its arguments.

  • If this method receives any files as arguments, only those files will start to upload.
  • If it has no arguments, all the selected files will start to upload.
@{
    var asyncSettings = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = "https://services.syncfusion.com/aspnet/production/api/FileUploader/Save", RemoveUrl = "https://services.syncfusion.com/aspnet/production/api/FileUploader/Remove" };
}

<div class="col-lg-8 control-section">
    <div class="control_wrapper">
        <ejs-uploader id="UploadFiles" asyncSettings="@asyncSettings" autoUpload="false">
        </ejs-uploader>
    </div>
    <span style=' padding-left: 40px; margin-top: 30px'>
        <button id='first' class='e-btn e-control'>Upload 0th File</button>
    </span>
    <span style=' padding-left: 40px; margin-top: 30px'>
        <button id='full' class='e-btn e-control'>Upload All Files</button>
    </span>
</div>

<script>
    window.onload = function () {
        var uploadObj = document.getElementById("UploadFiles").ej2_instances[0];
        document.getElementById('first').onclick = (args) => {
            uploadObj.upload(uploadObj.getFilesData()[0]);
        };

        document.getElementById('full').onclick = (args) => {
            uploadObj.upload(uploadObj.getFilesData());
        };
    }
</script>
.control_wrapper {
    max-width: 500px;
    margin: auto;
}

.e-upload {
    width: 100%;
    position: relative;
    margin-top: 15px;
    margin-bottom: 15px;
}

.e-upload-actions {
    display: none;
}

.e-btn {
    text-transform: none;
}

.control_wrapper .e-upload .e-upload-drag-hover {
    margin: 0;
}

Explore the ASP.NET Core File Upload feature tour page to discover its groundbreaking features. You can also check out our ASP.NET Core File Upload example to see how to browse and select files for upload to the server.