SaveAs Method

Object: SoftArtisans.FileUp
Syntax: SaveAs([in] Filename As String)
Description:

This method saves an uploaded file to the Web server's hard disk. If an upload contains more than one file, only the first one is saved.

To save multiple files in a single upload, use the method SAFile object's SaveAs() method: File.SaveAs.

SaveAs takes a physical path for its Filename argument. This can be provided in one of two ways:

  • Provide a complete physical path and file name.
  • Provide only a name for the file. SaveAs will take the directory path from the Path property.

If no path is specified (e.g., fileUpload.SaveAs "FileX.ext"), the value of the Path property is used. For more efficient processing, it is recommended that you always use set the Path property before saving any files.

If the Filename parameter includes a file path, it must specify a physical path (for example "C:\UploadDir\FileX.ext"). You cannot pass a virtual path to the SaveAs method.

By default, an uploaded file will overwrite a file on the server with the same name. To prevent this, set OverwriteFilesto False.

Examples:

The following sets the Path property to C:\Temp and saves the upload on the Web server at C:\Uploads:

ASP <%
'--- Instantiate FileUp
Set fileUpload = Server.CreateObject("SoftArtisans.FileUp")

'--- Cache upload to C:\Temp
fileUpload.Path = "C:\Temp"

'--- Save upload to C:\Uploads using the original filename of the
'--- file
fileUpload.SaveAs "C:\Uploads\" & fileUpload.Form("File1").ShortFileName
%>
C# //--- Instantiate FileUp
FileUp fileUpload = new FileUp(Context);

//--- Set default Save location to C:\Temp
//--- (Cache location is set in registry since HttpModule is used
//--- with .NET)
fileUpload.Path = "C:\\Temp";

//--- Save upload to C:\Uploads using the original filename of the
//--- file
fileUpload.SaveAs("C:\\Uploads\\" + fileUpload.Form("File1").ShortFileName);
VB.NET '--- Instantiate FileUp
Dim fileUpload As New FileUp(Context);

'--- Set default Save location to C:\Temp
'--- (Cache location is set in registry since HttpModule is used
'--- with .NET)
fileUpload.Path = "C:\Temp"

'--- Save upload to C:\Uploads using the original filename of the
'--- file
fileUpload.SaveAs("C:\Uploads\" + fileUpload.Form("File1").ShortFileName)

The following sets the Path property to C:\Temp and saves the upload to a network shared drive:

ASP <%
'--- Instantiate FileUp
Set fileUpload = Server.CreateObject("SoftArtisans.FileUp")

'--- Cache upload to C:\Temp
fileUpload.Path = "C:\Temp"

'--- Save upload to \\FileServer\Uploads using the original
'--- filename of the file
fileUpload.SaveAs "\\FileServer\Uploads" & fileUpload.Form("File1").ShortFileName
%>
C# //--- Instantiate FileUp
FileUp fileUpload = new FileUp(Context);

//--- Set default Save location to C:\Temp
//--- (Cache location is set in registry since HttpModule is used
//--- with .NET)
fileUpload.Path = "C:\\Temp";

//--- Save upload to \\FileServer\Uploads using the original
//--- filename of the file
fileUpload.SaveAs("\\FileServer\Uploads\" & fileUpload.form("File1").ShortFileName);
VB.NET '--- Instantiate FileUp
Dim fileUpload As New FileUp(Context)

'--- Set default Save location to C:\Temp
'--- (Cache location is set in registry since HttpModule is used
'--- with .NET)
fileUpload.Path = "C:\Temp"

'--- Save upload to \\FileServer\Uploads using the original '--- filename of the file
fileUpload.SaveAs("\\FileServer\Uploads\" + fileUpload.form("File1").ShortFileName)

Copyright © 2010 SoftArtisans, Inc. All rights reserved.