public static ZunePlaylist FromFileFactory(String filePath) { if (String.IsNullOrEmpty(filePath) || !File.Exists(filePath)) { throw new ArgumentException(); } ZunePlaylist p = new ZunePlaylist(); p.Tracks = new List<ZuneTrack>(); try { XDocument playlistXml = XDocument.Load(filePath); XElement mainDocument = playlistXml.Element("smil"); XElement head = mainDocument.Element("head"); p.Name = (string)head.Element("title"); XElement body = mainDocument.Element("body"); XElement trackList = body.Element("seq"); foreach (XElement trackElement in trackList.Elements()) { p.Tracks.Add(ZuneTrack.FromXElementFactory(trackElement)); } } catch (XmlException) { p.Name = Path.GetFileNameWithoutExtension(filePath); } return p; }
public static void ToTextFile(ZunePlaylist playlist, String filePath, String format) { using (FileStream s = File.Create(filePath)) using (StreamWriter writer = new StreamWriter(s)) { writer.Write(playlist.ToListingWithFormat(format)); } }