The following saves the uploaded file from form element "Form1" on the Web server
at C:\Uploads:
ASP |
<% '--- Instantiate FileUp Set fileUpload = Server.CreateObject("SoftArtisans.FileUp")
'--- Cache upload at C:\Uploads fileUpload.Path = "C:\Uploads"
'--- Save upload at C:\Uploads fileUpload.Form("File1").Save %>
|
C# |
//--- Instantiate FileUp FileUp fileUpload = new FileUp(Context);
//--- Set default Save location to C:\Uploads //--- (Cache location is set in registry since HttpModule is used //--- with .NET) fileUpload.Path = "C:\\Uploads";
//--- Save upload to C:\Uploads fileUpload.Form["File1"].Save();
|
VB.NET |
'--- Instantiate FileUp Dim fileUpload As New FileUp(Context)
'--- Set default Save location to C:\Uploads '--- (Cache location is set in registry since HttpModule is used '--- with .NET) fileUpload.Path = "C:\Uploads"
'--- Save upload to C:\Uploads fileUpload.Form("File1").Save()
|
The following saves the uploaded file from form element "File1" to a network shared
drive:
ASP |
<% '--- Instantiate FileUp Set fileUpload = Server.CreateObject("SoftArtisans.FileUp")
'--- Cache upload at \\FileServer\Uploads fileUpload.Path = "\\FileServer\Uploads"
'--- Save upload to \\FileServer\Uploads fileUpload.Form("File1").Save %>
|
C# |
//--- Instantiate FileUp FileUp fileUpload = new FileUp(Context);
//--- Set default Save location to \\FileServer\Uploads //--- (Cache location is set in registry since HttpModule is used //--- with .NET) fileUpload.Path = @"\\FileServer\Uploads";
//--- Save upload to \\FileServer\Uploads fileUpload.Form["File1"].Save();
|
VB.NET |
'--- Instantiate FileUp Dim fileUpload As New FileUp(Context)
'--- Set default Save location to \\FileServer\Uploads '--- (Cache location is set in registry since HttpModule is used '--- with .NET) fileUpload.Path = "\\FileServer\Uploads"
'--- Save upload to \\FileServer\Uploads fileUpload.Form("File1").Save()
|
The following snippet taken from the "SaveAllInLoop" sample, demonstrates the checks
neccessary to avoid errors when calling the Save method on a file:
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 fileUpload.Form(strFormElement).Save
Response.Write "<td>File</td><td>"
&_
"strFormElement & </td><td>Saved
as: " & _
fileUpload.Form(strFormElement).ServerName
& _ "</td>"
End If
End If %>
|
C# |
//--- If it's a SaFile object, it's a file if(oFormExItem[1] is SaFile) { SaFile file = (SaFile)oFormExItem[1];
//--- Check to be sure the file element isn't empty if(!file.IsEmpty) { //--- It's not empty, so we'll save it file.Save();
results.Append("<td>File</td><td>"
+
item.ToString() +
"</td><td>Saved
as: " +
file.ServerName + "</td>"); } else { //--- It's empty, just write a message results.Append("<td>File</td><TD>"
+
item.ToString() &
"</td>" + "<td>(empty)</td>"); } }
|
VB.NET |
'--- If it's a SaFile object, it's a file If (oFormExItem(1).GetType() Is GetType(SaFile)) Then
Dim file As SaFile = CType(oFormExItem(1), SaFile)
'--- Check to be sure the file element isn't empty If Not (file.IsEmpty) Then
'--- It's not empty, so we'll save it file.Save()
results.Append("<td>File</td><td>"
+_ item.ToString() + "</td><TD>Saved
as: " + _ file.ServerName + "</td>")
Else
'--- It's empty, just write a message results.Append("<TD>File</td><td>"
+_ item.ToString() + "</td>"
+ _
"<td>(empty)</td>") End If
'--- If it's "string", it's just a standard '--- form element ElseIf(oFormExItem(1).GetType() Is GetType(String)) Then
results.Append("<td>Form single value</td><td>"
+_ item.ToString() + "</td><td>" +
_ oFormExItem(1).ToString() + "</td>")
End If
|
|