UploadedFile.SaveAs(String) Method
Saves the uploaded file specifying the full path on the server.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v24.2.dll
Declaration
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. |
Remarks
Uploading a file specified on the client can be initiated either by the client ASPxClientUploadControl.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 ASPxUploadControl.FileUploadComplete event’s handler. Before calling the SaveAs method, it is recommended to test the FileUploadCompleteEventArgs.IsValid property, to verify whether the uploaded file passes the validation criteria if any have been defined via the ASPxUploadControl.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 relative to the web application folder (by using the 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 UploadedFile.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.
Important
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.
Important
To use the SaveAs method, set the ASPxUploadControl.UploadStorage property to NotSet. Otherwise, files are saved according to predefined settings automatically and the SaveAs method has no effect.
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the SaveAs(String) 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.