How to upload files in Button Click eventUpload Files

Last post 06-09-2009, 11:39 PM by amar.1401. 6 replies.
Sort Posts: Previous Next
  •  06-05-2009, 8:58 AM 52824

    How to upload files in Button Click eventUpload Files

    In the examples which you provided....when the user clicks on the "Upload Multiple Files"button a popup will be opened for browsing the files, from there user is selecting multiple files and clicking on open button then in the code behind in the Uploader1_FileUploaded event all the files are getting uploaded...........
    so my requirement is instead of uploading the selected files in the Uploader1_FileUploaded event, can we upload the same from the button click event......

    Please help me in this regard.......waiting 4 your reply...
    If this works fine then our company will buy the product.......Appreciate your speedy response.....
     
     
  •  06-05-2009, 11:43 AM 52830 in reply to 52824

    Re: How to upload files in Button Click eventUpload Files

    Hi,
     
    You can use the UploadAttachments control, and get the Items on the button_click event.
     
    Regards,
    Terry
  •  06-06-2009, 5:58 AM 52845 in reply to 52830

    Re: How to upload files in Button Click eventUpload Files

    HI Terry,

    Thank you for your quick reply

    Can you please provide me the sample code to do the same......

    Its very urgent for me.....

    Please do me the need full.......appreciate your speedy response

  •  06-09-2009, 4:10 AM 52886 in reply to 52845

    Re: How to upload files in Button Click eventUpload Files

    Hi,
     
    Please check this sample code :
     
    1. <%@ Page Language="C#" Title="First sample" %>  
    2.   
    3. <%@ Import Namespace="CuteWebUI" %>  
    4. <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>  
    5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">  
    6.   
    7. <script runat="server">  
    8.     protected void Button1_Click(object sender, EventArgs e)   
    9.     {   
    10.         System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();   
    11.         msg.From = "[email protected]";   
    12.         msg.To = "[email protected]";   
    13.         msg.Subject = tbTitle.Text;   
    14.         msg.Body = tbMessage.Text;   
    15.            
    16.         foreach (AttachmentItem item in UploadAttachments1.Items)   
    17.         {   
    18.             if (!item.Checked) continue;   
    19.   
    20.             //string filename = item.FileName;   
    21.             //int filesize=item.FileSize;   
    22.             //Stream stream=item.OpenStream();   
    23.   
    24.             System.Web.Mail.MailAttachment ma  
    25.                 = new System.Web.Mail.MailAttachment(item.GetTempFilePath());   
    26.             msg.Attachments.Add(ma);   
    27.         }   
    28.         //System.Web.Mail.SmtpMail.Send(msg);   
    29.   
    30.         //remove all items    
    31.         //UploadAttachments1.DeleteAllAttachments();   
    32.   
    33.            
    34.     }   
    35.   
    36. </script>  
    37.   
    38. <html xmlns="http://www.w3.org/1999/xhtml">  
    39. <head id="Head1" runat="server">  
    40. </head>  
    41. <body>  
    42.     <form id="Form1" runat="server">  
    43.         <table>  
    44.             <tr>  
    45.                 <td>  
    46.                 </td>  
    47.                 <td>  
    48.                     Send a mail:   
    49.                 </td>  
    50.             </tr>  
    51.             <tr>  
    52.                 <td>  
    53.                     Title :   
    54.                 </td>  
    55.                 <td>  
    56.                     <asp:TextBox runat="server" ID="tbTitle"></asp:TextBox>  
    57.                 </td>  
    58.             </tr>  
    59.             <tr>  
    60.                 <td>  
    61.                 </td>  
    62.                 <td>  
    63.                     <CuteWebUI:UploadAttachments runat="server" ID="UploadAttachments1" InsertText="Select attachments">  
    64.                         <ItemCellStyle CssClass="Cell" />  
    65.                         <TableStyle CssClass="Table" />  
    66.                     </CuteWebUI:UploadAttachments>  
    67.                 </td>  
    68.             </tr>  
    69.             <tr>  
    70.                 <td>  
    71.                     Message :   
    72.                 </td>  
    73.                 <td>  
    74.                     <asp:TextBox runat="server" ID="tbMessage" Rows="8" TextMode="MultiLine" Width="400px"></asp:TextBox>  
    75.                 </td>  
    76.             </tr>  
    77.             <tr>  
    78.                 <td>  
    79.                 </td>  
    80.                 <td>  
    81.                     <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send" Width="107px" />  
    82.                 </td>  
    83.             </tr>  
    84.         </table>  
    85.     </form>  
    86. </body>  
    87. </html>  
     
    Regards,
    Terry
  •  06-09-2009, 9:52 AM 52888 in reply to 52886

    Re: How to upload files in Button Click eventUpload Files

    HI,
     
    Thank you very much for your post......its working fine
     
    Can I have code for uploading the files manually.....I have seen the demo in the site for  Start uploading manually.....But I did't find the sample code in the downloaded samples.
     
    Can you please let me know from where I can get the code for that......or else Please provide me the code for the same.
     
    Appreciate your speedy response
     
    Thank you,
     
    Amarnath
  •  06-09-2009, 10:58 AM 52892 in reply to 52888

    Re: How to upload files in Button Click eventUpload Files

    amar.1401:
    HI,
     
    Thank you very much for your post......its working fine
     
    Can I have code for uploading the files manually.....I have seen the demo in the site for  Start uploading manually.....But I did't find the sample code in the downloaded samples.
     
    Can you please let me know from where I can get the code for that......or else Please provide me the code for the same.
     
    Appreciate your speedy response
     
    Thank you,
     
    Amarnath
     
     
     
    Framework 1.x-Csharp\Demo\Start-uploading-manually.aspx
    Framework 1.x-VB\Demo\Start-uploading-manually.aspx
    Framework 2.0-Csharp\Demo\Start-uploading-manually.aspx
    Framework 2.0-VB\Demo\Start-uploading-manually.aspx

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  06-09-2009, 11:39 PM 52931 in reply to 52892

    Re: How to upload files in Button Click eventUpload Files

    Thank you very much.......
View as RSS news feed in XML