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) { } string SearchAmazon(string strKeywords, string strSearchIndex) { // Create a new instance of the proxy class AWSECommerceService myProxy = new AWSECommerceService(); // Create a new instance of the ItemSearch class ItemSearch mySearch = new ItemSearch(); // ItemSearchRequest stores the actual request parameters ItemSearchRequest mySearchRequest = new ItemSearchRequest(); // Set some parameters, Keyword and Search Index mySearchRequest.Keywords = strKeywords; mySearchRequest.SearchIndex = strSearchIndex; // Just need Small results, not the full enchilada mySearchRequest.ResponseGroup = new string[] { "Medium", "Request"}; // Set the subscription and associate tags here mySearch.AWSAccessKeyId = ConfigurationManager.AppSettings["AWSAccessKeyId"]; mySearch.AssociateTag = ConfigurationManager.AppSettings["AssociateTag"]; // Setup request mySearch.Request = new ItemSearchRequest[] { mySearchRequest }; // Execute the request and get the response ItemSearchResponse myResponse = myProxy.ItemSearch(mySearch); // Parse the response and return the results in HTML string strHTML = ""; foreach (Items myItems in myResponse.Items) { foreach (Item myItem in myItems.Item) { // Get the results in HTML strHTML += FormatAsHTML(myItem); } } return strHTML; } /// /// Returns HTML for a specific Amazon Item /// /// The Item instance /// a string of HTML string FormatAsHTML(Item myItem) { // Will contain the results string strHTML =""; // Check for null if (myItem != null) { // Begin the item HTML strHTML += "
"; // Add the title strHTML += "

" + myItem.ItemAttributes.Title + "

"; // Add the item image if present if (myItem.SmallImage != null) { strHTML += ""; } // Add the ASIN strHTML += "ASIN: " + myItem.ASIN + "
"; // Add the price if present if (myItem.OfferSummary != null) { if (myItem.OfferSummary.LowestNewPrice != null) { strHTML += "Lowest Price: " + myItem.OfferSummary.LowestNewPrice.FormattedPrice + "
"; } } // Add a link to the details strHTML += "View Details
"; // Close the output strHTML += "
"; } return strHTML; } protected void cmdSubmit_ServerClick(object sender, EventArgs e) { string strKeywords = Request.Params["keywords"]; string strSearchIndex = Request.Params["searchIndex"]; myResults.Text = SearchAmazon(strKeywords, strSearchIndex); } }