Get File Stream similar to HTTP Posted File.

Last post 01-08-2013, 1:29 PM by Kenneth. 1 replies.
Sort Posts: Previous Next
  •  01-08-2013, 10:57 AM 76591

    Get File Stream similar to HTTP Posted File.

    Hi all , 

     

    I am using CuteWebUI file uploader control . It's markup is

     

    <table>
        <tr>
            <td style="width: 50%">
               <CuteWebUI:UploadAttachments runat="server" MultipleFilesUpload="true" ManualStartUpload="true"  ID="Uploader1" InsertText="Browse Files (Max 1M)"  >
            </CuteWebUI:UploadAttachments>
            </td>


             <td style="width: 50%">
                  <asp:Button ID="btnUploadFiles" Text="Create Scripts ....." runat="server" />
            </td>   
        
        </tr>   
       </table>   

     

    My requirement is given below .

     

    1) User should be able  to select multiple files. 

    2) When btnUploadFiles is clicked , file streams of selected files should be read in code behind , similar to HTTPPostedFileCollection that we have for asp.net upload control. 

    3) Further business logic after reading each of the  file content .  

     

    Can you please guide me if it is possible?

     

    Thanks

    Siddhesh  


    Thanks
    Siddhesh
  •  01-08-2013, 1:29 PM 76595 in reply to 76591

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