Uploading a File to the Server

To upload a file to the server, you should add the FileUploadControl and FileUploadActions control to the page and set the FileUploadControlID property to the correct id of the FileUploadControl.

The FileUploadControl integrates itself to the page, initializes the file upload engine and uses the file upload entry-point page to select file(s) (this uses the default template uploadiframe.aspx). All other controls should be assigned with the FileUploadControl via the FileUploadControlID property.

The FileUploadActions control shows the file upload command buttons: Show, Hide, Upload, Cancel. The user will be able to press the Show command to show the file upload entry-point. The following images show these examples.

Show button

Hide & Upload button

 

Cancel button

The user will specify the file(s) to upload by entering the full path to the file on the local computer or by selecting the file(s) using the Browse button which will allow them to locate them in the Choose File dialog box. While the file(s) are uploading to the server the user can cancel the upload by clicking the Cancel button or command. The user can hide the upload panel by clicking the Hide button.

The FileUploadControl Control

The FileUploadControl control does not automatically save file(s) to the server after the user selects the file. The user should use the FileUploadActions control and click the Upload button to begin or initiate their upload. The FileUploadControl uploads the file(s) to temporary file storage without having to submit the page. This enables you to upload both the file and also perform edits to related information simultaneously.

When you submit the page, the Files property of the FileUploadControl control retrieves uploaded file information and places it in the collection of FileStreamInfo. The FileStreamInfo class represents common information about file, including: Name, Size, ContentTypeName.   It also contains a reference to temporary storage (ProviderName SessionUid, FileStreamUid). The file name that this property returns does not include the path to the file on the client.

The code that you write to save the specified file should call the SaveAs method or the request file stream from TempFileStorageProvider. SaveAs methods can save the content of a file to a specified path on the server or to a sql server table row.

When you call the SaveAs (to local disk) method, you must specify the full path to the directory in which you want to save the uploaded file. The SaveAs (to local disk) method copies files from temporary storage to the specified directory.

Therefore, the ASP.NET application you are creating must have write access to the directory on the server.  There are two ways that the application you have written can get write access.

1)     You can explicitly grant write access to the account under which the application is running as well as to the directory in which the uploaded files will be saved.

2)     Alternatively, you can increase the level of trust that is granted to the ASP.NET application. To get write access to the executing directory for the application, the application must be granted the AspNetHostingPermission object with the trust level set to the System.Web.AspNetHostingPermissionLevel.Medium value. Increasing the level of trust also increases the application's access to resources on the server. Note: This is not a secure approach because a malicious user who gains control of your application will also be able to run under this higher level of trust. It is a best practice to run an ASP.NET application in the context of a user with the minimum privileges that are required for the application to run. For more information on security in ASP.NET applications, see Basic Security Practices for Web Applications and ASP.NET Trust Levels and Policy Files.

When you call the SaveAs (to sql table) method, you must specify the connection string, table name, column name (for the column that the current file stream will encapsulate), and the primary key of the row. The SaveAs (to sql table) method copies a file(s) from temporary storage to the specified row column.  Therefore, the sql row should already be created and the column data type should be set to image (A variable-length stream of binary data).

Use the ReleaseFile or ReleaseAll method to release temporary file(s) after save file(s) to persistent storage.

Use the Provider property to get the current TempFileStorageProvider. By, using TempFileStorageProvider you can work with the TempFileStorage directly. For example, you can request a file stream and then perform a save file to your own custom persistent file storage.

Use the FilesNotUploadedQuestion property to set the question text if some files are not uploaded before form submitting.  The user can press the Ok button to upload file and submit form again or Cancel button to cancel files selection. Set empty string, to disable question.

Use the ModeType property to define the file upload behavior such as: IFrame, PopUp or Embedded. Note: IFrame is the default value.

Additionally, you can modify the default file upload entry-point page (uploadiframe.aspx or uploadembedded.aspx or uploadpopup.aspx) that is included with the Mediachase FileUploader.NET package and customize it to your own style and needs.

Confirm message

Use the ModeType property to define the file upload behavior such as: IFrame, PopUp or Embedded. Note: IFrame is the default value.

Additionally, you can modify the default file upload entry-point page (uploadiframe.aspx or uploadembedded.aspx or uploadpopup.aspx) that is included with the Mediachase FileUploader.NET package and customize it to your own style and needs.

The FileUploadActions Control

The FileUploadActions control visualizes the FileUploadControl command set and allows you to interact with the user in many different ways.

FileUploadAction Designer View

You should assign the FileUploadControlID with the current ID of the FileUploadControl.

Use the ShowActionText, HideActionText, UploadActionText and CancelActionText properties to set the command text. Default values are Show, Hide, Upload, Cancel.

Use the DisplayShow, DisplayHide, DisplayUpload and DisplayCancel properties to show or hide commands that you want to display to the user.

To override the command view, you can use the command view template. Available templates are described in the following table and can be used to customize the appearance of the list.

 

Template name

Description

ShowTextTemplate

Defines the content and layout of show command.

HideTextTemplate

Defines the content and layout of hide command.

UploadTextTemplate

Defines the content and layout of upload command.

CancelTextTemplate

Defines the content and layout of cancel command.

 

You can get a more infomation about templates that can be used in the FileUploadAction control from using the included code samples provided in the Mediachase FileUploader.Net control package.

Copyright 2007 Mediachase. All rights reserved.