This is an update to a project I wrote using the .NET alpha release. This version
works with the .NET Beta 2 release.

I was looking for a useful little project to start learning C# and the .NET framework.
In my job we do a lot of things with XML so I was interested in exercising some of
the XML classes. In particular I wanted to see how XML and ADO+ fit together. The
result is the code in this project.

This code generates a list of entries in a directory as XML. The XML can be
returned to the caller as an XML string, a W3C DOM document, or an ADO+ DataSet.

A word of WARNING. To compile the attached code, you need to have the .NET Framework SDK
Beta 2 installed which. You can get the .NET Framework SDK here.
Please don't send me questions regarding installation of the SDK.

This says that I am creating a namespace for my code. Code that references the
XMLDirectoryLister will have to include the following line:

using GregHack.XMLStuff.Cs;

The meat of the work is done in the getXMLUsingDOMCalls() and
the getXMLUsingTextWriterClass() methods. They both create
a W3C document via the XmlDocument class of the .NET framework but using
alternate methods to do so. The first method uses the XmlDocument class
of the framework to add to and traverse the XML document. The second method uses the
XMLTextWriter class to accomplish the same thing.

Both implementations loop through all of the entries in the directory using the
foreach syntax of C#:

foreach ( FileSystemEntry entry in dir.GetFileSystemEntries() )

The XmlDocument version uses the AppendChild() method
to insert elements into the document that represent the entries in the directory. The
XMLTextWriter version uses WriteElementString() to accomplish
the same thing.

Something that I thought was pretty cool is how easy it is to translate XML into
an ADO+ DataSet. The following lines of code that are in the getXMLDataset
are all that are needed:

When the getXMLDataset() method is called, it returns a DataSet
with two tables dirlist and entry. Entry has 7 columns,

name, created, lastaccess, lastwrite, isfile, isdir, readonly

. You can see the
relationship between the XML and the tables.

One last thing of interest is the class and method documentation. You'll notice it
uses three forward slashes and some XML tags. If
you use this style you can tell the compiler to emit XML documentation as output. It
will then create and XML file containing the documentation you put in your source file.
The XML could then be rendered as HTML or some other format to document you source. Use
a specifier in your makefile such as /doc:XMLDirectoryLister.xml to emit
the XML documentation file. The sample project contains the XML documentation emitted
by the compiler.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

return doc;
}
}
}
I then pass a directory name using the button click event on another page:
private void Button1_Click(object sender, System.EventArgs e)
{
UltraWebGrid1.Rows.Clear();
XMLDirectoryLister xmld = new XMLDirectoryLister(true);
string dirname = "C:\\Xml document editor";
xmld.getXMLDocument(dirname);
}
but I don't see anyxml file being generated. How and where do I specify a name and path for the new file to be generated ? Can you please point out what I should do to accomplish creating and writing to an xml file , a specified directory's structure ?
Thanks

I have known for some time the code only worked with the alpha release of the .NET SDK and actually converted most of the code over some time ago. I finally got around to finishing the work and just posted it. It should appear here very shortly. Sorry for the delay in getting it done, but sometimes the day job takes up all the spare time.

1. Insert "System.xml.dll" and "System.data.dll" into the project (or solution like it´s seems to be called now):

In "Solution Explorer", click on "References" and select "Add References" via
popup-menu. It is now possible to select and add the DLL´s from the list in the dialog box.

2. This example uses an unknown namespace (unknown to my version of the .net framework), therefore change all "NewXML" to "XML" in the *.cs-files, for example "using System.NewXML" to "using System.Xml"

3. It can be compiled now, but you get an exception during runtime. To remove the exception I changed the following instruction in "XMLDirectoryLister.cs":