<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David&#039;s technobabble &#187; C#</title>
	<atom:link href="http://bable.cybermarshall.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://bable.cybermarshall.com</link>
	<description>David&#039;s thoughts about this and that</description>
	<lastBuildDate>Fri, 22 Jan 2010 18:29:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A walkthrough the code to extend the HP Digital Sending Software</title>
		<link>http://bable.cybermarshall.com/2009/05/21/a-walkthrough-the-code-to-extend-the-hp-digital-sending-software/</link>
		<comments>http://bable.cybermarshall.com/2009/05/21/a-walkthrough-the-code-to-extend-the-hp-digital-sending-software/#comments</comments>
		<pubDate>Fri, 22 May 2009 00:05:36 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[OCR]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[searchable PDF]]></category>

		<guid isPermaLink="false">http://bable.cybermarshall.com/?p=483</guid>
		<description><![CDATA[Recently, I wrote about extending the HP Digital Sending Software to &#8220;close the gap&#8221; and email the OCR&#8217;ed result. I received a request to release the code, so I&#8217;ve decided to do so with a bit a of documentation.

The HP digital sending software creates an XML document similar to the one below and places it [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I wrote about extending the <a href="http://tinyurl.com/onq3me" onclick="pageTracker._trackPageview('/outgoing/tinyurl.com/onq3me?referer=');">HP Digital Sending Software</a> to &#8220;close the gap&#8221; and email the OCR&#8217;ed result. I received a request to release the code, so I&#8217;ve decided to do so with a bit a of documentation.<br />
<span id="more-483"></span></p>
<p>The HP digital sending software creates an XML document similar to the one below and places it in the same folder with the OCR&#8217;ed PDF. This foldername will be set set in the App.config file so this service kniows where to watch.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code9'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4839"><td class="code" id="p483code9"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt;--! <span style="color: #ff0000;">&quot;s2d96A4D5F15D87FB9658B0ABC53184EE0A_1.xml --&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Info</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> <span style="color: #000066;">Version</span>=<span style="color: #ff0000;">&quot;4.0&quot;</span> <span style="color: #000066;">SentTimeStamp</span>=<span style="color: #ff0000;">&quot;2009-05-17 01:59:15 Pacific Daylight Time (GMT+08:00)&quot;</span> <span style="color: #000066;">FileName</span>=<span style="color: #ff0000;">&quot;s2d96A4D5F15D87FB9658B0ABC53184EE0A_1.pdf&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Scanner</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;my-printer&quot;</span> <span style="color: #000066;">ModelName</span>=<span style="color: #ff0000;">&quot;hp LaserJet 4345 mfp&quot;</span> <span style="color: #000066;">Status</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/Scanner<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Sender</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;GUEST&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/Sender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ScanSettings</span> <span style="color: #000066;">FileFormat</span>=<span style="color: #ff0000;">&quot;jpeg&quot;</span> <span style="color: #000066;">SendingQuality</span>=<span style="color: #ff0000;">&quot;COLOR DOCUMENT&quot;</span> <span style="color: #000066;">Pages</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Duplex</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/ScanSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Destination</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;SEND PDF TO MAIL&quot;</span> <span style="color: #000066;">Path</span>=<span style="color: #ff0000;">&quot;*.COMMON MFP GROUP.SEARCHABLE PDF&quot;</span> <span style="color: #000066;">NumberOfPrompts</span>=<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Prompt</span> <span style="color: #000066;">Index</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;MY-FROM&quot;</span> <span style="color: #000066;">Displaytext</span>=<span style="color: #ff0000;">&quot;From:&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #339933;">&lt;![CDATA[printer@somedomain]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Prompt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Prompt</span> <span style="color: #000066;">Index</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;MY-TO&quot;</span> <span style="color: #000066;">Displaytext</span>=<span style="color: #ff0000;">&quot;To:&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #339933;">&lt;![CDATA[email@somedomain]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Prompt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Prompt</span> <span style="color: #000066;">Index</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;MY-SUBJECT&quot;</span> <span style="color: #000066;">Displaytext</span>=<span style="color: #ff0000;">&quot;Subject:&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #339933;">&lt;![CDATA[Digital Document from My Printer]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Prompt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Destination<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Info<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>You can see above, the FileName, From Email Address, To Email Address(es) and Email Subject have been provided. Once this information was married with an SMTP Server, then all of the information required to email the resulting OCR&#8217;ed file as an attachment was available. </p>
<p>I wrote and built the code using Visual Studio 2008. Since the code uses .NET 2.0 you could use Visual Studio 2005 or 2008. Alternatively, you can download the full .NET 2.0 SDK and compile the code with the .NET C# compiler, csc. </p>
<p>In order to make the service flexible, the configuration data is in my App.config file</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code10'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48310"><td class="code" id="p483code10"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;">&lt;--! Where HP Scanning Software places the files --<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;WorkFlowScanPath&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;D:\test\files&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;--! The file type to watch for changes --<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;WorkFlowScanFileType&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;*.xml&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;--! The smtp server to send the email to --<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;WorkFlowScanSMTPServer&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;some.smtpserver&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;--! The text of the email body --<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;WorkFlowScanMailText&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'Your scanned document is attached.'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;--! What to do after the email <span style="color: #ff0000;">&quot;delete&quot;</span> or <span style="color: #ff0000;">&quot;keep&quot;</span> --<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;WorkFlowScanAfterSendAction&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;delete&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;--! If <span style="color: #ff0000;">&quot;keep&quot;</span>, where to move the processed files --<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;WorkFlowScanProcessedPath&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;D:\test\processed&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;--! The XPATH Query string to locate the from email address inside the HP produced xml file --<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;WorkFlowScanXPath_From&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'/Info/Destination/Prompt[@Displaytext=&quot;From:&quot;]'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;--! The XPATH Query string to locate the to email address inside the HP produced xml file --<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;WorkFlowScanXPath_To&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'/Info/Destination/Prompt[@Displaytext=&quot;To:&quot;]'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;--! The XPATH Query string to locate the from subject from inside the HP produced xml file --<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;WorkFlowScanXPath_Subject&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'/Info/Destination/Prompt[@Displaytext=&quot;Subject:&quot;]'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The class inherits from the .NET ServiceBase class</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code11'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48311"><td class="code" id="p483code11"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> eS_HPScan_WorkFlowEXT_Service <span style="color: #008000;">:</span> ServiceBase</pre></td></tr></table></div>

<p>When the service is started the OnStart method is called; the configuration data is retrieved and the file watcher event handler is setup and activated.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code12'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48312"><td class="code" id="p483code12"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnStart<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            log<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;starting&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            WorkflowScanPath <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanPath&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkflowScanProcessedPath <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanProcessedPath&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkflowScanFileType <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanFileType&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkFlowScanAfterSendAction <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanAfterSendAction&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkflowScanSMTPServer <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanSMTPServer&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkFlowScanMailText <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanMailText&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkFlowScanXPath_From <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanXPath_From&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkFlowScanXPath_To <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanXPath_To&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkFlowScanXPath_Subject <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanXPath_Subject&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            fileSystemWatcher1 <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">FileSystemWatcher</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">Path</span> <span style="color: #008000;">=</span> WorkflowScanPath<span style="color: #008000;">;</span>
            fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">Filter</span> <span style="color: #008000;">=</span> WorkflowScanFileType<span style="color: #008000;">;</span>
            fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">IncludeSubdirectories</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
            fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">Changed</span> <span style="color: #008000;">+=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">FileSystemEventHandler</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">File_Changed</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">NotifyFilter</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>NotifyFilters<span style="color: #008000;">.</span><span style="color: #0000FF;">CreationTime</span> <span style="color: #008000;">|</span> NotifyFilters<span style="color: #008000;">.</span><span style="color: #0000FF;">LastWrite</span> <span style="color: #008000;">|</span> NotifyFilters<span style="color: #008000;">.</span><span style="color: #0000FF;">FileName</span> <span style="color: #008000;">|</span> NotifyFilters<span style="color: #008000;">.</span><span style="color: #0000FF;">DirectoryName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">EnableRaisingEvents</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
            log<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;started&quot;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;-monitoring type(s) &quot;</span> <span style="color: #008000;">+</span> WorkflowScanFileType <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; in folder &quot;</span> <span style="color: #008000;">+</span> fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">Path</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The File_Changed event handler is really pretty boring. All of the real action happens in the method process_file. However, every time a file changes in the folder being watched that is of type *.xml, then this method is called with the full path of the file changed.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code13'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48313"><td class="code" id="p483code13"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> File_Changed<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">FileSystemEventArgs</span> e<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
             log<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;File_Changed: &quot;</span> <span style="color: #008000;">+</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">FullPath</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// file move causes event on the original file after moved, make sure file exists</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">FullPath</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
             process_file<span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">FullPath</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The process_file method reads the xml file for the attributes of FileName, From Email Address, To Email Address(es) and Email Subject. Afterwards, an email is sent with the OCR&#8217;ed file as an attachment. Finally, the files are moved or deleted depending on the setting in the App.config file.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code14'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48314"><td class="code" id="p483code14"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> process_file<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> xml_file_withpath<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            XmlNode xNode <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            XmlDocument xDoc <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> XmlDocument<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            Attachment message_attachment <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">try</span>
            <span style="color: #008000;">&#123;</span>
               xDoc<span style="color: #008000;">.</span><span style="color: #0000FF;">Load</span><span style="color: #008000;">&#40;</span>xml_file_withpath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               xNode <span style="color: #008000;">=</span> xDoc<span style="color: #008000;">.</span><span style="color: #0000FF;">SelectSingleNode</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;/Info&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #6666cc; font-weight: bold;">string</span> pdf_File_name <span style="color: #008000;">=</span> xNode<span style="color: #008000;">.</span><span style="color: #0000FF;">Attributes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetNamedItem</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FileName&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span> 
               pdf_File_name <span style="color: #008000;">=</span> WorkflowScanPath <span style="color: #008000;">+</span> pathSep <span style="color: #008000;">+</span> pdf_File_name<span style="color: #008000;">;</span>
               <span style="color: #6666cc; font-weight: bold;">string</span> scan_from <span style="color: #008000;">=</span> get_email_info<span style="color: #008000;">&#40;</span>xDoc, WorkFlowScanXPath_From<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #6666cc; font-weight: bold;">string</span> scan_to <span style="color: #008000;">=</span> get_email_info<span style="color: #008000;">&#40;</span>xDoc, WorkFlowScanXPath_To<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #6666cc; font-weight: bold;">string</span> scan_subject <span style="color: #008000;">=</span> get_email_info<span style="color: #008000;">&#40;</span>xDoc, WorkFlowScanXPath_Subject<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                MailMessage message <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> MailMessage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               message<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">From</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> MailAddress<span style="color: #008000;">&#40;</span>scan_from<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #008080; font-style: italic;">// allow the to address to use , ; and whitespace as separators</span>
               <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>scan_to<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;,&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> scan_to<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;;&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> scan_to<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
               <span style="color: #008000;">&#123;</span>
                   <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> stringSeparators <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">&quot;,&quot;</span>, <span style="color: #666666;">&quot;;&quot;</span>, <span style="color: #666666;">&quot; &quot;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
                   <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> to_addresses <span style="color: #008000;">=</span> scan_to<span style="color: #008000;">.</span><span style="color: #0000FF;">Split</span><span style="color: #008000;">&#40;</span>stringSeparators, StringSplitOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                   <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> ts <span style="color: #0600FF; font-weight: bold;">in</span> to_addresses<span style="color: #008000;">&#41;</span>
                   <span style="color: #008000;">&#123;</span>
                       <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>ts <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">!</span>ts<span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">!</span>ts<span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                       <span style="color: #008000;">&#123;</span>
                           message<span style="color: #008000;">.</span><span style="color: #0000FF;">To</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> MailAddress<span style="color: #008000;">&#40;</span>ts<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                       <span style="color: #008000;">&#125;</span>
                   <span style="color: #008000;">&#125;</span>
               <span style="color: #008000;">&#125;</span>
               <span style="color: #0600FF; font-weight: bold;">else</span>
               <span style="color: #008000;">&#123;</span>
                   message<span style="color: #008000;">.</span><span style="color: #0000FF;">To</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> MailAddress<span style="color: #008000;">&#40;</span>scan_to<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #008000;">&#125;</span>
&nbsp;
               message<span style="color: #008000;">.</span><span style="color: #0000FF;">Subject</span> <span style="color: #008000;">=</span> scan_subject<span style="color: #008000;">;</span>
               message<span style="color: #008000;">.</span><span style="color: #0000FF;">Body</span> <span style="color: #008000;">=</span> WorkFlowScanMailText<span style="color: #008000;">;</span>
               <span style="color: #008080; font-style: italic;">// Create  the file attachment for this e-mail message.</span>
               message_attachment <span style="color: #008000;">=</span> attach_file<span style="color: #008000;">&#40;</span>pdf_File_name<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #008080; font-style: italic;">// Add the file attachment to this e-mail message.</span>
               message<span style="color: #008000;">.</span><span style="color: #0000FF;">Attachments</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>message_attachment<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #008080; font-style: italic;">//Send the message.</span>
               SmtpClient mclient <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> SmtpClient<span style="color: #008000;">&#40;</span>WorkflowScanSMTPServer<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               mclient<span style="color: #008000;">.</span><span style="color: #0000FF;">Send</span><span style="color: #008000;">&#40;</span>message<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               message_attachment<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// free the memory and files!!</span>
               message_attachment <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
               move_delete_file<span style="color: #008000;">&#40;</span>xml_file_withpath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               move_delete_file<span style="color: #008000;">&#40;</span>pdf_File_name<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception ex<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                log<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Exception caught in process_file(): &quot;</span> <span style="color: #008000;">+</span> ex<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, EventLogEntryType<span style="color: #008000;">.</span><span style="color: #0000FF;">Error</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>  
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>message_attachment <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                message_attachment<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// free the memory!!</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The attach_file method deserves a bit of explanation. In a few cases, the XML file arrives before the actual OCR&#8217;ed file. To handle this case there is a loop to make sure that the OCR&#8217;ed file exists.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code15'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48315"><td class="code" id="p483code15"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">private</span> Attachment attach_file<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> attach_file<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Attachment result <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">int</span> cmax <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// Try file for 10 seconds</span>
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i<span style="color: #008000;">=</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>i <span style="color: #008000;">&lt;=</span> cmax<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>attach_file<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #008000;">==</span> cmax<span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> Exception<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;File does not exist: &quot;</span> <span style="color: #008000;">+</span> attach_file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #000000;">System.<span style="color: #0000FF;">Threading</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Thread</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">else</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            result <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> Attachment<span style="color: #008000;">&#40;</span>attach_file, MediaTypeNames<span style="color: #008000;">.</span><span style="color: #0000FF;">Application</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Octet</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// Add time stamp information for the file.</span>
            ContentDisposition disposition <span style="color: #008000;">=</span> result<span style="color: #008000;">.</span><span style="color: #0000FF;">ContentDisposition</span><span style="color: #008000;">;</span>
            disposition<span style="color: #008000;">.</span><span style="color: #0000FF;">CreationDate</span> <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetCreationTime</span><span style="color: #008000;">&#40;</span>attach_file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            disposition<span style="color: #008000;">.</span><span style="color: #0000FF;">ModificationDate</span> <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetLastWriteTime</span><span style="color: #008000;">&#40;</span>attach_file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            disposition<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadDate</span> <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetLastAccessTime</span><span style="color: #008000;">&#40;</span>attach_file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> result<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>I think the remainder of the methods are reliatively straight forward and unless someone wants an explanation I&#8217;ll leave that as an exercise for the reader. I did note that one improvement could be to place the email address separators in the App.config file. Although &#8220;;&#8221;, &#8220;,&#8221; and &#8221; &#8221; are the ones commonly used in email.</p>
<p>The full code listing.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code16'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48316"><td class="code" id="p483code16"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.ComponentModel</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Configuration</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Diagnostics</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Net.Mail</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Net.Mime</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.ServiceProcess</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Xml</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Xml.XPath</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">eS_HPScan_Workflow_Extender</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> eS_HPScan_Workflow_Extender
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> eS_HPScan_WorkFlowEXT_Service <span style="color: #008000;">:</span> ServiceBase
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Container</span> components <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">FileSystemWatcher</span> fileSystemWatcher1 <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">String</span> WorkflowScanPath <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">String</span> WorkFlowScanAfterSendAction <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">String</span> WorkflowScanProcessedPath <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">String</span> WorkflowScanFileType <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">String</span> WorkflowScanSMTPServer <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">String</span> WorkFlowScanMailText <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">String</span> WorkFlowScanXPath_From <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">String</span> WorkFlowScanXPath_To <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">String</span> WorkFlowScanXPath_Subject <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">String</span> pathSep <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\\</span>&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">String</span> delete_action <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;delete&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> default_EventID <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> eS_HPScan_WorkFlowEXT_Service<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">// This call is required by the Windows.Forms Component Designer.</span>
		InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008080; font-style: italic;">// TODO: Add any initialization after the InitComponent call</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// The main entry point for the process</span>
	<span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #000000;">System.<span style="color: #0000FF;">ServiceProcess</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">ServiceBase</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> ServicesToRun<span style="color: #008000;">;</span>	
		ServicesToRun <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> <span style="color: #000000;">System.<span style="color: #0000FF;">ServiceProcess</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">ServiceBase</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> eS_HPScan_WorkFlowEXT_Service<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">System.<span style="color: #0000FF;">ServiceProcess</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">ServiceBase</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Run</span><span style="color: #008000;">&#40;</span>ServicesToRun<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">/// &lt;summary&gt; </span>
		<span style="color: #008080; font-style: italic;">/// Required method for Designer support - do not modify </span>
		<span style="color: #008080; font-style: italic;">/// the contents of this method with the code editor.</span>
		<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">// </span>
		<span style="color: #008080; font-style: italic;">// eS_HPScan_WorkFlowEXT_Service</span>
		<span style="color: #008080; font-style: italic;">// </span>
		<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CanShutdown</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ServiceName</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;eS_HPScan_WorkFlowEXT_Service&quot;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// Clean up any resources being used.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Dispose<span style="color: #008000;">&#40;</span> <span style="color: #6666cc; font-weight: bold;">bool</span> disposing <span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span> disposing <span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>components <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> 
			<span style="color: #008000;">&#123;</span>
				components<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span> disposing <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnStart<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            log<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;starting&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            WorkflowScanPath <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanPath&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkflowScanProcessedPath <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanProcessedPath&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkflowScanFileType <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanFileType&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkFlowScanAfterSendAction <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanAfterSendAction&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkflowScanSMTPServer <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanSMTPServer&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkFlowScanMailText <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanMailText&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkFlowScanXPath_From <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanXPath_From&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkFlowScanXPath_To <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanXPath_To&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            WorkFlowScanXPath_Subject <span style="color: #008000;">=</span> ConfigurationSettings<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;WorkFlowScanXPath_Subject&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
            fileSystemWatcher1 <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">FileSystemWatcher</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">Path</span> <span style="color: #008000;">=</span> WorkflowScanPath<span style="color: #008000;">;</span>
            fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">Filter</span> <span style="color: #008000;">=</span> WorkflowScanFileType<span style="color: #008000;">;</span>
            fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">IncludeSubdirectories</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
            fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">Changed</span> <span style="color: #008000;">+=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">FileSystemEventHandler</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">File_Changed</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">NotifyFilter</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>NotifyFilters<span style="color: #008000;">.</span><span style="color: #0000FF;">CreationTime</span> <span style="color: #008000;">|</span> NotifyFilters<span style="color: #008000;">.</span><span style="color: #0000FF;">LastWrite</span> <span style="color: #008000;">|</span> NotifyFilters<span style="color: #008000;">.</span><span style="color: #0000FF;">FileName</span> <span style="color: #008000;">|</span> NotifyFilters<span style="color: #008000;">.</span><span style="color: #0000FF;">DirectoryName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">EnableRaisingEvents</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
            log<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;started&quot;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;-monitoring type(s) &quot;</span> <span style="color: #008000;">+</span> WorkflowScanFileType <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; in folder &quot;</span> <span style="color: #008000;">+</span> fileSystemWatcher1<span style="color: #008000;">.</span><span style="color: #0000FF;">Path</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnStop<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            log<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;stopping&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            log<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;stopped&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> File_Changed<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">FileSystemEventArgs</span> e<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
             log<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;File_Changed: &quot;</span> <span style="color: #008000;">+</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">FullPath</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// file move causes event on the original file after moved, make sure file exists</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">FullPath</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
             process_file<span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">FullPath</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> process_file<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> xml_file_withpath<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            XmlNode xNode <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            XmlDocument xDoc <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> XmlDocument<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            Attachment message_attachment <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">try</span>
            <span style="color: #008000;">&#123;</span>
               xDoc<span style="color: #008000;">.</span><span style="color: #0000FF;">Load</span><span style="color: #008000;">&#40;</span>xml_file_withpath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               xNode <span style="color: #008000;">=</span> xDoc<span style="color: #008000;">.</span><span style="color: #0000FF;">SelectSingleNode</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;/Info&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #6666cc; font-weight: bold;">string</span> pdf_File_name <span style="color: #008000;">=</span> xNode<span style="color: #008000;">.</span><span style="color: #0000FF;">Attributes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetNamedItem</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FileName&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span> 
               pdf_File_name <span style="color: #008000;">=</span> WorkflowScanPath <span style="color: #008000;">+</span> pathSep <span style="color: #008000;">+</span> pdf_File_name<span style="color: #008000;">;</span>
&nbsp;
               <span style="color: #6666cc; font-weight: bold;">string</span> scan_from <span style="color: #008000;">=</span> get_email_info<span style="color: #008000;">&#40;</span>xDoc, WorkFlowScanXPath_From<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #6666cc; font-weight: bold;">string</span> scan_to <span style="color: #008000;">=</span> get_email_info<span style="color: #008000;">&#40;</span>xDoc, WorkFlowScanXPath_To<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #6666cc; font-weight: bold;">string</span> scan_subject <span style="color: #008000;">=</span> get_email_info<span style="color: #008000;">&#40;</span>xDoc, WorkFlowScanXPath_Subject<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                MailMessage message <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> MailMessage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               message<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">From</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> MailAddress<span style="color: #008000;">&#40;</span>scan_from<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #008080; font-style: italic;">// allow the to address to use , ; and whitespace as separators</span>
               <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>scan_to<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;,&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> scan_to<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;;&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> scan_to<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
               <span style="color: #008000;">&#123;</span>
                   <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> stringSeparators <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">&quot;,&quot;</span>, <span style="color: #666666;">&quot;;&quot;</span>, <span style="color: #666666;">&quot; &quot;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
                   <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> to_addresses <span style="color: #008000;">=</span> scan_to<span style="color: #008000;">.</span><span style="color: #0000FF;">Split</span><span style="color: #008000;">&#40;</span>stringSeparators, StringSplitOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                   <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> ts <span style="color: #0600FF; font-weight: bold;">in</span> to_addresses<span style="color: #008000;">&#41;</span>
                   <span style="color: #008000;">&#123;</span>
                       <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>ts <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">!</span>ts<span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">!</span>ts<span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                       <span style="color: #008000;">&#123;</span>
                           message<span style="color: #008000;">.</span><span style="color: #0000FF;">To</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> MailAddress<span style="color: #008000;">&#40;</span>ts<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                       <span style="color: #008000;">&#125;</span>
                   <span style="color: #008000;">&#125;</span>
               <span style="color: #008000;">&#125;</span>
               <span style="color: #0600FF; font-weight: bold;">else</span>
               <span style="color: #008000;">&#123;</span>
                   message<span style="color: #008000;">.</span><span style="color: #0000FF;">To</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> MailAddress<span style="color: #008000;">&#40;</span>scan_to<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #008000;">&#125;</span>
&nbsp;
               message<span style="color: #008000;">.</span><span style="color: #0000FF;">Subject</span> <span style="color: #008000;">=</span> scan_subject<span style="color: #008000;">;</span>
               message<span style="color: #008000;">.</span><span style="color: #0000FF;">Body</span> <span style="color: #008000;">=</span> WorkFlowScanMailText<span style="color: #008000;">;</span> 
               <span style="color: #008080; font-style: italic;">// Create  the file attachment for this e-mail message.</span>
               message_attachment <span style="color: #008000;">=</span> attach_file<span style="color: #008000;">&#40;</span>pdf_File_name<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #008080; font-style: italic;">// Add the file attachment to this e-mail message.</span>
               message<span style="color: #008000;">.</span><span style="color: #0000FF;">Attachments</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>message_attachment<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #008080; font-style: italic;">//Send the message.</span>
               SmtpClient mclient <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> SmtpClient<span style="color: #008000;">&#40;</span>WorkflowScanSMTPServer<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               mclient<span style="color: #008000;">.</span><span style="color: #0000FF;">Send</span><span style="color: #008000;">&#40;</span>message<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               message_attachment<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// free the memory and files!!</span>
               message_attachment <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
               move_delete_file<span style="color: #008000;">&#40;</span>xml_file_withpath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
               move_delete_file<span style="color: #008000;">&#40;</span>pdf_File_name<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception ex<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                log<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Exception caught in process_file(): &quot;</span> <span style="color: #008000;">+</span> ex<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, EventLogEntryType<span style="color: #008000;">.</span><span style="color: #0000FF;">Error</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>  
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>message_attachment <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                message_attachment<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// free the memory!!</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> Attachment attach_file<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> attach_file<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Attachment result <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">int</span> cmax <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// Try file for 10 seconds</span>
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i<span style="color: #008000;">=</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>i <span style="color: #008000;">&lt;=</span> cmax<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>attach_file<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #008000;">==</span> cmax<span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> Exception<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;File does not exist: &quot;</span> <span style="color: #008000;">+</span> attach_file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #000000;">System.<span style="color: #0000FF;">Threading</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Thread</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">else</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            result <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> Attachment<span style="color: #008000;">&#40;</span>attach_file, MediaTypeNames<span style="color: #008000;">.</span><span style="color: #0000FF;">Application</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Octet</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// Add time stamp information for the file.</span>
            ContentDisposition disposition <span style="color: #008000;">=</span> result<span style="color: #008000;">.</span><span style="color: #0000FF;">ContentDisposition</span><span style="color: #008000;">;</span>
            disposition<span style="color: #008000;">.</span><span style="color: #0000FF;">CreationDate</span> <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetCreationTime</span><span style="color: #008000;">&#40;</span>attach_file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            disposition<span style="color: #008000;">.</span><span style="color: #0000FF;">ModificationDate</span> <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetLastWriteTime</span><span style="color: #008000;">&#40;</span>attach_file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            disposition<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadDate</span> <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetLastAccessTime</span><span style="color: #008000;">&#40;</span>attach_file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> result<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> move_delete_file<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> file1<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">try</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #6666cc; font-weight: bold;">string</span> destfile <span style="color: #008000;">=</span> WorkflowScanProcessedPath <span style="color: #008000;">+</span> pathSep <span style="color: #008000;">+</span> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Path</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetFileName</span><span style="color: #008000;">&#40;</span>file1<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>WorkFlowScanAfterSendAction<span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span>delete_action<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Delete</span><span style="color: #008000;">&#40;</span>file1<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">else</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #008080; font-style: italic;">// Move does not have over write option</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>destfile<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Delete</span><span style="color: #008000;">&#40;</span>destfile<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Move</span><span style="color: #008000;">&#40;</span>file1, destfile<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception ex<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> Exception<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Source: &quot;</span> <span style="color: #008000;">+</span> file1 <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; - Dest: &quot;</span> <span style="color: #008000;">+</span> WorkflowScanProcessedPath <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; &quot;</span>,ex<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> get_email_info<span style="color: #008000;">&#40;</span>XmlDocument xd, <span style="color: #6666cc; font-weight: bold;">string</span> p<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> result <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            XmlNode xn <span style="color: #008000;">=</span> xd<span style="color: #008000;">.</span><span style="color: #0000FF;">SelectSingleNode</span><span style="color: #008000;">&#40;</span>p<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            XmlNode cxn <span style="color: #008000;">=</span> xn<span style="color: #008000;">.</span><span style="color: #0000FF;">ChildNodes</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>cxn <a href="http://www.google.com/search?q=is+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=is+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">is</span></a> XmlCDataSection<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                XmlCDataSection cdataSection <span style="color: #008000;">=</span> cxn <span style="color: #0600FF; font-weight: bold;">as</span> XmlCDataSection<span style="color: #008000;">;</span>
                result <span style="color: #008000;">=</span> cdataSection<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> result<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> log<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> s<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            log<span style="color: #008000;">&#40;</span>s, EventLogEntryType<span style="color: #008000;">.</span><span style="color: #0000FF;">Information</span>, default_EventID<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span> <span style="color: #008080; font-style: italic;">// end method</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> log<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> s, EventLogEntryType logtype<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            log<span style="color: #008000;">&#40;</span>s, logtype, default_EventID<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span> <span style="color: #008080; font-style: italic;">// end method</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> log<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> s, EventLogEntryType logtype, <span style="color: #6666cc; font-weight: bold;">int</span> EventID<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            EventLog elog <span style="color: #008000;">=</span> getmylog<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            elog<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteEntry</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ServiceName</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; &quot;</span> <span style="color: #008000;">+</span> s, logtype, EventID<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span> <span style="color: #008080; font-style: italic;">// end method</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> EventLog getmylog<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            EventLog elog<span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">String</span> eventsource, logName<span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">//This name gets registered in the windows registry in</span>
            <span style="color: #008080; font-style: italic;">//a place where the event log knows where to find it.</span>
            eventsource <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ServiceName</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">//Give the event log a unique name. Don't choose </span>
            <span style="color: #008080; font-style: italic;">//Application, Security or System as a name</span>
            logName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Application&quot;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>EventLog<span style="color: #008000;">.</span><span style="color: #0000FF;">SourceExists</span><span style="color: #008000;">&#40;</span>eventsource<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                EventLog<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateEventSource</span><span style="color: #008000;">&#40;</span>eventsource, logName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            elog <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?q=new+msdn.microsoft.com&amp;referer=');"><span style="color: #008000;">new</span></a> EventLog<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">//set the log to read and write from to the new log</span>
            elog<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span> <span style="color: #008000;">=</span> logName<span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">//set the source to this program</span>
            elog<span style="color: #008000;">.</span><span style="color: #0000FF;">Source</span> <span style="color: #008000;">=</span> eventsource<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> elog<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://bable.cybermarshall.com/2009/05/21/a-walkthrough-the-code-to-extend-the-hp-digital-sending-software/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using PowerShell to activate a feature across all Sharepoint 2007/WSS 3.0 sites and subsites</title>
		<link>http://bable.cybermarshall.com/2009/01/17/using-powershell-to-activate-a-feature-across-all-sharepoint-2007wss-30-sites-and-subsites/</link>
		<comments>http://bable.cybermarshall.com/2009/01/17/using-powershell-to-activate-a-feature-across-all-sharepoint-2007wss-30-sites-and-subsites/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 18:57:35 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[WSS]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[WSS 3.0]]></category>

		<guid isPermaLink="false">http://bable.cybermarshall.com/?p=338</guid>
		<description><![CDATA[Recently, I was deploying a new feature to a WSS 3.0 site and needed to activate the feature on roughly 100 subsites. I did not want to do this manually with the web interface. I knew that I could write a C# program to do this, but I&#8217;d read a lot about the capabilities of [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I was deploying a new feature to a WSS 3.0 site and needed to activate the feature on roughly 100 subsites. I did not want to do this manually with the web interface. I knew that I could write a C# program to do this, but I&#8217;d read a lot about the capabilities of PowerShell and decided to see how this could be done with PowerShell.<br />
<span id="more-338"></span><br />
After downloading and installing PowerShell 1.0 on my Windows 2003 test server, I spent some time getting familiar with PowerShell and reading what others had done. I found a very helpful site to be <a href="http://sharepoint.microsoft.com/blogs/zach" onclick="pageTracker._trackPageview('/outgoing/sharepoint.microsoft.com/blogs/zach?referer=');">Zach Rosenfield&#8217;s blog</a> and the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.aspx" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/en-us/library/microsoft.sharepoint.aspx?referer=');">Microsoft.SharePoint class reference on msdn</a>. Based on my experience building custom workflows for sharepoint, I knew that if could obtain the list of website urls for a sharepoint site, then I could then call the STSADM program to activate the feature by name for the site by URL</p>
<ul> stsadm -o activatefeature -name <em>feature-name</em> -url <em>websiteurl</em> -force</ul>
<p>The synopsis of the <a href="#fullcode">code</a> is:</p>
<ul>
<li>Start with the sharepoint site object.</li>
<li>Loop through all of the sub-sites.
<ul>
<li>Get the website url for the sub-site.</li>
<li>Call stsadm to activate the feature for the sub-site.</li>
</ul>
</li>
</ul>
<p><a id="fullcode" name="fullcode"></a><br />
<strong>The PowerShell code</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p338code18'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p33818"><td class="code" id="p338code18"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">## Reference to SharePoint DLL</span>
<span style="color: #000000;">&#91;</span>void<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">System.Reflection.Assembly</span><span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.SharePoint&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #008000;">## Probable location of sharepoint STSADM utility program</span>
<span style="color: #800080;">$stsadm</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;$env:programfiles\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\STSADM.EXE&quot;</span> 
&nbsp;
<span style="color: #008000;">############################################</span>
<span style="color: #008000;"># Activate-feature-onSite [-feature  |-url  ]</span>
<span style="color: #008000;">############################################</span>
<span style="color: #0000FF;">function</span> global:Activate<span style="color: pink;">-</span>feature<span style="color: pink;">-</span>onSite<span style="color: #000000;">&#40;</span><span style="color: #800080;">$feature</span><span style="color: pink;">,</span> <span style="color: #800080;">$url</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$spsite</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">new-object</span> Microsoft.SharePoint.SPSite<span style="color: #000000;">&#40;</span><span style="color: #800080;">$url</span><span style="color: #000000;">&#41;</span>; 
&nbsp;
<span style="color: #0000FF;">for</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$i</span><span style="color: pink;">=</span><span style="color: #804000;">0</span>; <span style="color: #800080;">$i</span> <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$spsite</span>.AllWebs.Count;$i<span style="color: pink;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
   <span style="color: #800080;">$websiteurl</span><span style="color: pink;">=</span>  <span style="color: #800080;">$spsite</span>.AllWebs<span style="color: #000000;">&#91;</span><span style="color: #800080;">$i</span><span style="color: #000000;">&#93;</span>.url;
   <span style="color: #800080;">$sResult</span> <span style="color: pink;">=</span> <span style="color: pink;">&amp;</span>stsadm <span style="color: pink;">-</span>o activatefeature <span style="color: #008080; font-style: italic;">-name</span> <span style="color: #800080;">$feature</span> <span style="color: pink;">-</span>url <span style="color: #800080;">$websiteurl</span> <span style="color: #008080; font-style: italic;">-force</span>
   <span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: pink;">!</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$sResult</span> <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*Operation completed successfully*&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
      <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> <span style="color: #800000;">&quot;red&quot;</span> <span style="color: #008080; font-style: italic;">-BackgroundColor</span> <span style="color: #800000;">&quot;white&quot;</span> <span style="color: #800000;">&quot;Activate of feature '$feature' for '$websiteurl' Failed! <span style="color: #008080; font-weight: bold;">`n</span> $sResult&quot;</span>
     <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$spsite</span>.Dispose<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span> 
&nbsp;
<span style="color: #008000;"># to call</span>
Activate<span style="color: pink;">-</span>feature<span style="color: pink;">-</span>onSite <span style="color: #800000;">&quot;feature&quot;</span> <span style="color: #800000;">&quot;http://site&quot;</span></pre></td></tr></table></div>

<p><center><script type="text/javascript"><!--
google_ad_client = "pub-5633552336244805";
google_ad_slot = "5649858591";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</center></p>
]]></content:encoded>
			<wfw:commentRss>http://bable.cybermarshall.com/2009/01/17/using-powershell-to-activate-a-feature-across-all-sharepoint-2007wss-30-sites-and-subsites/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Customizing and enhancing the security of a WSS 3.0/SharePoint 2007 site</title>
		<link>http://bable.cybermarshall.com/2009/01/08/customizing-and-enhancing-the-security-of-a-wss-30sharepoint-2007-site/</link>
		<comments>http://bable.cybermarshall.com/2009/01/08/customizing-and-enhancing-the-security-of-a-wss-30sharepoint-2007-site/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 04:00:14 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[WSS]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[conditional]]></category>
		<category><![CDATA[rendering]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[WSS 3.0]]></category>

		<guid isPermaLink="false">http://bable.cybermarshall.com/?p=272</guid>
		<description><![CDATA[I wanted to compare the capabilities of WSS 3.0 (Sharepoint 2007) to host forum-like discussions, blogs and wiki&#8217;s. After I&#8217;d developed my site, there were items that were visible to anonymous and standard users that I felt were inappropriate. I wanted information to be visible or not based upon the users role. Such as the [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to compare the capabilities of WSS 3.0 (Sharepoint 2007) to host forum-like discussions, blogs and wiki&#8217;s. After I&#8217;d developed my site, there were items that were visible to anonymous and standard users that I felt were inappropriate. I wanted information to be visible or not based upon the users role. Such as the ability to view lists of People and Groups.  I&#8217;ve worked in several businesses where exposing customer names to all users is a violation of customer agreements. IMHO, this is a serious oversight in Microsoft&#8217;s implementation.<br />
<span id="more-272"></span><br />
After I did a good bit of research, experimentation and learning I was able to change the security using the SPSecurityTrimmedControl. Here is how I restricted access to some portions on my Sharepoint Site.</p>
<p>WSS 3.0 provides a control <a href="#spstrim">SPSecurityTrimmedControl</a> that allows the conditional rendering of content based on a users permission. Using this control, I was able to restrict who would be shown People and Groups on my site.  To do this I modified the <a href="#people">people.aspx</a> and the <a href="#groups">groups.aspx</a> files for my site.</p>
<p><em>A word of caution: I have no doubt that when applying a future service pack, Microsoft will overwrite my changes. Therefore I&#8217;m managing my changes externally from the Microsoft SharePoint directory. This will allow me to difference new code from Microsoft and reapply my changes.</em></p>
<p><a id="people" name="people"></a><br />
<strong>people.aspx</strong><br />
The file people.aspx resides in the <span style="text-decoration: underline;"><em>\Program Files\Common Files\Microsoft Shared\web server  extensions\12\TEMPLATE\LAYOUTS</em></span> folder. It lists the persons in the site. After I made a backup copy, I opened the file in a text editor and located the start of the &#8220;PlaceHolderMain&#8221; asp:Content section and added the start of my permission change</p>
<p>before</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p272code24'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27224"><td class="code" id="p272code24"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;asp:Content</span> <span style="color: #000066;">contentplaceholderid</span>=<span style="color: #ff0000;">&quot;PlaceHolderMain&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;asp:PlaceHolder</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;PanelAllPeople&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;ms-listdescription&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></td></tr></table></div>

<p>after</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p272code25'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27225"><td class="code" id="p272code25"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;asp:Content</span> <span style="color: #000066;">contentplaceholderid</span>=<span style="color: #ff0000;">&quot;PlaceHolderMain&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SharePoint:SPSecurityTrimmedControl</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span> <span style="color: #000066;">PermissionsString</span>=<span style="color: #ff0000;">&quot;ManagePermissions&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;asp:PlaceHolder</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;PanelAllPeople&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;ms-listdescription&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></td></tr></table></div>

<p>I located the end of the &#8220;PlaceHolderMain&#8221; asp:Content section and completed my permission change.</p>
<p>before</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p272code26'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27226"><td class="code" id="p272code26"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;asp:HyperLink</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;LnkCallTo&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;&lt;%$SPHtmlEncodedResources:wss,people_callbuttontext%&gt;</span></span>&quot;
		style=&quot;visibility:hidden;display:none&quot;
		NavigateUrl=&quot;callto:&quot; /&gt;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/asp:Content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>after</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p272code27'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27227"><td class="code" id="p272code27"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;asp:HyperLink</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;LnkCallTo&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;&lt;%$SPHtmlEncodedResources:wss,people_callbuttontext%&gt;</span></span>&quot;
		style=&quot;visibility:hidden;display:none&quot;
		NavigateUrl=&quot;callto:&quot; /&gt;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SharePoint:SPSecurityTrimmedControl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/asp:Content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>I also located the modifed the &#8220;PlaceHolderLeftNavBar&#8221; asp:Content and made the similar changes as above to require the user to have ManagePermissions as well.</p>
<p><a id="groups" name="groups"></a><br />
<strong>groups.aspx</strong><br />
The file group.aspx resides in the<span style="text-decoration: underline;"><em> \Program Files\Common Files\Microsoft Shared\web server  extensions\12\TEMPLATE\LAYOUTS</em></span> folder. It lists the groups in the site.  After I made a backup copy, I opened the file in a text editor and made the same &#8220;PlaceHolderMain&#8221; asp:Content section changes as I had to <a href="#people">people.aspx</a>.</p>
<p><a id="spstrim" name="spstrim"></a><br />
<strong>Overview of SPSecurityTrimmedControl</strong></p>
<p>The SPSecurityTrimmedControl conditionally renders the included contents only when the current user has the permissions defined by the PemissionsString.<br />
An example requiring the user to have &#8220;ManagePermissions&#8221;:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p272code28'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27228"><td class="code" id="p272code28"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Sharepoint:SPSecurityTrimmedControl</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span> <span style="color: #000066;">PermissionsString</span>=<span style="color: #ff0000;">&quot;ManagePermissions&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">...</span>
<span style="color: #808080; font-style: italic;">... code being managed ...</span>
<span style="color: #808080; font-style: italic;">...</span>
<span style="color: #808080; font-style: italic;">--&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SharePoint:SPSecurityTrimmedControl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Here are some of the values for the PermissionsString</p>
<table border="0">
<tbody>
<tr>
<td><em><strong>Permissions String</strong></em></td>
<td><em><strong>Description</strong></em></td>
</tr>
<tr>
<td>AddAndCustomizePages</td>
<td>Add, change, or delete HTML pages or Web Part Pages, and edit the Web site using a Windows SharePoint Services–compatible editor.</td>
</tr>
<tr>
<td>AddDelPrivateWebParts</td>
<td>Add or remove personal Web Parts on a Web Part Page.</td>
</tr>
<tr>
<td>AddListItems</td>
<td>Add items to lists, add documents to document libraries, and add Web discussion comments.</td>
</tr>
<tr>
<td>ApproveItems</td>
<td>Approve a minor version of a list item or document.</td>
</tr>
<tr>
<td>BrowseDirectories</td>
<td>Enumerate files and folders in a Web site using Microsoft Office SharePoint Designer 2007 and WebDAV interfaces.</td>
</tr>
<tr>
<td>BrowseUserInfo</td>
<td>View information about users of the Web site.</td>
</tr>
<tr>
<td>CancelCheckout</td>
<td>Discard or check in a document which is checked out to another user.</td>
</tr>
<tr>
<td>CreateAlerts</td>
<td>Create e-mail alerts.</td>
</tr>
<tr>
<td>CreateGroups</td>
<td>Create a group of users that can be used anywhere within the site collection.</td>
</tr>
<tr>
<td>DeleteListItems</td>
<td>Delete items from a list, documents from a document library, and Web discussion comments in documents.</td>
</tr>
<tr>
<td>DeleteVersions</td>
<td>Delete past versions of a list item or document.</td>
</tr>
<tr>
<td>EditListItems</td>
<td>Edit items in lists, edit documents in document libraries, edit Web discussion comments in documents, and customize Web Part Pages in document libraries.</td>
</tr>
<tr>
<td>EditMyUserInfo</td>
<td>Allows a user to change his or her user information, such as adding a picture.</td>
</tr>
<tr>
<td>EnumeratePermissions</td>
<td>Enumerate permissions on the Web site, list, folder, document, or list item.</td>
</tr>
<tr>
<td>ManageAlerts</td>
<td>Manage alerts for all users of the Web site.</td>
</tr>
<tr>
<td>ManageLists</td>
<td>Create and delete lists, add or remove columns in a list, and add or remove public views of a list.</td>
</tr>
<tr>
<td>ManagePermissions</td>
<td>Create and change permission levels on the Web site and assign permissions to users and groups.</td>
</tr>
<tr>
<td>ManagePersonalViews</td>
<td>Create, change, and delete personal views of lists.</td>
</tr>
<tr>
<td>Open</td>
<td>Allow users to open a Web site, list, or folder to access items inside that container.</td>
</tr>
<tr>
<td>OpenItems</td>
<td>View the source of documents with server-side file handlers.</td>
</tr>
<tr>
<td>UpdatePersonalWebParts</td>
<td>Update Web Parts to display personalized information.</td>
</tr>
<tr>
<td>ViewFormPages</td>
<td>View forms, views, and application pages, and enumerate lists.</td>
</tr>
<tr>
<td>ViewListItems</td>
<td>View items in lists, documents in document libraries, and view Web discussion comments.</td>
</tr>
<tr>
<td>ViewPages</td>
<td>View pages in a Web site.</td>
</tr>
<tr>
<td>ViewUsageData</td>
<td>View reports on Web site usage.</td>
</tr>
<tr>
<td>ViewVersions</td>
<td>View past versions of a list item or document.</td>
</tr>
</tbody>
</table>
<p>The full list is on <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx?referer=');">msdn</a>.</p>
<p><center><script type="text/javascript"><!--
google_ad_client = "pub-5633552336244805";
google_ad_slot = "5649858591";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</center></p>
]]></content:encoded>
			<wfw:commentRss>http://bable.cybermarshall.com/2009/01/08/customizing-and-enhancing-the-security-of-a-wss-30sharepoint-2007-site/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
