With the help of the FileUpload control in vs2005, the paper uploads the picture file and generates the thumbnail.
Implementation process: Choose the image upload success, get already existing server file generation thumbnail, and judge whether it is a picture type of file, this judgment can be modified in the program, this procedure just judged the "image/bmp", "Image/gif", "Image/pjpeg" three different types.
The code is as follows:
upfile.aspx file
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Upfile.aspx.cs" Inherits = "Upfile_upfile" %>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt D ">
< html xmlns = "http://www.w3.org/1999/xhtml" >
< head runat = "server" >
< title > Untitled page </title >
< BODY >
< form ID = "Form1" runat = "server" >
< div >
< Asp:fileupload ID = "FileUpload1" runat = "server"/>
< Asp:button ID = "Button1" runat = "server" OnClick = "Button1_Click" Text = "Upload"/>< br/>
< Asp:label ID = "Label1" runat = "server" ></Asp:label ></div >
</form >
</Body >
</HTML >
Upfile.aspx.cs file
Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.IO;
public partial class Upfile_upfile:System.Web.UI.Page
... {
protected void Page_Load (object sender, EventArgs e)
... { }
protected void Button1_Click (object sender, EventArgs e)
... {
if (fileupload1.hasfile)
... {
string filecontenttype = FileUpload1.PostedFile.ContentType;
if (Filecontenttype = = "Image/bmp" | | | filecontenttype = "Image/gif" | | filecontenttype = "IMAGE/PJPEG")
... {
String name = FileUpload1.PostedFile.FileName; Client file path
FileInfo file = new FileInfo (name);
String fileName = file. Name; File name
String filename_s = "S_" + file. Name; Thumbnail file name
String filename_sy = "Sy_" + file. Name; Watermark image file name (text)
String FILENAME_SYP = "Syp_" + file. Name; Watermark image file name (picture)