topical media & game development

talk show tell print

mashup-amazon-07-07-02-AmazonRSS-default.aspx.cs / cs



  using System;
  using System.Data;
  using System.Configuration;
  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;
  using com.amazon.webservices;
  using System.Xml.Serialization;
  using System.IO;
  
  public partial class _default : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          // If this page was passed any keywords, then GetResults
          if (Request.Params["keywords"] != null)
          {
              GetResults();
          }
      } 
      
      void GetResults()
      {
          string strKeywords = Request.Params["keywords"];
          string strSearchIndex = Request.Params["searchIndex"];
  
          // Check for null and set the default (music)
          if (strSearchIndex == null) strSearchIndex = "Music";
          ItemSearchResponse myResponse = AmazonUtility.SearchAmazon(strKeywords, strSearchIndex);
  
          // If the request is for RSS data, then obtain the RSS
          if (Request.Params["type"] == "rss")
          { 
              // Since this is RSS, need to clear the existing Response stream
              Response.Clear();
              // Set the response type to XML
              Response.ContentType = "text/xml";
  
              // Obtain the RSS
              string strRSS = AmazonUtility.GetResultsFromResponse(myResponse, true);
              // Write out the RSS
              Response.Write(strRSS);
  
              // End the response so the ASPX form does not get output
              Response.End();            
          }
          else
          {
              // Otherwise just output the HTML results. 
              myResults.Text = AmazonUtility.GetResultsFromResponse(myResponse, false);
          }
      }
  
      protected void cmdSubmit_ServerClick(object sender, EventArgs e)
      {
          // Process the button-click 
          GetResults();
      }
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.