Re: Ajax Uploader missed new 3 features...

  •  04-06-2012, 7:59 AM

    Re: Ajax Uploader missed new 3 features...

    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. 
    1. <%@ Page Language="C#" %>  
    2.   
    3. <%@ Import Namespace="CuteWebUI" %>  
    4. <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>  
    5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    6.   
    7. <script runat="server">  
    8.   
    9.     protected override void OnInit(EventArgs e)  
    10.     {  
    11.         base.OnInit(e);  
    12.         //below code for preview   
    13.         string st = Request.QueryString["ShowThumbnail"];  
    14.         if (st != null)  
    15.         {  
    16.             MvcUploader uploader = new MvcUploader(Context);  
    17.             Guid guid = new Guid(st);  
    18.             MvcUploadFile file = uploader.GetUploadedFile(guid);  
    19.             if (file == null)  
    20.             {  
    21.                 Response.StatusCode = 404;  
    22.                 Response.Write("Invalid File : " + guid);  
    23.                 Response.End();  
    24.             }  
    25.             //handel the preview photo size here, default 64 64  
    26.             using (System.Drawing.Image thumbnail = new System.Drawing.Bitmap(64, 64, System.Drawing.Imaging.PixelFormat.Format32bppArgb))  
    27.             {  
    28.                 using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(thumbnail))  
    29.                 {  
    30.                     using (Stream stream = file.OpenStream())  
    31.                     {  
    32.                         using (System.Drawing.Image img = System.Drawing.Image.FromStream(stream))  
    33.                         {  
    34.                             g.DrawImage(img  
    35.                                 , new System.Drawing.Rectangle(0, 0, thumbnail.Width, thumbnail.Width)  
    36.                                 , new System.Drawing.Rectangle(0, 0, img.Width, img.Width)  
    37.                                 , System.Drawing.GraphicsUnit.Pixel);  
    38.                         }  
    39.                     }  
    40.                 }  
    41.                 MemoryStream ms = new MemoryStream();  
    42.                 thumbnail.Save(ms, System.Drawing.Imaging.ImageFormat.Png);  
    43.                 Response.ContentType = "image/png";  
    44.                 Response.Cache.SetExpires(DateTime.Now.AddYears(1));  
    45.                 Response.AddHeader("Content-Length", ms.Length.ToString());  
    46.                 Response.BinaryWrite(ms.ToArray());  
    47.                 Response.End();  
    48.             }  
    49.         }  
    50.     }  
    51.   
    52.     protected void UploadAttachment1_FileUploaded(object sender, UploaderEventArgs args)  
    53.     {  
    54.         Session["guid"] = args.FileGuid;  
    55.         UploadAttachment1.GetItemsTable().Visible = false;  
    56.         image1.Visible = true;  
    57.         image1.ImageUrl = "Thumbnail.aspx?ShowThumbnail=" + args.FileGuid;  
    58.   
    59.     }  
    60. </script>  
    61.   
    62. <html xmlns="http://www.w3.org/1999/xhtml">  
    63. <head id="Head1" runat="server">  
    64.     <title>Untitled Page</title>  
    65. </head>  
    66. <body>  
    67.     <form id="form1" runat="server">  
    68.         <div>  
    69.             <CuteWebUI:UploadAttachments runat="server" ID="UploadAttachment1" OnFileUploaded="UploadAttachment1_FileUploaded"  
    70.                 MultipleFilesUpload="false" InsertText="Upload">  
    71.             </CuteWebUI:UploadAttachments>  
    72.             <br />  
    73.             preview<br />  
    74.             <asp:Image ID="image1" runat="server" Visible="false" />  
    75.         </div>  
    76.     </form>  
    77. </body>  
    78. </html>  
     From server side dynamically JavaScript execution after success upload
     
    The example below shows you how to execute the javascript function after success upload
    1. <%@ Page Language="C#" %>  
    2.   
    3. <%@ Register TagPrefix="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" Namespace="CuteWebUI" %>  
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    5.   
    6. <script runat="server">  
    7.     protected void Uploader1_UploadCompleted(object sender, UploaderEventArgs[] args)  
    8.     {  
    9.         ClientScript.RegisterClientScriptBlock(this.GetType(), "show""<script>alert('some message');</"+"script>"false);  
    10.     }  
    11. </script>  
    12.   
    13. <html xmlns="http://www.w3.org/1999/xhtml">  
    14. <head id="Head1" runat="server">  
    15.     <title>example</title>  
    16. </head>  
    17. <body>  
    18.     <form id="form1" runat="server">  
    19.         <CuteWebUI:Uploader runat="server" ID="Uploader1" OnUploadCompleted="Uploader1_UploadCompleted">  
    20.         </CuteWebUI:Uploader>  
    21.     </form>  
    22. </body>  
    23. </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 
View Complete Thread