////Code For Multiple Albums USe NewPhotoManager
string[] m_Photos;
string[] m_Original_Photos;
Albums m_Albums = NewPhotoManager.GetAlbums();
int albumCount = 0;
foreach (Album alb in m_Albums)
{
albumCount++;
Label lbl = new Label();
lbl.Text = alb.Summary;
//MainDIV.Controls.Add(lbl);
System.Web.UI.HtmlControls.HtmlGenericControl h4Tag =
new System.Web.UI.HtmlControls.HtmlGenericControl("h4");
//h4Tag.Attributes.Add("style", "float:left;");
h4Tag.InnerText = lbl.Text;
MainDIV.Controls.Add(h4Tag);
System.Web.UI.HtmlControls.HtmlGenericControl ulTag =
new System.Web.UI.HtmlControls.HtmlGenericControl("ul");
ulTag.Attributes.Add("class", "portfolio-4col");
ulTag.Attributes.Add("id", "UnOList"+albumCount);
//ulTag.Attributes.Add("style", "float:left;");
m_Photos = NewPhotoManager.GetPhotos(alb.Title);
m_Original_Photos = NewPhotoManager.GetOriginalPhotos();
for (int i = 0; i < m_Photos.Length; i++)
{
System.Web.UI.HtmlControls.HtmlGenericControl liList =
new System.Web.UI.HtmlControls.HtmlGenericControl("li");
/////////////////////
System.Web.UI.HtmlControls.HtmlGenericControl dynDiv1 =
new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
dynDiv1.Attributes.Add("class", "portfolio-blockimg3");
System.Web.UI.HtmlControls.HtmlGenericControl dynDiv2 =
new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
dynDiv2.Attributes.Add("class", "portfolio-imgbox3");
System.Web.UI.HtmlControls.HtmlGenericControl dynDiv3 =
new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
dynDiv3.Attributes.Add("class", "zoom");
HyperLink hp = new HyperLink();
Image img = new Image();
img.ImageUrl = m_Photos[i];
img.Height = new Unit (86);
img.Width = new Unit(147);
//hp.Attributes.Add("style", "z-index:100000000;");
img.CssClass = "boximg-pad fade";
hp.Controls.Add(img);
hp.NavigateUrl = m_Original_Photos[i];
hp.Controls.Add(img);
hp.Attributes.Add("rel", "prettyPhoto[portfolio]");
dynDiv3.Controls.Add(hp);
dynDiv2.Controls.Add(dynDiv3);
dynDiv1.Controls.Add(dynDiv2);
liList.Controls.Add(dynDiv1);
ulTag.Controls.Add(liList);
}
MainDIV.Controls.Add(ulTag);
System.Web.UI.HtmlControls.HtmlGenericControl spacerDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
spacerDiv.Attributes.Add("class", "spacer");
MainDIV.Controls.Add(spacerDiv);
}
}
}
NewPhotoManager.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Web;
using Google.GData.Photos;
using System.Web.Security;
/// <summary>
/// Summary description for NewPhotoManager
/// </summary>
public class NewPhotoManager
{
private static Albums m_albums;
private static PicasaService m_picasaService;
private static String[] myImages;
private static String[] myThumnailsImages;
public static PicasaService PicasaService
{
get
{
if (m_picasaService == null)
m_picasaService = new PicasaService("PhotoBrowser");
return m_picasaService;
}
}
public static bool TryGetAlbum(string id, out Album album)
{
if (m_albums == null)
InitializeAlbums();
return m_albums.TryGetItem(id, out album);
}
public static Albums GetAlbums()
{
//if (m_albums == null)
InitializeAlbums();
return m_albums;
}
public static void Reset()
{
InitializeAlbums();
}
private static void InitializeAlbums()
{
m_albums = new Albums();
AlbumQuery albumQuery = new AlbumQuery();
albumQuery.Uri = new Uri(PicasaQuery.CreatePicasaUri(ConfigurationManager.AppSettings.Get("PicasaWebUserId")));
albumQuery.Access = PicasaQuery.AccessLevel.AccessPublic;
//Below Code Can be used if you want all the albums
PicasaFeed feed1 = PicasaService.Query(albumQuery);
if (feed1 != null && feed1.Entries.Count > 0)
{
foreach (PicasaEntry entry in feed1.Entries)
{
Album album = new Album();
album.Title = entry.Title.Text;
album.Summary = entry.Summary.Text.Replace("\r\n", "<br/>");
album.FeedUri = entry.FeedUri;
album.ThumbnailUrl = entry.Media.Thumbnails[0].Attributes["url"].ToString();
album.NumberOfPhotos = ((GPhotoNumPhotos)entry.ExtensionElements[5]).IntegerValue;
m_albums.Add(album);
}
}
}
//Return Thumbnail Images
public static String[] GetPhotos(String Album_Name)
{
/////////////////////////
PhotoQuery query = new PhotoQuery(PicasaQuery.CreatePicasaUri("YOUR PICASAUSERID", Album_Name));
query.Access = PicasaQuery.AccessLevel.AccessPublic;
PicasaFeed feed = PicasaService.Query(query);
myImages = new String[feed.Entries.Count];
myThumnailsImages = new String[feed.Entries.Count];
int i = 0;
foreach (PicasaEntry entry in feed.Entries)
{
//Console.WriteLine(entry.Title.Text);
//PhotoAccessor ac = new PhotoAccessor(entry);
String url = entry.Content.AbsoluteUri;
myImages[i] = url;
String thumbUrl = entry.Media.Thumbnails[0].Attributes["url"].ToString();
myThumnailsImages[i] = thumbUrl;
i++;
}
return myThumnailsImages;
}
//Return Original Images
public static String[] GetOriginalPhotos()
{
return myImages;
}
}
Albums.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Google.GData.Photos;
using System.Collections.ObjectModel;
public class Albums: KeyedCollection<string, Album>
{
protected override string GetKeyForItem(Album item)
{
return item.FeedUri;
}
public bool TryGetItem(string feedUri, out Album matchingAlbum)
{
matchingAlbum = null;
if (Dictionary != null && Dictionary.TryGetValue(feedUri, out matchingAlbum))
return true;
else
return false;
}
}
Album.CS
using System.Collections.Generic;