Tab

ASPxUploadControl.SaveAs(String, Boolean) Method

Obsolete. Saves the uploaded file specifying the full path on the server.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.dll

Declaration

[Obsolete("Use the UploadedFiles[].SaveAs method instead.")]
public void SaveAs(
    string fileName,
    bool allowOverwrite
)
<Obsolete("Use the UploadedFiles[].SaveAs method instead.")>
Public Sub SaveAs(
    fileName As String,
    allowOverwrite As Boolean
)

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 the file specified on the client can be initiated either by the ASPxUploadControl's ASPxClientUploadControl.Upload method, 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 ASPxClientUploadControl.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 relate to the web application's 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 ASPxUploadControl.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 file full path 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.

Note that 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.

Examples

The following sample code demonstrates how to save the file specified within the ASPxUploadControl on the client. Before file saving, the FileUploadCompleteEventArgs.IsValid property is tested to verify whether the file passes the validation criteria defined via the ASPxUploadControl.ValidationSettings property. Note, that in order to compose the ASPxUploadControl.SaveAs method's parameter value, the HostingEnvironment.MapPath(String) method and ASPxUploadControl.FileName property are used to specify the web application's Image folder as a location where the file should be saved and define the file's name, respectively.

protected void ASPxUploadControl1_FileUploadComplete(object sender, 
DevExpress.Web.FileUploadCompleteEventArgs e) {
    if (e.IsValid) {
        e.UploadedFile.SaveAs(MapPath("Images/" + e.UploadedFile.FileName));
    }
}
See Also