Ajax Uploader missed new 3 features...

Last post 04-06-2012, 7:59 AM by Kenneth. 1 replies.
Sort Posts: Previous Next
  •  04-06-2012, 1:08 AM 73640

    Ajax Uploader missed new 3 features...

    Hi,

    We tried your demo Ajax Uploader for ASP.NET, but we not found 3 new features:

    * Small image preview before start upload or after upload completed

    * From server side dynamically JavaScript execution after success upload (like does Microsoft Ajax, from code behind can run any JavaScript), that is really need feature, e.g. we uploading file with XLS extension but we doing import to database and then validation for file, if something wasn't ok then  we open other JavaScript dialog or redirect to other page and so on..

    * With possibility to  change progress bar just text from server side, e.g. we chose large file then click upload button then starts to display  progress bar with percentage, but after uploaded file we started validate file (and from there we need to display for client different progress - just print text where displayed before progress bar, e.g. "Validating file, please wait..."), then after success validation we start import data to database (now display on client browser in the same place where was before progress text, e.g. "Importing data, please wait..."), and while it not finished all processes.


    Is all this features possible to build in?

    Thanks


  •  04-06-2012, 7:59 AM 73645 in reply to 73640

    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 as RSS news feed in XML