Web Forms upload guides
Paste Images into an ASP.NET Web Forms Upload
A user who has a screenshot on the clipboard should not have to save it to disk, find it in a file dialog and then browse to it. In a bug report, a support ticket or a document editor, pasting is the fastest route. AjaxUploader accepts a paste on the uploader itself, with no extra code.
Enable paste
Paste is on by default. An uploader accepts Ctrl+V as soon as it is on the page. Restrict the file types with AllowedExtensions so a pasted file that does not match is rejected in the browser before any bytes are sent:
<au:AjaxFileUpload ID="Screenshot" runat="server"
AutoUpload="true"
ShowProgress="true"
AllowedExtensions="jpg,jpeg,png,gif,webp,bmp"
ButtonText="Browse or Paste (Ctrl+V)" />
Set Paste="false" to turn it off. EnablePaste is an alias for the same property.
What arrives on the clipboard
Two different things can be pasted, and both are handled:
- A screenshot (Print Screen, Win+Shift+S or Cmd+Shift+4) arrives as raw image data with no filename. The uploader names it from the timestamp and image type, for example
Screenshot_20260823_143052.png. A JPEG paste is saved as .jpg.
- A copied file from Explorer or Finder arrives with its real name and type.
Where the paste is accepted
A paste event only reaches an element that can take focus. The uploader gets tabindex="0" when it has none, so the user must click the upload area before pressing Ctrl+V. To accept a paste anywhere on the page, point pasteTarget at a wider element. It takes a CSS selector or an element:
AjaxUploader.create(el, {
uploadUrl: '/ajaxupload.axd/upload',
paste: true,
pasteTarget: 'body'
});
Inspect or refuse a paste
The onPaste callback receives the files the clipboard produced, before anything is queued. Return false to discard the paste. This is useful when a form accepts typed text but should not accept pasted files in one particular field:
onPaste: function (files, uploader) {
if (files.length > 3) { alert('Paste up to three images at a time.'); return false; }
}
The same information is available as a paste event if you prefer uploader.on('paste', ...).
Try the demo
The paste upload demo runs the markup above. Copy an image, click the upload area and press Ctrl+V. For file-type and size rules on the same uploader, see the max file size demo.
Related