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)