Saves an uploaded file to the specified location. Overwriting a file of the same name is allowed..
Namespace:
EasyAlgo.EAUploadAssembly: EasyAlgo.EAUpload (in EasyAlgo.EAUpload.dll)
Version: 1.3.0.0
Syntax
| C# |
|---|
public void SaveAs( string path, bool overwrite ) |
| Visual Basic (Declaration) |
|---|
Public Sub SaveAs ( _ path As String, _ overwrite As Boolean _ ) |
Parameters
- path
- Type: System..::.String
The path to save an uploaded file.
- overwrite
- Type: System..::.Boolean
true if existing file can be overwritten; otherwise false.
Remarks
The path argument is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the application working directory (see also HttpRequest..::.PhysicalApplicationPath).
Method calling affects on StoredFileName property. A new property value depends on path parameter value.
Examples
The following code example demonstrates how to save the uploaded file to the specific location. This code example is part of a larger example provided for the UploadedFile class.
CopyC#
CopyVB.NET
// UploadFile.aspx.cs ... Upload _upload = UploadsManager.GetUpload(); // Define directory to which an uploaded files will be stored. string SaveFolder = Server.MapPath("") + "\\UploadedFiles\\"; if (_upload != null && _upload.Status.State == UploadState.Complete) { // Iterate through uploaded files collection. for (int i = 0; i < _upload.UploadedFiles.Count; i++) { UploadedFile _file = _upload.UploadedFiles[i]; // Save an uploaded file to a specific location // with name that was been on the client's machine. // You can save an uploaded file with any name. // To do that, just specify the required name in "path" parameter of SaveAs method. _file.SaveAs(SaveFolder + _file.QualifiedFileName, true); } } ...
' UploadFile.aspx.vb ... Dim _upload As Upload = UploadsManager.GetUpload ' Define directory to which an uploaded files will be stored. Dim SaveFolder As String = Server.MapPath("") & "\UploadedFiles\" If ((Not _upload Is Nothing) AndAlso (_upload.Status.State = UploadState.Complete)) Then Dim i As Integer ' Iterate through uploaded files collection. For i = 0 To _upload.UploadedFiles.Count - 1 Dim _file As UploadedFile = _upload.UploadedFiles.Item(i) ' Save an uploaded file to a specific location ' with name that was been on the client's machine. ' You can save an uploaded file with any name. ' To do that, just specify the required name in "path" parameter of SaveAs method. _file.SaveAs(SaveFolder & _file.QualifiedFileName, True) Next i End If ...
Exceptions
| Exception | Condition |
|---|---|
| System..::.ArgumentNullException | Thrown when the specified path is nullNothingnullptra null reference (Nothing in Visual Basic). |
| EasyAlgo.EAUpload..::.EAUploadException | Thrown if overwrite is falseFalsefalsefalse (False in Visual Basic) and the destination file already exists. |
| System..::.UnauthorizedAccessException | Thrown if ASP.NET process does not have write permissions to the specified path |
