Not the first time I've done this (at least LINQ makes it a bit more interesting);
static void Main(string[] args)
{
using (NorthwindDataContext ctx = new NorthwindDataContext())
{
List<Employee> employees = ctx.Employees.ToList();
XElement photos =
new XElement("photos",
from e in employees
select new XElement("employee",
new XAttribute("id", e.EmployeeID),
new XAttribute("photo", MakeFileName(e.EmployeeID))));
photos.Save("photos.xml");
foreach (Employee e in employees)
{
// bit wasteful...
byte[] bytes = new byte[e.Photo.Length - 78];
Array.Copy(e.Photo, 78, bytes, 0, e.Photo.Length - 78);
File.WriteAllBytes(MakeFileName(e.EmployeeID), bytes);
}
}
}
static string MakeFileName(int id)
{
return (string.Format(".\\images\\{0}.bmp", id));
}
Posted
Mon, Sep 10 2007 3:59 AM
by
mtaulty