Hi Demon1,
* Small image preview before start upload or after upload completed
The example below shows you how to generate the preview image after upload completed.
- <%@ Page Language="C#" %>
-
- <%@ Import Namespace="CuteWebUI" %>
- <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
- <script runat="server">
-
- protected override void OnInit(EventArgs e)
- {
- base.OnInit(e);
-
- string st = Request.QueryString["ShowThumbnail"];
- if (st != null)
- {
- MvcUploader uploader = new MvcUploader(Context);
- Guid guid = new Guid(st);
- MvcUploadFile file = uploader.GetUploadedFile(guid);
- if (file == null)
- {
- Response.StatusCode = 404;
- Response.Write("Invalid File : " + guid);
- Response.End();
- }
-
- using (System.Drawing.Image thumbnail = new System.Drawing.Bitmap(64, 64, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
- {
- using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(thumbnail))
- {
- using (Stream stream = file.OpenStream())
- {
- using (System.Drawing.Image img = System.Drawing.Image.FromStream(stream))
- {
- g.DrawImage(img
- , new System.Drawing.Rectangle(0, 0, thumbnail.Width, thumbnail.Width)
- , new System.Drawing.Rectangle(0, 0, img.Width, img.Width)
- , System.Drawing.GraphicsUnit.Pixel);
- }
- }
- }
- MemoryStream ms = new MemoryStream();
- thumbnail.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
- Response.ContentType = "image/png";
- Response.Cache.SetExpires(DateTime.Now.AddYears(1));
- Response.AddHeader("Content-Length", ms.Length.ToString());
- Response.BinaryWrite(ms.ToArray());
- Response.End();
- }
- }
- }
-
- protected void UploadAttachment1_FileUploaded(object sender, UploaderEventArgs args)
- {
- Session["guid"] = args.FileGuid;
- UploadAttachment1.GetItemsTable().Visible = false;
- image1.Visible = true;
- image1.ImageUrl = "Thumbnail.aspx?ShowThumbnail=" + args.FileGuid;
-
- }
- </script>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head id="Head1" runat="server">
- <title>Untitled Page</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <CuteWebUI:UploadAttachments runat="server" ID="UploadAttachment1" OnFileUploaded="UploadAttachment1_FileUploaded"
- MultipleFilesUpload="false" InsertText="Upload">
- </CuteWebUI:UploadAttachments>
- <br />
- preview<br />
- <asp:Image ID="image1" runat="server" Visible="false" />
- </div>
- </form>
- </body>
- </html>
* From server side dynamically JavaScript execution after success upload
The example below shows you how to execute the javascript function after success upload
- <%@ Page Language="C#" %>
-
- <%@ Register TagPrefix="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" Namespace="CuteWebUI" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
- <script runat="server">
- protected void Uploader1_UploadCompleted(object sender, UploaderEventArgs[] args)
- {
- ClientScript.RegisterClientScriptBlock(this.GetType(), "show", "<script>alert('some message');</"+"script>", false);
- }
- </script>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head id="Head1" runat="server">
- <title>example</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <CuteWebUI:Uploader runat="server" ID="Uploader1" OnUploadCompleted="Uploader1_UploadCompleted">
- </CuteWebUI:Uploader>
- </form>
- </body>
- </html>
* With possibility to change progress bar just text from server side
You can hide the progressbar by property "ShowProgressBar"
<CuteWebUI:Uploader runat="server" ID="Uploader1" ShowProgressBar="false">
</CuteWebUI:Uploader>
And refer to http://www.ajaxuploader.com/document/scr/create-custom-progress-template.htm to change the progress template text
Regards,
Ken