# Copy and Paste Files in the Upload

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Upload</td>
 </tr>
 <tr>
  <td>Progress Telerik UI for ASP.NET MVC version</td>
  <td>Created with the 2022.2.802 version</td>
 </tr>
</table>

## Description

How can I copy and paste a file into the Telerik UI for ASP.NET MVC Upload?

## Solution

1. Create a paste container and decorate it with the `contenteditable` HTML attribute.
2. To paste a copied file, handle the `paste` event of the container.
3. To insert the newly pasted file, use the `DataTransfer` object within the handler.

```Razor Index.cshtml
    @(Html.Kendo().Upload()
        .Name("files")
        .Async(a => a
            .Save("Async_Save", "Upload")
            .Remove("Async_Remove", "Upload")
            .AutoUpload(false)
        )
    )

    <div class="paste-area" contenteditable="true">
        Paste Area
    </div>
```

```JS script.js
    <script>
        $(function(){
            $(".paste-area").on("paste", function(e){
                if (e.originalEvent.clipboardData.files.length) { // Assert if a file is pasted.
                    const fileObject = e.originalEvent.clipboardData.files[0]; // Get the pasted file object.

                    const fileInput = $("#files")[0]; // Get the file input.
                    const dataTransfer = new DataTransfer(); // Create a new DataTransfer object instance.

                    dataTransfer.items.add(fileObject) // Add the pasted file object to the DataTransfer object.
                    fileInput.files = dataTransfer.files; // Change the file input's files.

                    $("#files").trigger("change"); // Trigger the change event of the Upload.
                } else {
                  alert(
                    "No image data was found in your clipboard. Copy an image first or take a screenshot."
                  );
                }
            });
        });
    </script>
```

For the complete implementation of the suggested approach, refer to the following [Telerik REPL](https://netcorerepl.telerik.com/mmOsQJlh07s1j6qK25) example.

## More ASP.NET MVC Upload Resources

* [ASP.NET MVC Upload Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/upload/overview)

* [ASP.NET MVC Upload Demos](https://demos.telerik.com/aspnet-mvc/upload)

* [ASP.NET MVC Upload Product Page](https://www.telerik.com/aspnet-mvc/upload)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Telerik REPL: Copy and Paste Files in the Upload](https://netcorerepl.telerik.com/mmOsQJlh07s1j6qK25)
* [Client-Side API Reference of the Upload for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/upload)
* [Server-Side API Reference of the Upload for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/upload)
* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)
* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
