SaveAs Method

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

This method saves an uploaded file to the web server's hard disk.

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.

See also the SaveAs method for the SAFileUp object.

Examples:

The following sets the Path property to C:\Temp and saves the uploaded file from form element "File1" 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.Form("File1").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.Form["File1"].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.Form("File1").SaveAs("C:\Uploads\" + fileUpload.Form("File1").ShortFileName)

The following sets the Path property to C:\Temp and saves the uploaded file from form element "File1" 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.Form("File1").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.Form["File1"].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.Form("File1").SaveAs("\\FileServer\Uploads\" + _
fileUpload.form("File1").ShortFileName)

The following demonstrates the checks that should be made on a file before calling SaveAs:

ASP <%
If IsObject(fileUpload.Form(strFormElement)) Then

'--- It's a file element,
'--- so we'll see if it's empty or not
If Not fileUpload.Form(strFormElement).IsEmpty Then

'--- It's not empty, so we'll save it
strPath = "c:\SaveLocation\myfirstfile.txt"
fileUpload.Form(strFormElement).SaveAs(strPath)
End If
End If
%>
C# if(file1 != null)
{
if(!file1.IsEmpty)
{
file1.SaveAs("C:\\SaveLocation\\myfirstfile.txt");
}
}
VB.NET If Not (file1 Is Nothing) Then
If Not (file1.IsEmpty) Then

file1.SaveAs("c:\SaveLocation\myfirstfile.txt")
End If
End If

Copyright © 2010 SoftArtisans, Inc. All rights reserved.