Site Map | About Us | Contact Us  
 The same content in Microsoft HTML help file format is included in the download package.

Advanced Features

Overview

EO.Web Downloader supports dynamic contents generation. For example, you may require user to enter a few criteria in order to dynamically generates an excel report for the user to download; or require user to fill in a form in order to generates a .pdf file with the user filled in information for user to download.

Please follow these steps to dynamically generate download contents:

  1. Set the Downloader's DynamicContent to true;
  2. Create a new class that derives from DynamicDownloadContent class, override GenerateContent method. For example:
  3. [C#]
    private class ContentGenerator: EO.Web.DynamicDownloadContent
    {
        protected override void GenerateContent()
        {
            //your code to generates the download contents
            ......
        }
    }
    
    [Visual Basic.NET]
    Private Class ContentGenerator
        Inherits EO.Web.DynamicDownloadContent
             
        Protected Overrides Sub GenerateContent()
        
            'your code to generates the download contents
            ......
        End Sub    
    End Class    
    
  4. Handle the Downloader's Download event, inside the event handler, call DynamicDownload method on the event argument, passing in the type of class defined in step 2 as the first argument and any additional arguments you may have (for your content generating logic) as the second parameter. For example,
    private void Downloader1_Download(object sender, EO.Web.DownloadEventArgs e)
    {
        //Pass whatever argument to your content generator
        NameValueCollection args = new NameValueCollection();
        args["Text"] = TextBox1.Text;
    
        //Start a dynamic download. The first parameter is the
        //type of the content generator class. The second parameter
        //is whatever additional parameters you wish to pass to
        //your content generator
        e.DynamicDownload(typeof(ContentGenerator), args);
    }
    
    Private Sub Downloader1_Download(sender As Object, _
        e As EO.Web.DownloadEventArgs) Handles Downloader1.Download
        
        'Pass whatever argument to your content generator
        Dim args As New NameValueCollection()
        args("Text") = TextBox1.Text
             
        'Start a dynamic download. The first parameter is the
        'type of the content generator class. The second parameter
        'is whatever additional parameters you wish to pass to
        'your content generator
        e.DynamicDownload(GetType(ContentGenerator), args)    
    End Sub
    
  5. Inside your GenerateContent method, checks for the additional argument passed and calls SetFileName to set the download file name, then call Write method to dynamically generates the download content. For example,
    protected override void GenerateContent()
    {
        //Set the download file name
        SetFileName("test.txt", -1);
        
        //Get the argument we passed in
        string s = Arguments["Text"];
        
        //Generates download contents based on the file
        //For demonstration purpose, this code only writes
        //whatever we passed in. However a real life
        //scenario is most likely to be much complicated.
        //For example, you may need to run a query based
        //on the argument passed in and then generates the
        //download content based on the query result
        byte[] buffer = Encoding.ASCII.GetBytes(s);
    
        Write(buffer, 0, buffer.Length);
    }
    
    Protected Overrides Sub GenerateContent()
    
        'Set the download file name
        SetFileName("test.txt", -1)
        
        'Get the argument we passed in
        Dim s as String = Me.Arguments("Text")
        
        'Generates download contents based on the file
        'For demonstration purpose, this code only writes
        'whatever we passed in. However a real life
        'scenario is most likely to be much complicated.
        'For example, you may need to run a query based
        'on the argument passed in and then generates the
        'download content based on the query result
        Dim buffer As Byte() = Encoding.ASCII.GetBytes(s)
        Write(buffer, 0, buffer.Length)
    End Sub
    

Direct link to this topic