Re: Upload photos should not upload any file with 0 bytes or show a proper warning message

  •  04-23-2009, 9:16 AM

    Re: Upload photos should not upload any file with 0 bytes or show a proper warning message

    Hi,
     
    Here is an example for you :
     
     
    1. <%@ Page Language="C#" Title="First sample" %>  
    2. <%@ Import Namespace="CuteWebUI" %>  
    3. <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>  
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">  
    5.   
    6. <script runat="server">  
    7.   
    8.     void InsertMsg(string msg)   
    9.     {   
    10.         ListBoxEvents.Items.Insert(0, msg);   
    11.         ListBoxEvents.SelectedIndex = 0;   
    12.     }   
    13.     protected void UploadAttachments1_AttachmentAdded(object sender, AttachmentItemEventArgs args)   
    14.     {   
    15.         InsertMsg("Added.." + args.Item.FileName);   
    16.     }   
    17.   
    18.     protected void UploadAttachments1_FileValidating(object sender, UploaderEventArgs args)   
    19.     {   
    20.         if (args.FileSize == 0)   
    21.         {   
    22.             throw (new Exception("Please do not upload empty file !"));   
    23.         }   
    24.     }   
    25. </script>  
    26.   
    27. <html xmlns="http://www.w3.org/1999/xhtml">  
    28. <head id="Head1" runat="server">  
    29. </head>  
    30. <body>  
    31.     <form id="Form1" runat="server">  
    32.         <CuteWebUI:UploadAttachments runat="server" ID="UploadAttachments1"    
    33.             OnAttachmentAdded="UploadAttachments1_AttachmentAdded"    
    34.             OnFileValidating="UploadAttachments1_FileValidating">  
    35.         </CuteWebUI:UploadAttachments>  
    36.         <br />  
    37.         <div>  
    38.             Server Trace:   
    39.             <br />  
    40.             <asp:ListBox runat="server" ID="ListBoxEvents" Width="800"></asp:ListBox>  
    41.         </div>  
    42.     </form>  
    43. </body>  
    44. </html>  
    Regards,
    Terry
View Complete Thread