Uploading to disk
The file upload stream provider is a built-in SlickUpload provider that uses the filesystem for uploaded file storage.
Using this provider, SlickUpload can store files to any location your ASP.NET application has access to, including
paths inside the application, other paths on the same server, or a seperate server via a UNC path to a file share.
Configuration
To use the file provider, set the provider="File" attribute on the uploadStreamProvider web.config key. The following
settings allow you to customize the filename and location where the files will be stored:
| Setting |
Description |
| provider |
provider="File"
|
| location |
Required string attribute.
Specifies the path to which to write upload files. Supports the ~/ application root syntax.
This may also be a UNC path to a file share. For example: \\server\file\share\
NOTE: The user ASP.NET is running under (by default ASPNET for XP and IIS_WPG for 2003) must
have write access to the specified path.
|
| existingAction |
Optional ExistingAction attribute.
Specifies what action to take if a file exists with the filename SlickUpload is attempting to
write to. Possible values:
- Exception – Throw an exception, terminating the upload. This is the default.
- Overwrite – Overwrite the file.
- Rename – Append a numeric suffix to the filename to make it unique.
|
| fileNameMethod |
Optional FileNameMethod attribute.
- Client – Use the name of the file from the client. This is the default.
- Guid – Generate a unique Guid for the filename.
- Custom – Use a IFileNameGenerator, specified in the fileNameGenerator attribute, to generate the filename.
|
| fileNameGenerator |
Optional class reference attribute.
Specifies a custom class that implements the IFileNameGenerator interface. Loaded when the fileNameMethod attribute is set to Custom.
|
Controlling filename during upload
To control the filename used during the upload, you can use one of the three file name generation methods defined
above: Client, Guid, and Custom. To generate your own filename (including path if you desire), use the Custom filename
method with a file name generator. For an example of this, look at the FileNameGenerator sample.
Retrieving server filename
After the upload you can get the server filename a file was written to by indexing into the UploadedFile.LocationInfo
dictionary. For example, given an UploadedFile instance named file:
string path = file.LocationInfo[FileUploadStreamProvider.FileNameKey];
|