<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" version="2.0">
  <channel>
    <title>Paul Mrozowski's Blog - LINQ</title>
    <link>http://www.rcs-solutions.com/blog/</link>
    <description>A day in the life (of a developer)</description>
    <language>en-us</language>
    <copyright>Paul Mrozowski / RCS Solutions, Inc.</copyright>
    <lastBuildDate>Sun, 30 Nov 2008 18:46:11 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>paulm@rcs-solutions.com</managingEditor>
    <webMaster>paulm@rcs-solutions.com</webMaster>
    <item>
      <trackback:ping>http://www.rcs-solutions.com/blog/Trackback.aspx?guid=46c2ad44-1dcb-4363-b727-050ee2494dfb</trackback:ping>
      <pingback:server>http://www.rcs-solutions.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.rcs-solutions.com/blog/PermaLink,guid,46c2ad44-1dcb-4363-b727-050ee2494dfb.aspx</pingback:target>
      <dc:creator>Paul Mrozowski</dc:creator>
      <wfw:comment>http://www.rcs-solutions.com/blog/CommentView,guid,46c2ad44-1dcb-4363-b727-050ee2494dfb.aspx</wfw:comment>
      <wfw:commentRss>http://www.rcs-solutions.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=46c2ad44-1dcb-4363-b727-050ee2494dfb</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <style type="text/css">
.code { background-color: #efefef; font-family:consolas,courier new; }
</style>
        <p>
I recently added a maintenance form to our website which allows a user to add and
delete entries to a list of banner ads stored in a simple XML file. Previously we've
just been maintaining them manually by editing the XML directly and copying the associated
banner images into a folder on the website. When you delete an ad, I decided to NOT
delete the associated image since they may be reused (and I wanted to avoid forcing
the user to upload the image again). However, we'd still like to periodically clean
out this folder and "archive" the images so they're not cluttering up the selection
screen.
</p>
        <p>
I basically needed some code which would get me a list of files in the banner images
folder which were not referenced in my banner XML file. It can be kind of clunky to
iterate through XML but they've made it much easier with the introduction of LINQ.
I fired up LINQPad (which, BTW, is an AWESOME free tool for testing out LINQ code)
and tried out a few ideas. As a side note, it looks like Intellisense is now available
if you purchase a copy of LINQPad.
</p>
        <p>
          <a href="http://www.linqpad.net/">http://www.linqpad.net/</a>
        </p>
        <p>
I started with querying the filesystem to get a list of files:
</p>
   
<div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"><p style="margin: 0px"><span style="color: #2b91af">DirectoryInfo</span> info = <span style="color: blue">new</span><span style="color: #2b91af">DirectoryInfo</span>(<span style="color: #a31515">@"X:\inetpub\wwwroot\images\banner"</span>);
</p><p style="margin: 0px"><span style="color: #2b91af">FileInfo</span>[] files = info.GetFiles();
</p><p style="margin: 0px">
 
</p><p style="margin: 0px">
files.Dump();
</p><p style="margin: 0px">
 
</p></div><p>
.Dump() is an extension method available in LINQPad which dumps out the results of
the query (we haven't actually used LINQ yet to do anything). 
</p><p>
Here's what it looks like: 
</p><p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="308" alt="FileInfoLinq" src="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/LINQQueriesXMLandtheFilesystem_C03C/FileInfoLinq_3.png" width="780" border="0" /></p><p>
You might notice that Directory contains a DirectyInfo element. If you click on the
down arrow it will expand out these values as well. 
</p><p>
So I now had a list of files, I wanted to then get a list of images referenced in
my banner file. Here's the format of the XML file:
</p><pre><p>
&lt;News&gt;    
<br />
   &lt;NewsItem&gt;<br />
       &lt;Title&gt;Supertooth3-banner.gif&lt;/Title&gt;<br />
       &lt;Image&gt;/images/banner/Supertooth3-banner.gif&lt;/Image&gt;<br />
       &lt;Height&gt;183&lt;/Height&gt;<br />
       &lt;Link&gt;/PortalView.aspx?navto=/Supertooth3-banner.gif&lt;/Link&gt;<br />
       &lt;Date&gt;July, 19th, 2003&lt;/Date&gt;<br />
       &lt;Target&gt;&lt;/Target&gt;<br />
   &lt;/NewsItem&gt;    
</p><p>
   
</p><p>
 
</p></pre><p>
I haven't really been using Title for anything besides the name of the image file,
so I was able to take a bit of a shortcut here and use it for my comparison. To pull
out the list of images used in the XML, I wrote this query: 
</p><div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"><p style="margin: 0px"><span style="color: #2b91af">XDocument</span> doc = System.Xml.Linq.<span style="color: #2b91af">XDocument</span>.Load(<span style="color: #a31515">@"X:\inetpub\wwwroot\adv.xml"</span>);
</p><p style="margin: 0px">
doc.Dump();
</p><p style="margin: 0px">
 
</p><p style="margin: 0px"><span style="color: blue">var</span> news = <span style="color: blue">from</span> item <span style="color: blue">in</span> doc.Descendants(<span style="background: #e5e5e5">"Title"</span>)
</p><p style="margin: 0px">
           <span style="color: blue">orderby</span> item.Value
</p><p style="margin: 0px">
           <span style="color: blue">select</span> item.Value;
</p><p style="margin: 0px">
news.Dump();
</p></div><p>
 
</p><p>
Which produces this: 
</p><p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="221" alt="XmlTitlesLinq" src="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/LINQQueriesXMLandtheFilesystem_C03C/XmlTitlesLinq_3.png" width="267" border="0" /></p><p>
I noticed that the banner images folder contained a bunch of other files that I really
didn't want to consider for filtering, so I needed to narrow my query to files that
had specific extensions. C# doesn't really have a direct equivalent for INLIST, but
we can do this a slightly different way for the same effect. 
</p><p>
First I define an array of valid extensions, then (inside the where clause of the
LINQ query) I check to see if this list of file types contains the filetype of the
file I'm currently evaluating. It's a bit backwards, but it's simple and it works. 
</p><div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"><p style="margin: 0px"><span style="color: blue">string</span>[] fileTypes = { <span style="background: #e5e5e5">".jpg"</span>, <span style="background: #e5e5e5">".gif"</span>, <span style="background: #e5e5e5">".png"</span> };
</p><p style="margin: 0px"><span style="color: blue">var</span> imgFiles = <span style="color: blue">from</span> file <span style="color: blue">in</span> files
</p><p style="margin: 0px">
               <span style="color: blue">where</span> (fileTypes.Contains(file.Extension))
</p><p style="margin: 0px">
               <span style="color: blue">orderby</span> file.Name
</p><p style="margin: 0px">
               <span style="color: blue">select</span> file.Name;
</p><p style="margin: 0px">
 
</p><p style="margin: 0px">
imgFiles.Dump();
</p><p style="margin: 0px">
 
</p></div><p>
Now I've got a list of files from my XML and a list of files from the banner images
folder. I want to get a list of files from the banner images folder that aren't in
the XML list. I do this via a final query: 
</p><div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"><p style="margin: 0px"><span style="color: blue">var</span> extra = <span style="color: blue">from</span> singleFile <span style="color: blue">in</span> imgFiles
</p><p style="margin: 0px">
            <span style="color: blue">where</span> !(news.Contains(singleFile))
</p><p style="margin: 0px">
            <span style="color: blue">select</span> singleFile;
</p><p style="margin: 0px">
extra.Dump();    
</p></div><p>
This returns my extra files. Now I can just use this list to move my images into an
archive folder periodically. 
</p><p>
If I put it all together, I end up with this:
</p><div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"><p style="margin: 0px"><span style="color: #2b91af"></span> 
</p><p style="margin: 0px"><span style="color: #2b91af">XDocument</span> doc = System.Xml.Linq.<span style="color: #2b91af">XDocument</span>.Load(<span style="color: #a31515">@"X:\inetpub\wwwroot\adv.xml"</span>);
</p><p style="margin: 0px"><span style="color: #2b91af">DirectoryInfo</span> info = <span style="color: blue">new</span><span style="color: #2b91af">DirectoryInfo</span>(<span style="color: #a31515">@"X:\inetpub\wwwroot\images\banner"</span>);
</p><p style="margin: 0px"><span style="color: #2b91af">FileInfo</span>[] files = info.GetFiles();
</p><p style="margin: 0px">
doc.Dump();
</p><p style="margin: 0px">
files.Dump();
</p><p style="margin: 0px">
 
</p><p style="margin: 0px"><span style="color: blue">var</span> news = <span style="color: blue">from</span> item <span style="color: blue">in</span> doc.Descendants(<span style="background: #e5e5e5">"Title"</span>)
</p><p style="margin: 0px">
           <span style="color: blue">orderby</span> item.Value
</p><p style="margin: 0px">
           <span style="color: blue">select</span> item.Value;
</p><p style="margin: 0px">
news.Dump();
</p><p style="margin: 0px"><span style="color: blue">string</span>[] fileTypes = { <span style="background: #e5e5e5">".jpg"</span>, <span style="background: #e5e5e5">".gif"</span>, <span style="background: #e5e5e5">".png"</span> };
</p><p style="margin: 0px"><span style="color: blue">var</span> imgFiles = <span style="color: blue">from</span> file <span style="color: blue">in</span> files
</p><p style="margin: 0px">
               <span style="color: blue">where</span> (fileTypes.Contains(file.Extension))
</p><p style="margin: 0px">
               <span style="color: blue">orderby</span> file.Name
</p><p style="margin: 0px">
               <span style="color: blue">select</span> file.Name;
</p><p style="margin: 0px">
 
</p><p style="margin: 0px">
imgFiles.Dump();
</p><p style="margin: 0px">
 
</p><p style="margin: 0px"><span style="color: blue">var</span> extra = <span style="color: blue">from</span> singleFile <span style="color: blue">in</span> imgFiles
</p><p style="margin: 0px">
            <span style="color: blue">where</span> !(news.Contains(singleFile))
</p><p style="margin: 0px">
            <span style="color: blue">select</span> singleFile;
</p><p style="margin: 0px">
extra.Dump();    
</p></div><p><strong>Links:</strong></p><p><a href="http://www.linqpad.net/">http://www.linqpad.net/</a></p><img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=46c2ad44-1dcb-4363-b727-050ee2494dfb" /></body>
      <title>LINQ Queries - XML and the Filesystem</title>
      <guid isPermaLink="false">http://www.rcs-solutions.com/blog/PermaLink,guid,46c2ad44-1dcb-4363-b727-050ee2494dfb.aspx</guid>
      <link>http://www.rcs-solutions.com/blog/2008/11/30/LINQQueriesXMLAndTheFilesystem.aspx</link>
      <pubDate>Sun, 30 Nov 2008 18:46:11 GMT</pubDate>
      <description> &lt;style type="text/css"&gt;
.code { background-color: #efefef; font-family:consolas,courier new; }
&lt;/style&gt;
&lt;p&gt;
I recently added a maintenance form to our website which allows a user to add and
delete entries to a list of banner ads stored in a simple XML file. Previously we've
just been maintaining them manually by editing the XML directly and copying the associated
banner images into a folder on the website. When you delete an ad, I decided to NOT
delete the associated image since they may be reused (and I wanted to avoid forcing
the user to upload the image again). However, we'd still like to periodically clean
out this folder and "archive" the images so they're not cluttering up the selection
screen.
&lt;/p&gt;
&lt;p&gt;
I basically needed some code which would get me a list of files in the banner images
folder which were not referenced in my banner XML file. It can be kind of clunky to
iterate through XML but they've made it much easier with the introduction of LINQ.
I fired up LINQPad (which, BTW, is an AWESOME free tool for testing out LINQ code)
and tried out a few ideas. As a side note, it looks like Intellisense is now available
if you purchase a copy of LINQPad.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.linqpad.net/"&gt;http://www.linqpad.net/&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
I started with querying the filesystem to get a list of files:
&lt;/p&gt;
&amp;nbsp;&amp;nbsp; 
&lt;div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #2b91af"&gt;DirectoryInfo&lt;/span&gt; info = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DirectoryInfo&lt;/span&gt;(&lt;span style="color: #a31515"&gt;@"X:\inetpub\wwwroot\images\banner"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #2b91af"&gt;FileInfo&lt;/span&gt;[] files = info.GetFiles();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
files.Dump();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
.Dump() is an extension method available in LINQPad which dumps out the results of
the query (we haven't actually used LINQ yet to do anything). 
&lt;/p&gt;
&lt;p&gt;
Here's what it looks like: 
&lt;/p&gt;
&lt;p&gt;
&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="308" alt="FileInfoLinq" src="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/LINQQueriesXMLandtheFilesystem_C03C/FileInfoLinq_3.png" width="780" border="0"&gt; 
&lt;p&gt;
You might notice that Directory contains a DirectyInfo element. If you click on the
down arrow it will expand out these values as well. 
&lt;/p&gt;
&lt;p&gt;
So I now had a list of files, I wanted to then get a list of images referenced in
my banner file. Here's the format of the XML file:
&lt;/p&gt;
&lt;pre&gt;
&lt;p&gt;
&amp;lt;News&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;NewsItem&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Title&amp;gt;Supertooth3-banner.gif&amp;lt;/Title&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Image&amp;gt;/images/banner/Supertooth3-banner.gif&amp;lt;/Image&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Height&amp;gt;183&amp;lt;/Height&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Link&amp;gt;/PortalView.aspx?navto=/Supertooth3-banner.gif&amp;lt;/Link&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Date&amp;gt;July, 19th, 2003&amp;lt;/Date&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Target&amp;gt;&amp;lt;/Target&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;/NewsItem&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;p&gt;
&amp;nbsp;&amp;nbsp; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/pre&gt;
&lt;p&gt;
I haven't really been using Title for anything besides the name of the image file,
so I was able to take a bit of a shortcut here and use it for my comparison. To pull
out the list of images used in the XML, I wrote this query: 
&lt;/p&gt;
&lt;div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #2b91af"&gt;XDocument&lt;/span&gt; doc = System.Xml.Linq.&lt;span style="color: #2b91af"&gt;XDocument&lt;/span&gt;.Load(&lt;span style="color: #a31515"&gt;@"X:\inetpub\wwwroot\adv.xml"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
doc.Dump();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;var&lt;/span&gt; news = &lt;span style="color: blue"&gt;from&lt;/span&gt; item &lt;span style="color: blue"&gt;in&lt;/span&gt; doc.Descendants(&lt;span style="background: #e5e5e5"&gt;"Title"&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;orderby&lt;/span&gt; item.Value
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;select&lt;/span&gt; item.Value;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
news.Dump();
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Which produces this: 
&lt;/p&gt;
&lt;p&gt;
&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="221" alt="XmlTitlesLinq" src="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/LINQQueriesXMLandtheFilesystem_C03C/XmlTitlesLinq_3.png" width="267" border="0"&gt; 
&lt;/p&gt;
&lt;p&gt;
I noticed that the banner images folder contained a bunch of other files that I really
didn't want to consider for filtering, so I needed to narrow my query to files that
had specific extensions. C# doesn't really have a direct equivalent for INLIST, but
we can do this a slightly different way for the same effect. 
&lt;/p&gt;
&lt;p&gt;
First I define an array of valid extensions, then (inside the where clause of the
LINQ query) I check to see if this list of file types contains the filetype of the
file I'm currently evaluating. It's a bit backwards, but it's simple and it works. 
&lt;/p&gt;
&lt;div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;string&lt;/span&gt;[] fileTypes = { &lt;span style="background: #e5e5e5"&gt;".jpg"&lt;/span&gt;, &lt;span style="background: #e5e5e5"&gt;".gif"&lt;/span&gt;, &lt;span style="background: #e5e5e5"&gt;".png"&lt;/span&gt; };
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;var&lt;/span&gt; imgFiles = &lt;span style="color: blue"&gt;from&lt;/span&gt; file &lt;span style="color: blue"&gt;in&lt;/span&gt; files
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;where&lt;/span&gt; (fileTypes.Contains(file.Extension))
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;orderby&lt;/span&gt; file.Name
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;select&lt;/span&gt; file.Name;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
imgFiles.Dump();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
Now I've got a list of files from my XML and a list of files from the banner images
folder. I want to get a list of files from the banner images folder that aren't in
the XML list. I do this via a final query: 
&lt;/p&gt;
&lt;div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;var&lt;/span&gt; extra = &lt;span style="color: blue"&gt;from&lt;/span&gt; singleFile &lt;span style="color: blue"&gt;in&lt;/span&gt; imgFiles
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;where&lt;/span&gt; !(news.Contains(singleFile))
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;select&lt;/span&gt; singleFile;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
extra.Dump();&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
This returns my extra files. Now I can just use this list to move my images into an
archive folder periodically. 
&lt;/p&gt;
&lt;p&gt;
If I put it all together, I end up with this:
&lt;/p&gt;
&lt;div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #2b91af"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #2b91af"&gt;XDocument&lt;/span&gt; doc = System.Xml.Linq.&lt;span style="color: #2b91af"&gt;XDocument&lt;/span&gt;.Load(&lt;span style="color: #a31515"&gt;@"X:\inetpub\wwwroot\adv.xml"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #2b91af"&gt;DirectoryInfo&lt;/span&gt; info = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DirectoryInfo&lt;/span&gt;(&lt;span style="color: #a31515"&gt;@"X:\inetpub\wwwroot\images\banner"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #2b91af"&gt;FileInfo&lt;/span&gt;[] files = info.GetFiles();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
doc.Dump();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
files.Dump();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;var&lt;/span&gt; news = &lt;span style="color: blue"&gt;from&lt;/span&gt; item &lt;span style="color: blue"&gt;in&lt;/span&gt; doc.Descendants(&lt;span style="background: #e5e5e5"&gt;"Title"&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;orderby&lt;/span&gt; item.Value
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;select&lt;/span&gt; item.Value;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
news.Dump();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;string&lt;/span&gt;[] fileTypes = { &lt;span style="background: #e5e5e5"&gt;".jpg"&lt;/span&gt;, &lt;span style="background: #e5e5e5"&gt;".gif"&lt;/span&gt;, &lt;span style="background: #e5e5e5"&gt;".png"&lt;/span&gt; };
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;var&lt;/span&gt; imgFiles = &lt;span style="color: blue"&gt;from&lt;/span&gt; file &lt;span style="color: blue"&gt;in&lt;/span&gt; files
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;where&lt;/span&gt; (fileTypes.Contains(file.Extension))
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;orderby&lt;/span&gt; file.Name
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;select&lt;/span&gt; file.Name;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
imgFiles.Dump();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;var&lt;/span&gt; extra = &lt;span style="color: blue"&gt;from&lt;/span&gt; singleFile &lt;span style="color: blue"&gt;in&lt;/span&gt; imgFiles
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;where&lt;/span&gt; !(news.Contains(singleFile))
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;select&lt;/span&gt; singleFile;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
extra.Dump();&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;strong&gt;Links:&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.linqpad.net/"&gt;http://www.linqpad.net/&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=46c2ad44-1dcb-4363-b727-050ee2494dfb" /&gt;</description>
      <comments>http://www.rcs-solutions.com/blog/CommentView,guid,46c2ad44-1dcb-4363-b727-050ee2494dfb.aspx</comments>
      <category>.NET</category>
      <category>C#</category>
      <category>LINQ</category>
    </item>
  </channel>
</rss>