FileUpload upload image directly to browse the display (no upload button how to upload)

Source: Internet
Author: User

1. Add a onchange event to FileUpload: FileUpload1.Attributes.Add ("onchange", "document.getElementById (' IMGP ')." Src= This.value ");

2, the original is a separate upload event, now there is no upload button, upload the event (code) directly into the Insert (Submit information) button to execute the event.

protected void btnSubmit_Click (object sender, EventArgs e)
{
if (IsValid)

{

Perform upload events first

String picname = "";
String newpicname = "";
string file = "/images/small/";
String NewPath = "/images/small/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "-" + DateTime.Now.Day + "/";
Uploadpicture.creatdirectory (NewPath);

...........................

You can also add a well-done watermark at this time

Picname = Uploadinfo (fulimage, file);
Newpicname = Uploadinfo (Fulimage, NewPath);

System.Drawing.Image Image = System.Drawing.Image.FromFile (Server.MapPath (picname));
System.Drawing.Image copyimage = System.Drawing.Image.FromFile (Server.MapPath ("/images/shuiyin.jpg"));
Graphics g = graphics.fromimage (image);
G.drawimage (Copyimage, new Rectangle (image). Width-copyimage.width, image. Height-copyimage.height, Copyimage.width, Copyimage.height), 0, 0, Copyimage.width, Copyimage.heigh T, GraphicsUnit.Pixel);
G.dispose ();
Save the image after the watermark, delete the original image
Image. Save (Server.MapPath (newpicname));
Image. Dispose ();
if (File.exists (Server.MapPath (picname)))
File.delete (Server.MapPath (picname));

}
{

FileUpload upload image directly to browse the display (no upload button how to upload)

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.