asp.net.ph

HttpPostedFile.SaveAs Method

System.Web Namespace   HttpPostedFile Class


Saves an uploaded MIME message body to a file on the server.

[ VB ]
Public Sub SaveAs ( _
   ByVal filename As String _
)

[ C# ]
public void SaveAs (
   string filename
);

[ C++ ]
public: void SaveAs (
   String* filename
);

[ JScript ]
public function SaveAs (
   filename : String
);

Parameters

filename
The name of the file.

Example

The following example saves all the files uploaded by the client to a folder named "C:\TempFiles" on the Web server's local disk.

[ VB ]
Dim Loop1 As Integer
Dim TempFileName As String
Dim myFileCollection As HttpFileCollection = Request.Files

For Loop1 = 0 To myFileCollection.Count - 1
    ' Create a new file name.
    TempFileName = "C:\TempFiles\File_" & CStr ( Loop1 ) 
    ' Save the file.
    myFileCollection ( Loop1 ).SaveAs ( TempFileName ) 
Next Loop1


[ C# ]
String TempFileName;
HttpFileCollection myFileCollection = Request.Files;

For ( int Loop1 = 0; Loop1 < myFileCollection.Count; Loop1++ ) {
    // Create a new file name.
    TempFileName = "C:\\TempFiles\\File_" + Loop1.ToString ( );
   // Save the file.
    myFileCollection [ Loop1 ] .SaveAs ( TempFileName );
}
See Also

HttpPostedFile Members   HttpFileCollection Class Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph