Use the FileUpload control to upload pictures and automatically generate thumbnails, automatically generate a watermark with text and pictures (original)

Source: Internet
Author: User
 Posted on 2006-05-05 12:55 0 Reading (3146) Comments (9) Edit favorite References NET picks belong to Category: asp.net2.0--> This article uses the FileUpload control in vs2005 to realize the upload of picture files and generate thumbnails.
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.dtd ">

< 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.