Uploading in ASP.NET |
 |
The following VB.NET example uploads a file from an HTML form to a Web server.
SoftArtisans FileUpEE processes the upload on the server. |
| To allow file uploads, NTFS permissions must be set
appropriately for FileUpEE's temporary and destination directories.
For more information, see
Security Considerations.
|
|
A 100K size limit has been set on upload samples.
The example includes two scripts:
Vb-form.aspx
Vb-form.aspx contains the upload form. The HTML form submitting the file must contain:
- The
<form> tag attribute ENCTYPE="multipart/form-data".
- An
<input type="file"> tag, including a <name> attribute.
Vb-webserver.uplx
Vb-webserver.uplx is the FileUpEE upload
processing script. It saves the upload on the Web server.
The FileUpEE objects are in the SoftArtisans.Net
namespace. The objects can be referenced as fully qualified names, such as
SoftArtisans.Net.FileUpEE. To minimize typing and errors,
use an Import directive to import the namespace to the ASP.NET
page. This allows you to reference objects by name alone, without the namespace prefix.
Following the Page directive in the aspx page, include:
<%@Import namespace="SoftArtisans.Net"%>
The following lines process the upload request, and save the uploaded
file:
Dim oFileUpEE As New FileUpEe()
Creates an instance of FileUpEE.
oFileUpEE.TransferStage = saTransferStage.saWebServer
Specifies the stage of an upload, which may be either Web server or file server.
Always set this property. Set TransferStage
immediately after creating an instance of FileUpEE.
oFileUpEE.ProcessRequest(Page.Request, False, False)
Passes the Request object to FileUpEE. This instructs FileUpEE to read the upload request
and populate the Files and Form collections.
oFileUpEE.DestinationDirectory = Server.MapPath(String.Format("{0}/temp", Application("sampleroot")))
Sets the destination directory for the uploaded file.
oFile.DestinationFileName = oFile.ClientFileName
Sets the destination file name to the file's original name.
oFile.Save()
Saves the file.
When you are finished using an instance of FileUpEE under .NET, always call
FileUpEE.Dispose() to ensure thorough cleanup of temporary files.
Finally
oFileUpEE.Dispose()
End Try
Top
A 100K size limit has been set on upload samples.
Note: The C# Language does not support parameterized properties. Due to this language limitation,
to access a parameterized property of the FileUpEE object model,
you will need to call the property's 'getter' or 'setter' method directly.
For example:
<%@Page language="C#"%>
<%@Import namespace="SoftArtisans.Net"%>
<%
FileUpEE objFileUpEE = New FileUpEE();
// This will cause a compiler error
//objFileUpEe.MaxKBytesToCancel(saTransferStage.saWebServer) = 200;
// Instead use
objFileUpEE.set_MaxKBytesToCancel(saTransferStage.saWebServer, 200);
...
%>
|
Top
Copyright © 2003, SoftArtisans, Inc.