Problem In Implementing Uploader in Code Behind Page in asp.net

Last post 10-05-2009, 12:42 AM by cutechat. 7 replies.
Sort Posts: Previous Next
  •  01-02-2009, 12:13 PM 47353

    Problem In Implementing Uploader in Code Behind Page in asp.net

    Hi,
     
    i have downloaded ajax uploader and tested the given code. it worked properly.
     
    so i tried to implement the same in my code.
     
    but the problem is that the given code is in one page format ie no code behind pages
     
    whereas i have to implement the uploader in code behind page (aspx.cs).
     
    also i am using master pages, so it gets difficult to implement the code.
     
    so can you provide me with example on how to implement the uploader in the code behind pages in asp.net.
     
    i want to implement the simple-upload-Validation example in my project where all the uploading code should be in the code behind page (aspx.cs page)
     
     
     
    Thanks.
     
     
  •  01-04-2009, 11:46 PM 47386 in reply to 47353

    Re: Problem In Implementing Uploader in Code Behind Page in asp.net

    Hi ssjal,
     
    Here is the example code:
     
    simple-upload-Validation.aspx
     
     
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="simple-upload-Validation.aspx.cs"
        Inherits="simple_upload_Validation" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Simple Upload with Progress</title>
        <link rel="stylesheet" href="demo.css" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <div class="content">
                    <asp:ScriptManager ID="Scriptmanager1" runat="server">
                    </asp:ScriptManager>
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <h2>
                                Simple Upload with Progress (Custom Validation)
                            </h2>
                            <p>
                                A sample demonstrating how to create user-defined validation functions for an upload
                                control. In this example, we defined two validation rules:</p>
                            <ul>
                                <li>Maximum file size: 100K</li><li>Allowed file types: jpeg, jpg, gif,png </li>
                            </ul>
                            <p>
                                Click the following button to upload.
                            </p>
                            <CuteWebUI:Uploader runat="server" ID="Uploader1" InsertText="Upload">
                                <ValidateOption AllowedFileExtensions="jpeg,jpg,gif,png" MaxSizeKB="100" />
                            </CuteWebUI:Uploader>
                            <br />
                            <br />
                            <div>
                                Server Trace:
                                <br />
                                <asp:ListBox runat="server" ID="ListBoxEvents" Width="400"></asp:ListBox>
                            </div>
                            <br />
                            <br />
                            <asp:Button ID="ButtonPostBack" Text="This is a PostBack button" runat="server" />
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </div>
            </div>
        </form>
    </body>
    </html>
    code behind
     
    simple-upload-Validation.aspx.cs
     

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class simple_upload_Validation : System.Web.UI.Page
    {
        void InsertMsg(string msg)
        {
            ListBoxEvents.Items.Insert(0, msg);
            ListBoxEvents.SelectedIndex = 0;
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            SampleUtil.SetPageCache();
            Uploader1.FileUploaded += new CuteWebUI.UploaderEventHandler(Uploader_FileUploaded);
            ButtonPostBack.Click += new EventHandler(ButtonPostBack_Click);

        }

        void ButtonPostBack_Click(object sender, EventArgs e)
        {
            InsertMsg("You clicked a PostBack Button.");
        }

        void Uploader_FileUploaded(object sender, CuteWebUI.UploaderEventArgs args)
        {
            CuteWebUI.Uploader uploader = (CuteWebUI.Uploader)sender;
            InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");
        }

    }


     
     
    Regards,
     
    Ken
  •  01-05-2009, 8:34 AM 47405 in reply to 47386

    Re: Problem In Implementing Uploader in Code Behind Page in asp.net

    Hey Kennith,
    Thanks for your reply my friend, i really appreciate your help.
     
    Regards,
    ssjal
  •  01-05-2009, 8:16 PM 47432 in reply to 47405

    Re: Problem In Implementing Uploader in Code Behind Page in asp.net

     
    You can just create a new uploader and put it into some container , at every page's init/load event:
     
     Uploader _uploader;
     protected override void OnLoad(EventArgs e)
     {
      _uploader = new Uploader();
      _uploader.ID = "MyUploader";
      _uploader.InsertText = "Select photos";
      _uploader.ValidateOption.AllowedFileExtensions = "jpg,png,gif";
      _uploader.FileUploaded += new UploaderEventHandler(_uploader_FileUploaded);
      MyPanel.Controls.Add(_uploader);
      base.OnLoad(e);
     }
     void _uploader_FileUploaded(object sender, UploaderEventArgs args)
     {
      
     }
     
     
    Regards,
    Terry
     
  •  04-17-2009, 12:25 PM 51213 in reply to 47432

    Re: Problem In Implementing Uploader in Code Behind Page in asp.net

    But ...which namespace i ill using?
     
    Because when i go Build the solution i get the error:
     
    The type or namespace name 'Uploader' could not be found (are you missing a using directive or an assembly reference?)
     
    I´m work in 1.1 framework
  •  04-17-2009, 1:53 PM 51221 in reply to 51213

    Re: Problem In Implementing Uploader in Code Behind Page in asp.net

    Hi,
     
    Please use CuteWebUI
     
    Regards,
    Terry
  •  10-01-2009, 2:55 PM 56024 in reply to 51221

    Re: Problem In Implementing Uploader in Code Behind Page in asp.net

    I am having trouble with this code. I want to do the same thing in triggering the upload of a queued file from the code behind but I do not use the default queue I am using a custom queue for some reason my uaUserPicture.Items.Count == 0 even though there is 1 file queued up.

    my code is:

    <CuteWebUI:UploadAttachments runat="server" ID="uaUserPicture" ManualStartUpload="true" MultipleFilesUpload="false"
           InsertButtonID="lbChangePicture" ShowProgressBar="false" ShowProgressInfo="false" ShowRemoveButtons="false"   />

    and in the code behind:

    if (SaveUserData() && Page.IsValid)
    {
            //some code 
    if (uaUserPicture.Items.Count == 1)
             {
                    UploadUserPicture();
             }
    }

  •  10-05-2009, 12:42 AM 56087 in reply to 56024

    Re: Problem In Implementing Uploader in Code Behind Page in asp.net

    Hi,
     
    Do you use ManualStartUpload ?
     
    If you submit the form while the queue-items is not marked as green icon , the files are not uploaded yet.
     
    Regards,
    Terry
View as RSS news feed in XML