Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml.Linq;
- namespace lab10_2
- {
- class Program
- {
- private const string folderLocation = @"D:\1307B";
- static void Main(string[] args)
- {
- DirectoryInfo dir = new DirectoryInfo(folderLocation);
- // makes everything wrapped in an XElement called serverfiles.
- // Also a declaration as specified (sorry about the standalone status:
- // it's required in the XDeclaration constructor)
- var doc = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"),
- CREATEXML(dir));
- Console.WriteLine(doc.ToString());
- Console.Read();
- }
- private static XElement CREATEXML(DirectoryInfo dir)
- {
- //get directories
- var xmlInfo = new XElement("serverfiles", new XAttribute("name", dir.Name));
- //get all the files first
- foreach (var file in dir.GetFiles())
- {
- xmlInfo.Add(new XElement("file", new XAttribute("name", file.Name)));
- }
- //get subdirectories
- foreach (var subDir in dir.GetDirectories())
- {
- xmlInfo.Add(CREATEXML(subDir));
- }
- return xmlInfo;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement