- Purpose
- Getting Started
- In Session
- Creating Listings
- Finding Listings
- Photo Browser
- Conclusion
Photo Browser
Given some of the wacky auctions on eBay, sometimes it's fun just to browse the photos that have been posted. With the eBay API, it's not difficult to create an application that does just that, letting the user enter a search term or seller ID and look at the pictures of those items that are returned. The preceding two code snippets called processItem() on each Item that they found. Let's flesh out that method here:
private void processItem(IItem item) { String url = ""; if(item.PhotoCount > 0) { url = item.PhotoUrl; } else { url = item.GalleryUrl; } if(url.Length != 0) { items.Add(item); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse( ); System.Drawing.Image image = System.Drawing.Image.FromStream(response.GetResponseStream()); Images.Add(image); } }
Here we're looking over all those Items, and, for any that have an image URL of some sort associated, we retrieve the picture. To display the pictures, we'll create a 4x4 grid of PictureBoxes, and with a little simple logic, we can fill the grid with the global ArrayList called Images that we populated earlier. We can even scroll through them (see Figure 1).
Figure 1 A simple eBay image browser.
To open the images, assign an index to each of the PictureBoxes, and assign their Click method to call this method with that index (see Figure 2):
private void displayItem(int item) { int index = item + imageOffset; InternetExplorer ie = new InternetExplorerClass(); String url = "http://cgi.sandbox.ebay.com/ws/eBayISAPI.dll?ViewItem&item=" + ((Item)items.ToArray()[index]).ItemId; if(ie == null) { Console.WriteLine("Error: could not create IE instance"); } else { object empty = String.Empty; ie.Visible = true; ie.Navigate(url, ref empty, ref empty, ref empty, ref empty); } }
Figure 2 Viewing an auction through the image browser.