New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Auto Saving to a Target Folder

RadUpload has been replaced by RadAsyncUpload, Telerik’s next-generation ASP.NET upload component. If you are considering Telerik’s Upload control for new development, check out the documentation of RadAsyncUpload or the control’s product page. If you are already using RadUpload in your projects, you may be interested in reading how easy the transition to RadAsyncUpload is and how you can benefit from it in this blog post. The official support for RadUpload has been discontinued in June 2013 (Q2’13), although it is still be available in the suite. We deeply believe that RadAsyncUpload can better serve your upload needs and we kindly ask you to transition to it to make sure you take advantage of its support and the new features we constantly add to it.

To enable RadUpload to automatically save files to a folder, all you must do is set a single property, giving the directory where the files should be saved. Which property you use depends on whether you are using a virtual path name or a physical path name:

  • The TargetFolder property specifies the name of an existing virtual path such as "~/UploadedFiles". This virtual path is internally resolved to a physicalpath by a call to the Server.MapPath() method. Using virtual paths can make your application more portable.

  • The TargetPhysicalFolder property specifies the name of an existing physical path where files should be saved. Using physical paths is useful for applications that need to upload files to the same location, regardless of how they are deployed.

If you set both the TargetFolder and TargetPhysicalFolder properties, RadUpload uses the TargetPhysicalFolder property.

When you enable automatic file saving using the TargetFolder or TargetPhysicalFolder properties, files are saved to the target folder with their original names from the client computer. Some files may still not be saved to the specified folder:

  • If you are using the integrated validation, invalid files are not saved to the target folder. You can, however, still access them using the server-side API.

  • By default, if a file with the same name as an uploaded file already exists in the target directory, RadUpload does not overwrite the existing file. There are two approaches you can take to deal with name clashes:

    • You can allow RadUpload to overwrite existing files in the target directory by setting the OverwriteExistingFiles property to True.

    • You can write special code to handle the name clash using the FileExists event.

The following example illustrates how to implement automatic file saving. The uploaded files are saved in the "~/MyFiles" folder, overwriting any existing files:

<telerik:radupload id="RadUpload1" runat="server" overwriteexistingfiles="true" targetfolder="~/MyFiles" />
<asp:Button runat="server" ID="Button1" Text="Submit" />
In this article