File Source in ASP.NET MVC File Upload
26 Aug 20265 minutes to read
Paste to upload
The Uploader control allows you to upload files using the select or drop option from the file explorer. It also supports pasting to upload the image files. You can upload any currently copied images in the clipboard.
When you paste the image, it will be saved in the server with the filename as
image.png. The file name can be renamed in the server end. You can generate a random name for the file name using thegetUniqueIDmethod.
Refer to the following example.
Server-side configuration for save the paste file
[AcceptVerbs("Post")]
public void Save()
{
var httpPostedFile = HttpContext.Current.Request.Files["UploadFiles"];
var fileSave = HttpContext.Current.Server.MapPath("UploadedFiles");
var fileSavePath = Path.Combine(fileSave, httpPostedFile.FileName);
if (!System.IO.File.Exists(fileSavePath))
{
httpPostedFile.SaveAs(fileSavePath);
// Get the current file name
var oldName = httpPostedFile.FileName;
// Get the additional data as name in server end by corresponding key.
var newName = HttpContext.Current.Request.Form["fileName"];
// Rename the file
File.Move(oldName, newName);
HttpResponse Response = System.Web.HttpContext.Current.Response;
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
// Sending the file path to client side
Response.StatusDescription = fileSavePath;
Response.End();
}
}Directory upload
The Uploader control allows you to upload all files in the folders to server using the directoryUpload property. When this property is enabled, the Uploader control processes the files by iterating through the files and sub-directories in a directory. It allows you to select only folders instead of files to upload.
The directory upload is available only in browsers that support HTML5 directory. The uploader will process directory upload via drag-and-drop in the Edge browser.
Refer to the following example to upload files to the server.
Server-side configuration for save the files of folders
[AcceptVerbs("Post")]
public void Save()
{
var httpPostedFile = System.Web.HttpContext.Current.Request.Files["UploadFiles"];
var fileSave = System.Web.HttpContext.Current.Server.MapPath("UploadedFiles");
// split the folders by using file name
string[] folders = httpPostedFile.FileName.Split('/');
string fileSavePath = "";
if (folders.Length > 1)
{
for (var i = 0; i < folders.Length - 1; i++)
{
var newFolder = Path.Combine(fileSave, folders[i]);
// create folder
Directory.CreateDirectory(newFolder);
fileSave = newFolder;
}
fileSavePath = Path.Combine(fileSave, folders[folders.Length - 1]);
}
else
{
fileSavePath = Path.Combine(fileSave, httpPostedFile.FileName);
}
if (!System.IO.File.Exists(fileSavePath))
{
// save file in the corresponding server location
httpPostedFile.SaveAs(fileSavePath);
HttpResponse Response = System.Web.HttpContext.Current.Response;
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
// Sending the file path to client side
Response.StatusDescription = fileSavePath;
Response.End();
}
}Drag and drop
The Uploader control allows you to drag and drop the files to upload. You can drag the files from file explorer and drop into the drop area. By default, the Uploader control acts as the drop area element. The drop area gets highlighted when you drag the files over drop area.
Custom drop area
The Uploader control allows you to set an external target element as the drop area using the dropArea property. The element can be represented as an HTML element or it’s id.
The output is shown below.

Customize drop area
You can customize the appearance of drop area by overriding the default drop area styles.
The class “” and “” is available to handle this customization.
The output is shown below.

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.