<?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; PDF</title>
	<atom:link href="http://bable.cybermarshall.com/tag/pdf/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>OCR&#8217;ing all of the PDF files in a SharePoint Document Library using PowerShell and Solid PDF Tools</title>
		<link>http://bable.cybermarshall.com/2009/05/27/ocring-all-of-the-pdf-files-in-a-sharepoint-document-library-using-powershell-and-solid-pdf-tools/</link>
		<comments>http://bable.cybermarshall.com/2009/05/27/ocring-all-of-the-pdf-files-in-a-sharepoint-document-library-using-powershell-and-solid-pdf-tools/#comments</comments>
		<pubDate>Thu, 28 May 2009 03:39:33 +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[OCR]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[PowerGUI]]></category>
		<category><![CDATA[searchable PDF]]></category>

		<guid isPermaLink="false">http://bable.cybermarshall.com/?p=572</guid>
		<description><![CDATA[A recent review of the PDF Documents in our Document Control Library, revealed that most were &#8220;image only&#8221; PDF&#8217;s. We&#8217;ve run our document control system on different versions of SharePoint technologies since SharePoint Portal Server 2001. We are currently running SharePoint 2007. I&#8217;m surprised that someone did not previously notice that most of our PDF [...]]]></description>
			<content:encoded><![CDATA[<p>A recent review of the PDF Documents in our Document Control Library, revealed that most were &#8220;image only&#8221; PDF&#8217;s. We&#8217;ve run our document control system on different versions of SharePoint technologies since SharePoint Portal Server 2001. We are currently running SharePoint 2007. I&#8217;m surprised that someone did not previously notice that most of our PDF files were not showing up in the searches.</p>
<p>The question is:<em>&#8220;How can we get all of these PDFs reprocessed to be searchable for a reasonable cost?&#8221;</em><span id="more-572"></span> I spent some time reviewing various PDF tools and was surprised that few were &#8220;truly&#8221; scriptable in batch. Some tools would not run on a server or could not interface with a &#8220;HTTP Network Place&#8221;. There were some development kits that were marketed and priced for you to build your own PDF tools and they have a pretty spendy price tag.  These were out of scope with this year&#8217;s budget. Some, like Acrobat, had a batching mechanism in their GUI. However, this would require us to:</p>
<ul>
<li>Manually checkout all of the PDF&#8217;s</li>
<li>Download them into a folder structure</li>
<li>Batch them in the UI</li>
<li>Upload all of the OCR&#8217;ed PDFs</li>
<li>Manually check-in all of the PDF&#8217;s</li>
</ul>
<p>I don&#8217;t think so! We are talking about tens of thousands of documents. This would be labor intensive and prone to human error.</p>
<p>I&#8217;d just about given up finding something that would fit into the current budget, when I received an email notice about Solid Converter PDF V5 being available. While reviewing the v5 features, I noticed Solid PDF Tools v5 was out and it was just $20 more the upgrade to Solid Converter PDF v5. Low and behold, Solid PDF Tools v5 claims that it has a scriptable interface. I got to looking further and discovered their script reference manual and <a href="http://developer.soliddocuments.com/" onclick="pageTracker._trackPageview('/outgoing/developer.soliddocuments.com/?referer=');">developer blog</a>. I downloaded the trial and verified it. The software worked, I sent them my $59 upgrade fee and viola, I had a &#8220;<em>scriptable enough&#8221;</em> tool that I could re-scan &#8220;image-only&#8221; pdf files to create &#8220;searchable&#8221; pdf files. <em>I say &#8220;scriptable enough&#8221; because it gets the job done, but Solid PDF Tools v5 needs to load the GUI, load the splash screen, and display the UI for each file processed. This seems to add 10-15 seconds to the processing time of each file</em></p>
<p>Now to convert the &#8220;image-only&#8221; PDF&#8217;s in SharePoint. Once again, I decided to try PowerShell rather than write a C# program to interface with SharePoint. At the same time, I decided to give the <a href="http://www.powergui.org/downloads.jspa" onclick="pageTracker._trackPageview('/outgoing/www.powergui.org/downloads.jspa?referer=');">PowerGUI Tools</a> a try. I found the PowerGUI Script Editor to be quite useful for developing, debugging and running my script.</p>
<p>The &#8220;proof-of-concept&#8221; result is ~100 lines of PowerShell code that</p>
<ul>
<li>processes all of the webs in a sharepoint site</li>
<li>processes all of the folders and sub-folders</li>
<li>processes all of the PDF documents and sends them to OCR processing</li>
</ul>

<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('p572code2'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5722"><td class="code" id="p572code2"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">## References</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: #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;System.IO&quot;</span><span style="color: #000000;">&#41;</span> 
&nbsp;
<span style="color: #800080;">$SolidPDFTools</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;$env:SolidPDFTools.exe&quot;</span> 
<span style="color: #800080;">$LocalFileFolder</span><span style="color: pink;">=</span> <span style="color: #800000;">&quot;D:\spwork\input&quot;</span>;
<span style="color: #800080;">$OCRWorkFolder</span><span style="color: pink;">=</span> <span style="color: #800000;">&quot;D:\spwork\output&quot;</span>;
<span style="color: #800080;">$OCRWorkLogFolder</span><span style="color: pink;">=</span> <span style="color: #800000;">&quot;D:\spwork\logs&quot;</span>;
<span style="color: #800080;">$OCRScriptFile</span><span style="color: pink;">=</span> <span style="color: #800000;">&quot;D:\spwork\ocr.sdscript&quot;</span>;
&nbsp;
<span style="color: #0000FF;">function</span> script:write_local_file<span style="color: #000000;">&#40;</span><span style="color: #800080;">$file</span><span style="color: pink;">,</span> <span style="color: #800080;">$fileFolder</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$fs</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.IO.FileStream<span style="color: #000000;">&#40;</span>$<span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Join-Path</span> <span style="color: #800080;">$fileFolder</span> <span style="color: #800080;">$file</span>.Name<span style="color: #000000;">&#41;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span>System.IO.FileMode<span style="color: #000000;">&#93;</span>::Create<span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$bw</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.IO.BinaryWriter<span style="color: #000000;">&#40;</span><span style="color: #800080;">$fs</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">Byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$binfile</span> <span style="color: pink;">=</span> <span style="color: #800080;">$file</span>.OpenBinary<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;    
	<span style="color: #800080;">$bw</span>.<span style="color: #008080; font-weight: bold;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$binfile</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$bw</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$fs</span>.close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">function</span> script:ocr_local_file<span style="color: #000000;">&#40;</span><span style="color: #800080;">$file</span><span style="color: pink;">,</span> <span style="color: #800080;">$in_fpath</span><span style="color: pink;">,</span> <span style="color: #800080;">$out_fpath</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$infile</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Join-Path</span> <span style="color: #800080;">$in_fpath</span> <span style="color: #800080;">$file</span>.Name;
	<span style="color: #800080;">$infile</span> <span style="color: pink;">=</span> <span style="color: #800080;">$infile</span> <span style="color: #FF0000;">-replace</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;\\&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;\\&quot;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$outfile</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Join-Path</span> <span style="color: #800080;">$out_fpath</span> <span style="color: #800080;">$file</span>.Name;
	<span style="color: #800080;">$outfile</span> <span style="color: pink;">=</span> <span style="color: #800080;">$outfile</span> <span style="color: #FF0000;">-replace</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;\\&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;\\&quot;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #800080;">$logfile</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Join-Path</span> <span style="color: #800080;">$OCRWorkLogFolder</span> <span style="color: #800000;">&quot;debug.log&quot;</span>;
	<span style="color: #800080;">$logfile</span> <span style="color: pink;">=</span> <span style="color: #800080;">$logfile</span> <span style="color: #FF0000;">-replace</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;\\&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;\\&quot;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$DBG</span><span style="color: pink;">=</span><span style="color: #800000;">'&lt;&lt;/Level/Verbose /Emit (starting) /FileName ('</span> <span style="color: pink;">+</span>  <span style="color: #800080;">$logfile</span> <span style="color: pink;">+</span><span style="color: #800000;">') &gt;&gt; Trace'</span>;
	<span style="color: #800080;">$INP</span><span style="color: pink;">=</span><span style="color: #800000;">'&lt;&lt;/Input ('</span> <span style="color: pink;">+</span> <span style="color: #800080;">$infile</span> <span style="color: pink;">+</span> <span style="color: #800000;">')'</span>;
	<span style="color: #800080;">$OTP</span><span style="color: pink;">=</span><span style="color: #800000;">'/Output ('</span> <span style="color: pink;">+</span> <span style="color: #800080;">$outfile</span> <span style="color: pink;">+</span> <span style="color: #800000;">')'</span>;
	<span style="color: #800080;">$OCR</span><span style="color: pink;">=</span><span style="color: #800000;">'/OCR/Searchable'</span>;
	<span style="color: #800080;">$CRE</span><span style="color: pink;">=</span><span style="color: #800000;">'&gt;&gt; Create'</span>;
	<span style="color: #800080;">$XIT</span><span style="color: pink;">=</span><span style="color: #800000;">'EXIT'</span>;
	<span style="color: #008080; font-weight: bold;">Write-output</span> <span style="color: #800080;">$DBG</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #800080;">$OCRScriptFile</span> <span style="color: #008080; font-style: italic;">-encoding</span> ascii;
	<span style="color: #008080; font-weight: bold;">Write-output</span> <span style="color: #800080;">$INP</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #800080;">$OCRScriptFile</span> <span style="color: #008080; font-style: italic;">-append</span> <span style="color: #008080; font-style: italic;">-encoding</span> ascii;
	<span style="color: #008080; font-weight: bold;">Write-output</span> <span style="color: #800080;">$OTP</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #800080;">$OCRScriptFile</span> <span style="color: #008080; font-style: italic;">-append</span> <span style="color: #008080; font-style: italic;">-encoding</span> ascii;
	<span style="color: #008080; font-weight: bold;">Write-output</span> <span style="color: #800080;">$OCR</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #800080;">$OCRScriptFile</span> <span style="color: #008080; font-style: italic;">-append</span> <span style="color: #008080; font-style: italic;">-encoding</span> ascii;
	<span style="color: #008080; font-weight: bold;">Write-output</span> <span style="color: #800080;">$CRE</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #800080;">$OCRScriptFile</span> <span style="color: #008080; font-style: italic;">-append</span> <span style="color: #008080; font-style: italic;">-encoding</span> ascii;
	<span style="color: #008080; font-weight: bold;">Write-output</span> <span style="color: #800080;">$XIT</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #800080;">$OCRScriptFile</span> <span style="color: #008080; font-style: italic;">-append</span> <span style="color: #008080; font-style: italic;">-encoding</span> ascii;  
&nbsp;
	<span style="color: #800080;">$sTemp</span> <span style="color: pink;">=</span> <span style="color: pink;">&amp;</span>SolidPDFTools <span style="color: pink;">/</span>i <span style="color: #800080;">$OCRScriptFile</span> <span style="color: pink;">/</span>f script 
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$sTemp</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">function</span> script:upload_ocr_result<span style="color: #000000;">&#40;</span><span style="color: #800080;">$file</span><span style="color: pink;">,</span> <span style="color: #800080;">$ocr_fpath</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$ocrfile</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Join-Path</span> <span style="color: #800080;">$ocr_fpath</span> <span style="color: #800080;">$file</span>.Name;
	<span style="color: #800080;">$fs</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.IO.FileStream<span style="color: #000000;">&#40;</span>$<span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Join-Path</span> <span style="color: #800080;">$ocr_fpath</span> <span style="color: #800080;">$file</span>.Name<span style="color: #000000;">&#41;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span>System.IO.FileMode<span style="color: #000000;">&#93;</span>::Open<span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$br</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.IO.BinaryReader<span style="color: #000000;">&#40;</span><span style="color: #800080;">$fs</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">Byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$binfile</span> <span style="color: pink;">=</span> <span style="color: #800080;">$br</span>.ReadBytes<span style="color: #000000;">&#40;</span><span style="color: #800080;">$br</span>.BaseStream.Length<span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$file</span>.SaveBinary<span style="color: #000000;">&#40;</span><span style="color: #800080;">$binfile</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$br</span>.close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$fs</span>.close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
 <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">function</span> script:process_a_folder<span style="color: #000000;">&#40;</span><span style="color: #800080;">$folder</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$files</span> <span style="color: pink;">=</span> <span style="color: #800080;">$folder</span>.Files;
	<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$file</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$files</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$file</span>.Name.ToLower<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.Contains<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;.pdf&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$file</span>.CheckOutStatus <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;None&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #800080;">$file</span>.CheckOut<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            			write_local_file <span style="color: #800080;">$file</span> <span style="color: #800080;">$LocalFileFolder</span>;
				ocr_local_file <span style="color: #800080;">$file</span> <span style="color: #800080;">$LocalFileFolder</span> <span style="color: #800080;">$OCRWorkFolder</span>;
				upload_ocr_result <span style="color: #800080;">$file</span> <span style="color: #800080;">$OCRWorkFolder</span>; 
				<span style="color: #800080;">$file</span>.CheckIn<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;version has had OCR processing performed&quot;</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #800080;">$file</span>.Update<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #800080;">$sub_folders</span> <span style="color: pink;">=</span> <span style="color: #800080;">$folder</span>.SubFolders;
	process_folders<span style="color: #000000;">&#40;</span><span style="color: #800080;">$sub_folders</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">function</span> script:process_folders<span style="color: #000000;">&#40;</span><span style="color: #800080;">$folders</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$folder</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$folders</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		process_a_folder<span style="color: #000000;">&#40;</span><span style="color: #800080;">$folder</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">function</span> script:append<span style="color: pink;">-</span>path <span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$oldPath</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">get-content</span> Env:\Path;
	<span style="color: #800080;">$newPath</span> <span style="color: pink;">=</span> <span style="color: #800080;">$oldPath</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;;&quot;</span> <span style="color: pink;">+</span> <a href="about:blank"><span style="color: #000080;">$args</span></a>;
	<span style="color: #008080; font-weight: bold;">set-content</span> Env:\Path <span style="color: #800080;">$newPath</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># MAIN</span>
append<span style="color: pink;">-</span>path <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">resolve-path</span> <span style="color: #800000;">'D:\Program Files\SolidDocuments\Solid PDF Tools\SPDFT'</span><span style="color: #000000;">&#41;</span>.Path
&nbsp;
<span style="color: #800080;">$site</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: #800000;">&quot;http://my-sp-server&quot;</span><span style="color: #000000;">&#41;</span>;   
<span style="color: #800080;">$siteweb</span> <span style="color: pink;">=</span> <span style="color: #800080;">$site</span>.OpenWeb<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;   
<span style="color: #800080;">$webs</span> <span style="color: pink;">=</span> <span style="color: #800080;">$siteweb</span>.Webs;   
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$web</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$webs</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>   
	<span style="color: #800080;">$folders</span> <span style="color: pink;">=</span> <span style="color: #800080;">$web</span>.Folders;
	process_folders<span style="color: #000000;">&#40;</span><span style="color: #800080;">$folders</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>I do plan to add some logging, change the hard-coded variables, and look at using streams instead of Byte[] to be more flexible and scaleable. I&#8217;ll need some error handling to deal with things like download or upload failures before I can run this in production. I&#8217;m also trying to determine if a PDF is &#8220;image only&#8221; or searchable. However, the &#8220;Proof-of-concept&#8221; does work.</p>
]]></content:encoded>
			<wfw:commentRss>http://bable.cybermarshall.com/2009/05/27/ocring-all-of-the-pdf-files-in-a-sharepoint-document-library-using-powershell-and-solid-pdf-tools/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<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('p483code11'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48311"><td class="code" id="p483code11"><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('p483code12'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48312"><td class="code" id="p483code12"><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('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;">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('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;">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('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> <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('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;">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('p483code17'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48317"><td class="code" id="p483code17"><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('p483code18'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48318"><td class="code" id="p483code18"><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>Making OCR&#8217;ed PDF&#8217;s using the HP Digital Sending Software</title>
		<link>http://bable.cybermarshall.com/2009/05/08/making-ocred-pdfs-using-the-hp-digital-sending-software/</link>
		<comments>http://bable.cybermarshall.com/2009/05/08/making-ocred-pdfs-using-the-hp-digital-sending-software/#comments</comments>
		<pubDate>Fri, 08 May 2009 22:18:18 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[OCR]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[searchable PDF]]></category>

		<guid isPermaLink="false">http://bable.cybermarshall.com/?p=396</guid>
		<description><![CDATA[We recently became aware that our fancy HP workgroup printers which can copy a document and email the result as pdf to a set of email addresses only creates image pdf&#8217;s. None of the text in the pdf is searchable. After some investigation, we discovered that we needed to install the HP Digital Sending Software [...]]]></description>
			<content:encoded><![CDATA[<p>We recently became aware that our fancy HP workgroup printers which can copy a document and email the result as pdf to a set of email addresses only creates image pdf&#8217;s. None of the text in the pdf is searchable. After some investigation, we discovered that we needed to install the HP Digital Sending Software and let it perform OCR post-processing on the image pdf that was created by the printer.</p>
<p><span id="more-396"></span></p>
<p>This works all well and good, except that  the HP Digital Sending Software places the OCR&#8217;ed file in a single configurable folder on the Print Server&#8217;s local disk . You might be wondering:  &#8220;<em>What&#8217;s the problem with that? Just share the folder to all users and be done with it</em>.&#8221; Well, my answer is:  &#8220;<em>Not so fast. Much of the material being scanned is confidential and should not be placed where an unauthorized user might be able to access it</em>.&#8221;</p>
<p>After further analysis of how the HP Digital Sending Software works, we determined that for every document scanned there are 2 files being created. One is the OCR&#8217;ed pdf file and the other is an informational xml file. The xml file contains the information that the user provided during the scan.  This gave us access to  the &#8220;from email address&#8221;,  &#8220;to email address(es)&#8221;,  and the OCR&#8217;ed pdf file name.</p>
<p>With this information, it was pretty straight forward to write a  FileWatcher service in  C# that would:</p>
<ul>
<li> Handle the file changed events events with a filter on &#8220;*.xml&#8221; files.<br />
<em>I initially thought that I would be processing a file created event, but the HP software creates the xml file, then updates it.</em></li>
<li>Generate an email from the &#8220;from email address&#8221; to the &#8220;to email address(es)&#8221; with the OCR&#8217;ed pdf file as an attachment.</li>
<li>Delete the processed xml and pdf files from the folder.</li>
</ul>
<p>It was pretty easy to plug this gap.  However, without our little &#8220;gap filler&#8221; the HP Digital Sending Software is just technology and not a solution for a Company. I wonder why HP doesn&#8217;t provide tools with their Digital Sending Software to perform this function already?</p>
]]></content:encoded>
			<wfw:commentRss>http://bable.cybermarshall.com/2009/05/08/making-ocred-pdfs-using-the-hp-digital-sending-software/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
