Ajax Uploader

Last post 10-14-2008, 1:37 AM by cutechat. 4 replies.
Sort Posts: Previous Next
  •  10-13-2008, 10:32 AM 44836

    Ajax Uploader

    I am trying out Ajax Uploader. After I place the dll in my Bin directory and update my  web.config then what? I cant find the Ajax Uploader control to put it .aspx  web page. It's not in the Toolbox where I was hoping to find it. A simple example in C# would help including how to register tag prefix CuteWebUI.  Please advise, thanks.
    Filed under:
  •  10-13-2008, 12:36 PM 44838 in reply to 44836

    Re: Ajax Uploader

    Hi,
     
    you can try this code :
     
     
    <%@ Page Language="C#" Title="First sample" %>
    <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    </head>
    <body>
     <form runat="server">
      <CuteWebUI:Uploader runat="server" ID="Uploader1" InsertText="Uploader1">
      </CuteWebUI:Uploader>
      <br />
      <CuteWebUI:UploadPersistedFile runat="server" ID="UploadPersistedFile1" InsertText="UploadPersistedFile1">
      </CuteWebUI:UploadPersistedFile>
      <br />
      <CuteWebUI:UploadAttachments runat="server" ID="UploadAttachments1" InsertText="UploadAttachments1">
      </CuteWebUI:UploadAttachments>
     </form>
    </body>
    </html>
     
     
  •  10-13-2008, 1:18 PM 44839 in reply to 44838

    Re: Ajax Uploader

    Thanks, that helped!
    Filed under:
  •  10-13-2008, 2:30 PM 44843 in reply to 44839

    Re: Ajax Uploader

    Next I would like to attach the file to an email. With  FileUpload control I would do it as posted below. Is there an example that  would work with UploadAttachments1 ? It should be even simpler than the code below.
     

    if (this.IsPostBack)

    {


    MailMessage
    email = new MailMessage();

    email.From = new MailAddress("Fake@Email.com");

    email.To.Add(new MailAddress("FakeRecipient@Email.com"));

    email.Subject = "Test";

    email.Body = "Test";

     

    if (FileUpload1.PostedFile != null &&

    FileUpload1.PostedFile.ContentLength > 0)

    {

    // attachFile.PostedFile.FileName contains

    // the full path of the file. We only want the file

    // so we delimit it by forward slashes into an array

    string[] tempFileName =

    FileUpload1.PostedFile.FileName.Split('\\');

    // attachFile.PostedFile exposes a System.IO.Stream

    // property named InputStream

    Attachment emailAttach = new Attachment(FileUpload1.PostedFile.InputStream,tempFileNametempFileName.Length - 1]);

     

    email.Attachments.Add(emailAttach);

    }

     

    Filed under:
  •  10-14-2008, 1:37 AM 44854 in reply to 44839

    Re: Ajax Uploader

    Please try based on this code :
     
     

    <%@ Page Language="C#" Title="First sample" %>
    <%@ Import Namespace="CuteWebUI" %>
    <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
    <script runat="server">
     protected void Button1_Click(object sender, EventArgs e)
     {
      System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
      msg.From = "mymail@myhost.com";
      msg.To = "yourmail@yourmail.com";
      msg.Subject = "Test";
      msg.Body = "Test";
      foreach (AttachmentItem item in UploadAttachments1.Items)
      {
       if (!item.Checked) continue;

       //string filename = item.FileName;
       //int filesize=item.FileSize;
       //Stream stream=item.OpenStream();
       
       System.Web.Mail.MailAttachment ma
        = new System.Web.Mail.MailAttachment(item.GetTempFilePath());

       msg.Attachments.Add(ma);
      }
      System.Web.Mail.SmtpMail.Send(msg);
     }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
    </head>
    <body>
     <form id="Form1" runat="server">
      <CuteWebUI:UploadAttachments runat="server" ID="UploadAttachments1" InsertText="UploadAttachments1">
      </CuteWebUI:UploadAttachments>
      <br />
      <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send" Width="107px" />
     </form>
    </body>
    </html>

     
View as RSS news feed in XML