asp.net dropdownlist appenddatabounditems

Original Post : http://weblogs.asp.net/scottgu/archive/2006/01/29/436804.aspx


Here is a simple example of where this comes in handy:


<asp:DropDownList ID=”DropDownList1″AppendDataBoundItems=”true” runat=”server”DataSourceID=”SqlDataSource1″DataTextField=”state”DataValueField=”state”>


    <asp:ListItem Text=”(Select a State)”Value=”” />   


</asp:DropDownList>


 


<asp:SqlDataSource ID=”SqlDataSource1″runat=”server”


                   ConnectionString=”<%$ ConnectionStrings:pubsConnectionString %>


                   SelectCommand=”SELECT DISTINCT [state] FROM [authors]”>


</asp:SqlDataSource>

EO.Web AJAXUploader File Upload Explained

Original Post : http://doc.essentialobjects.com/library/1/ajaxuploader/ajaxuploader_behavior.aspx


File Upload Explained



The following steps described how a file is being transferred to the server:



  1. Stage 1: File is transferred from client side to TempFileLocation;

    1. User browses a file on the client side;
    2. If the uploader’s AutoUpload is set to true, the upload would automatically starts;
    3. When AutoUpload is false (default value), the user must click the Upload to start uploading;
    4. The uploader transfers the file to TempFileLocation. A number of files are created for each file to be uploaded. All these files have long temporary file names that are not in anyway related to the original file name of the file being uploaded. You do not need to clean up these files;

  2. Stage 2: User submits the page;


    1. Even after the file has been completely transferred to TempFileLocation, they do not automatically become available to your code. In order for them to become available to your code, user must submit the page. Think the uploader control as a textbox and “uploading a file” as “type a letter in the textbox”. The textbox now have contents, but user must submit the page (usually by another button control) in order for server side code to access the textbox contents.


      The uploader control can also automatically submit the page as soon as the upload is done. To use this feature, set the uploader’s AutoPostBack to true;


    2. Once the page is submitted, the uploader’s FileUploaded event is fired. Inside this event you can use PostedFiles to get information about each posted files. Each posted file is represented by an AJAXPostedFile object. Most importantly, the object contains the file’s original name and the temporary file name. At this stage, you can copy the file to any destination you wish, usually also rename it to back to its originally file name:
      [C#]
      foreach (EO.Web.AJAXPostedFile file in AJAXUploader1.PostedFiles)
      {
      //Get the temp file name
      string tempFileName = file.TempFileName;

      //Create the final file name based on the original file name
      string finalFileName = System.IO.Path.Combine(“c:\upload\”, file.ClientFileName);

      //Move the file to the desired location
      System.IO.File.Move(tempFileName, finalFileName);
      }

      [Visual Basic.NET]
      Dim file As EO.Web.AJAXPostedFile
      For Each file In AJAXUploader1.PostedFiles
      ‘Get the temp file name

      Dim tempFileName As String = file.TempFileName;

      ‘Create the final file name based on the original file name

      Dim finalFileName As String = System.IO.Path.Combine(“c:\upload\”, file.ClientFileName)

      ‘Move the file to the desired location

      System.IO.File.Move(tempFileName, finalFileName)
      Next file


      The above code may not be necessary if FinalFileLocation is set.


  3. Stage 3: moving files from TempFileLocation to FinalFileLocation.

    You can optionally set the uploader’s FinalFileLocation property. When this property is set, the uploader automatically moves the files from TempFileLocation to FinalFileLocation when the page submits. In this case the above sample code that moves posted files is no longer necessary;


    Even though FinalFileLocation is convenient, it may not always the best option. For example, if you store files in your database, there is no need to set FinalFileLocation to introduce an extra copy of the file. Instead you should read directly from files inTempFileLocation, because all the information for you to create the database record is already available at that stage;


  4. Stage 4: Clean up

    The uploader automatically cleans up files in TempFileLocation after it detects the files have not been accessed after a certain period of time. You do not need to write any code to clean up.


    Sometimes you may notice the files are not deleted on your development machine after a long time. This usually occurs when:



    1. You included TempFileLocation in your project. Visual Studio scans files included in the project, which marks the files as being recently used. This prevents the uploader from deleting the files;
    2. The uploader does not delete the files immediately. So if the application has never run long enough to satisfy the time delay (which is often the case on a development machine), the files may not get deleted;
    3. You have changed TempFileLocation. When TempFileLocation is changed, the previous temporary file directory will no longer be monitored. Thus files in that directory will not be deleted;

    In any case the files should not be a concern in a properly configured production environment.