Rich controls mainly include:
(1) fileupload Control
(2) calender Control
(3) adrotator Control
(4) multiview Control
(5) wizard Control
This document describes the simple usage of the fileupload control.
1. The fileupload control is used by the user to apply to the WebProgramUpload a file.
(1) Save the file to the file system
In the fileupload control, browse and select the local file to be uploaded, and click OK to upload the file,CodeAs follows:
Protected void button#click (Object sender, eventargs E)
{
If (fileupload1.hasfile)
{
If (checkfiletype (fileupload1.filename ))
{
String dpath = mappath ("~ /Uploadfile ");
Directoryinfo DR = new directoryinfo (dpath );
If (! Dr. exists)
Dr. Create (); // if the specified image storage directory does not exist, this directory is created.
String filepath = "~ /Uploadfile/"+ fileupload1.filename;
Fileupload1.saveas (mappath (filepath); // Save the uploaded file
Datalist1_databind ();
}
}
}
The checkfiletype method is used in the process to determine the type of the uploaded file.
Bool checkfiletype (string filename)
{
String ext = path. getextension (filename );
Switch (EXT)
{
Case ". GIF ":
Return true;
Case ". jpg ":
Return true;
Case "Jpeg ":
Return true;
Default:
Return false;
}
}
(2) Save the file to the database
You can use the fileupload control to save files to the database.
Idea: Obtain the filebytes attribute content of the fileupload control and save the content to the corresponding fields of the database.
Available when reading files in the database
Context. response. binarywrite (File );
Method to display the file content in the browser.
(3) Upload large files
You need to do some extra work to upload large files. Do not use the server's entire memory to accommodate the entire large file to be uploaded. When processing large files, you need to use multiple managed memory blocks to process files.
First, configure the application to process large files. Two configuration items affect the submission of large files to the server:
Httpruntime maxrequestlength and httpruntime requestlengthdiskthreshold.
The maxrequestlength configuration item specifies the maximum value that the submitted form can receive by the server. The default value is 4 MB.
The requestlengthdiskthreshold configuration item determines how to cache the upload form in the file system. When the file size exceeds the set value of requestlengthdiskthreshold (80 KB by default), the remaining part of the file is cached in the file system (Asp.net Temporary Folder.
Note: requestlengthdiskthreshold <maxrequestlength
Configuration is required for uploading large files in Web. config.
<System. Web>
<Httpruntime maxrequestlength = "102400" requestlengthdiskthreshold = "100"/>
</System. Web>
2. Display calendar
The calender control is used to display the calendar. This control is not complicated and does not take notes here.
3. Display Advertisement
The adrotator control is used to randomly display different advertisements on the page. You can save the ad list in an XML file or database table.
4. display different page views
The mutiview control is used to display and hide different areas of a page. This control is useful when you need to create a tab page (tabbed page.
In useMutiviewNormallyMenuControls andViewControl.
5. Display wizard
Like the mutiview control, the wizard control can be used to divide a large form into multiple subforms. However, the wizard control has more advantages that the mutiview control does not support.