ASP.NET 2.0 Instant Results
.pdfChapter 11
Property Name |
Type |
Default Value |
Description |
|
|
|
|
GenerateDateFolder |
Boolean |
False |
Determines whether |
|
|
|
subfolders are created for |
|
|
|
the current year and |
|
|
|
month to store the file in. |
|
|
|
This is useful when you |
|
|
|
have a lot of uploaded |
|
|
|
files and want to store |
|
|
|
them in logical folders. |
GenerateUniqueFileName |
Boolean |
False |
Determines whether the |
|
|
|
file gets a unique name. |
|
|
|
When set to True, the |
|
|
|
property FileName is |
|
|
|
ignored and the file is |
|
|
|
saved with a GUID as |
|
|
|
its name. |
OverwriteExistingFile |
Boolean |
False |
Determines whether |
|
|
|
existing files should be |
|
|
|
overwritten when they |
|
|
|
already exist. |
VirtualSavePath |
String |
n/a |
Gets or sets the virtual |
|
|
|
path to the folder where |
|
|
|
the uploaded files should |
|
|
|
be saved. This property |
|
|
|
is updated when |
|
|
|
GenerateDateFolder is |
|
|
|
True. |
|
|
|
|
Once these properties have been set, your code should call the class’s only public method UploadFile and pass it an instance of an <asp:FileUpload> control. This method carries out some checks using the private FileExists and IsExtensionAllowed methods and then either saves the uploaded file to disk or throws an exception. The following table describes the three methods (other than its constructor) of the UploadHandler class:
Method |
Return Type |
Description |
|
|
|
FileExists |
Boolean |
Returns True when a file with the same name |
|
|
already exists. |
IsExtensionAllowed |
Boolean |
Returns True when the extension of the |
|
|
uploaded file meets the criteria set in the |
|
|
AllowedExtensions property. |
UploadFile |
n/a |
This method is the workhorse of the |
|
|
UploadHandler class. It performs a number |
|
|
of checks on extensions, paths, and so on, |
|
|
and then saves the file to disk or throws an |
|
|
exception. |
|
|
|
360