Re: Get File Stream similar to HTTP Posted File.

  •  01-08-2013, 1:29 PM

    Re: Get File Stream similar to HTTP Posted File.

    Hi,

     

    Please try the example below.

     

    1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="UploaderExample.aspx.cs" Inherits="UploaderExample" %>  
    2.   
    3. <%@ Register Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" TagPrefix="CuteWebUI" %>  
    4. <!DOCTYPE html>  
    5.   
    6. <html xmlns="http://www.w3.org/1999/xhtml">  
    7. <head runat="server">  
    8.     <title>example</title>  
    9. </head>  
    10. <body>  
    11.     <form id="form1" runat="server">  
    12.         <div>  
    13.             <CuteWebUI:UploadAttachments runat="server" ManualStartUpload="true" ID="Uploader1"  
    14.                 InsertText="Browse Files (Max 1M)" OnFileUploaded="Uploader1_FileUploaded">  
    15.             </CuteWebUI:UploadAttachments>  
    16.   
    17.         </div>  
    18.         <p>  
    19.             <asp:Button runat="server" ID="SubmitButton" Text="Submit" OnClientClick="return submitbutton_click()" />  
    20.         </p>  
    21.     </form>  
    22. </body>  
    23. </html>  
    24. <script type="text/javascript">  
    25.   
    26.     function submitbutton_click() {  
    27.         var submitbutton = document.getElementById('<%=SubmitButton.ClientID %>');  
    28.         var uploadobj = document.getElementById('<%=Uploader1.ClientID %>');  
    29.         if (!window.filesuploaded) {  
    30.             if (uploadobj.getqueuecount() > 0) {  
    31.   
    32.                 uploadobj.startupload();  
    33.             }  
    34.             else {  
    35.                 var uploadedcount = parseInt(submitbutton.getAttribute("itemcount")) || 0;  
    36.                 if (uploadedcount > 0) {  
    37.                     return true;  
    38.                 }  
    39.                 alert("Please browse files for uploading");  
    40.             }  
    41.             return false;  
    42.         }  
    43.         window.filesuploaded = false;  
    44.         return true;  
    45.     }  
    46.     function CuteWebUI_AjaxUploader_OnPostback() {  
    47.         window.filesuploaded = true;  
    48.         var submitbutton = document.getElementById('<%=SubmitButton.ClientID %>');  
    49.           submitbutton.click();  
    50.           return false;  
    51.       }  
    52. </script>  
     .cs file

     

    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Web;  
    4. using System.Web.UI;  
    5. using System.Web.UI.WebControls;  
    6.   
    7. public partial class UploaderExample : System.Web.UI.Page  
    8. {  
    9.     protected void Uploader1_FileUploaded(object sender, CuteWebUI.UploaderEventArgs args)  
    10.     {  
    11.         byte[] data = new byte[args.FileSize];  
    12.         //read the upload file stream  
    13.         using (System.IO.Stream stream = args.OpenStream())  
    14.         {  
    15.             //achieve your own logic here  
    16.         }  
    17.     }  
    18. }  
     

    Regards,

     

    Ken 

View Complete Thread