Skip to main content
A newer version of this page is available. .
Tab

UploadedFile.SaveAs(String, Boolean) Method

Saves the uploaded file on the server.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v19.2.dll

Declaration

public void SaveAs(
    string fileName,
    bool allowOverwrite
)

Parameters

Name Type Description
fileName String

A String value that specifies the full path to the location on the server to save the uploaded file.

allowOverwrite Boolean

true to overwrite the specified file, if it already exists; otherwise, false.

Remarks

Uploading a file specified on the client can be initiated either by the client Upload method, using the upload button or automatically on the next round trip to the server. The SaveAs method can be used to save the uploaded file to a specific location on the server. Typically, the SaveAs method is called within the FileUploadComplete event’s handler. Before calling the SaveAs method, it is recommended to test the IsValid property, to verify whether the uploaded file passes the validation criteria, if any have been defined via the ValidationSettings property, or specific custom code.

The SaveAs method’s parameter value represents the full path on the server where the uploaded file should be saved. This path can either be absolute (for instance, “C:/Documents/Image.jpg”) or relate to the web application’s folder (by using the System.Web.HttpServerUtility.MapPath method). When composing the saved file’s path, you can define any custom name for the file or use the name obtained by the FileName property.

Note

  • To be able to save the uploaded file, the ASP.NET application should have write access to the specified directory on the server. If the full path file is not indicated, the file will be saved to the current location. If the file with the specified name already exists, this file will be overwritten.
  • The SaveAs method is not in effect if the file hasn’t been uploaded to the server because of specific limitations defined within the web.config file’s httpRuntime section; in particular, the maxRequestLength and executionTimeout attribute settings may affect file uploading. You can define the values of these attributes using the “Set Uploading Properties in web.config“ dialog, available via the ASPxUploadControl‘s smart tag.
  • To use the SaveAs method, set the UploadStorage property to NotSet. Otherwise, files are saved according to predefined settings automatically and the SaveAs method has no effect.

Example

for (int i = 0; i < uploadControl.UploadedFiles.Length; i++){
    UploadedFile file = uploadControl.UploadedFiles[i];
    if (file.FileName != ""){
        string fileName = string.Format("{0}{1}", MapPath("~/Images/"), file.FileName);
        file.SaveAs(fileName, true);
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the SaveAs(String, Boolean) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also