ASP.NET User Control for Uploading Files to your server. Written By Amos ZoellnerMain Page Abstract:
Many times a web application requires files to be uploaded to the server, which can then be accessed either by the System.IO methods, or by manual review later. This user control creates a simple interface for managing uploaded content by providing support for the file naming and managing, as well as screen for certain file types, size, etc.
The user control creates the following simple interface. (Modify as you wish) Properties/Methods:
Prefix Prefix attatched to begininning of a filename before saving to server (a unique ID, for example). If not given, defaults to empty string.
Folder Folder name within current directory where file will be stored. If not given, defaults to wwwroot If folder does not exist on server, it is created.
FileName FileName to save file as in upload directory. If not given, defaults to file name of uploaded file. If a prefix is specified, it will be appended to the beginning of this filename.
MaxLength Maximum length in Kilobytes of file to upload. If not given, defaults to 100.
Type Setting this to 'text' will allow only Text based files, webpages PDF files, and Word documents to be uploaded. Setting this to 'text/image' will allow most image and text based files to be uploaded. Otherwise, set this to a comma delimited list of allowable extensions. ".doc, .wps" for example.
Upload Called by the 'Upload' button... uploads file to server.
.aspx code for the Web Page with the FileControl on it: MyPage.aspx
file control register:
<%@ Register TagPrefix="Ctrl" TagName="FileControl" Src="FileControl.ascx" %>
form tag: Note the ENCTYPE value, which is required for uploading to occur!