Skip to main content

Posts

Showing posts from August, 2010

Class to get Live Photo and Album Information in .NET

Thanks to the Windows Live Spaces Photo Album plugin project at CodePlex, I was able to abstract the code to get Album and Pictures information from a Live Spaces account. This class serves as a helper when generating javascript code for slideshows containing photos stored at Live Spaces. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using HtmlAgilityPack; using System.Web; namespace LivePhotoDataProvider { public class AlbumInfo { public string URL { get; set; } public string Name { get; set; } } public class PhotoInfo { public string FullSizeURL { get; set; } } public class LivePhotoData { public List<AlbumInfo> GetAlbums(string live_spaces_link) { List<AlbumInfo> albums = new List<AlbumInfo>(); XmlDocument doc = new XmlDocument(); try { doc.Load(live_spaces_link);

Using SQL Server’s XML features as a fast ORM

When you need load POCO objects from a SQL Server database in a faster way than LinqToSQL, you may consider using  SQL Server’s XML features.  The FOR XML PATH command can be a really powerful tool to convert your relational data into XML that C# can de-serialize into C# plain objects. The key is to find how C# serializes objects to XML. In order to do that, I did a small test: public class Store { public string Name { get; set; } public int Sales { get; set; } public List<StoreContact> StoreContact { get; set; } } public class StoreContact { public int ContactId { get; set; } public int ContactTypeID { get; set; } } public static void TestSaveToXML(string path) { XmlSerializer serializer = new XmlSerializer(typeof(List<Store>)); TextWriter writer = new StreamWriter(path); List<Store> stores = new List<Store&g