<?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>Eric Juden &#187; c#</title>
	<atom:link href="http://thejudens.com/eric/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://thejudens.com/eric</link>
	<description>Web Application Developer, Husband and Father</description>
	<lastBuildDate>Wed, 01 Sep 2010 20:11:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>HttpWebRequest and Multiple Files</title>
		<link>http://thejudens.com/eric/2009/06/httpwebrequest-and-multiple-files/</link>
		<comments>http://thejudens.com/eric/2009/06/httpwebrequest-and-multiple-files/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 14:53:56 +0000</pubDate>
		<dc:creator>Eric Juden</dc:creator>
				<category><![CDATA[In the Trenches]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[exists]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[http web request]]></category>
		<category><![CDATA[httpwebrequest]]></category>
		<category><![CDATA[multiple]]></category>
		<category><![CDATA[response]]></category>
		<category><![CDATA[time out]]></category>

		<guid isPermaLink="false">http://thejudens.com/eric/?p=144</guid>
		<description><![CDATA[I&#8217;m working on a project at work right now to pull inventory data from the bookstore&#8217;s point-of-sale system into the e-commerce site I&#8217;m setting up for them. One of the parts in the process is to check the web server for any new/updated images for the items on the website. I am doing a web [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a project at work right now to pull inventory data from the bookstore&#8217;s point-of-sale system into the e-commerce site I&#8217;m setting up for them. One of the parts in the process is to check the web server for any new/updated images for the items on the website. I am doing a web request for each image on the server to see if I really does exist. After doing so many, I noticed that all of the files kept coming back saying they weren&#8217;t there, when I know darn well they are! So after a little research online, I noticed that you need to close your Response object when you are finished with it.</p>
<p>Here&#8217;s my code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">bool</span> _FileExists<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> filename<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">try</span> <span style="color: #000000;">&#123;</span>
        HttpWebRequest req <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>HttpWebRequest<span style="color: #000000;">&#41;</span>WebRequest.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span>filename<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        req.<span style="color: #0000FF;">Timeout</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">5000</span><span style="color: #008000;">;</span>
        req.<span style="color: #0000FF;">Method</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;HEAD&quot;</span><span style="color: #008000;">;</span>
        HttpWebResponse response <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>HttpWebResponse<span style="color: #000000;">&#41;</span>req.<span style="color: #0000FF;">GetResponse</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>response.<span style="color: #0000FF;">StatusCode</span> <span style="color: #008000;">==</span> HttpStatusCode.<span style="color: #0000FF;">OK</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            response.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>    <span style="color: #008080; font-style: italic;">// IMPORTANT</span>
            <span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span> <span style="color: #0600FF;">else</span> <span style="color: #000000;">&#123;</span>
            response.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>    <span style="color: #008080; font-style: italic;">// IMPORTANT</span>
            <span style="color: #0600FF;">return</span> false<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span> <span style="color: #0600FF;">catch</span><span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">return</span> false<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The big thing to note here is when I&#8217;m calling response.Close(), as that closes out the connection. So if you are experiencing issues where you keep getting time out errors, give this a try. Here&#8217;s the <a href="http://www.velocityreviews.com/forums/t112367-httpwebrequest-the-operation-has-timedout.html" target="_blank">original article</a> that helped me.</p>
]]></content:encoded>
			<wfw:commentRss>http://thejudens.com/eric/2009/06/httpwebrequest-and-multiple-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Mobile Event Viewer</title>
		<link>http://thejudens.com/eric/2008/02/windows-mobile-event-viewer/</link>
		<comments>http://thejudens.com/eric/2008/02/windows-mobile-event-viewer/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 13:19:41 +0000</pubDate>
		<dc:creator>Eric Juden</dc:creator>
				<category><![CDATA[In the Trenches]]></category>
		<category><![CDATA[.netcf]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[windowsmobile]]></category>

		<guid isPermaLink="false">http://thejudens.com/eric/?p=141</guid>
		<description><![CDATA[Well, I started in on a new project last night. This project will essentially be an event viewer for windows mobile devices. One of my concerns is that it won’t log events from the device…I’m not exactly sure how to hook in to device events yet. I can’t guarantee that this application will be running [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I started in on a new project last night. This project will essentially be an event viewer for windows mobile devices. One of my concerns is that it won’t log events from the device…I’m not exactly sure how to hook in to device events yet. I can’t guarantee that this application will be running all the time to record device events, so I am thinking mainly of using it for application developers that want to use it to record events from their programs. They will be able to call a<br />
method and pass all the information to create a new event in the event log.</p>
<p>I’ll post something worthwhile when it gets a little farther.</p>
]]></content:encoded>
			<wfw:commentRss>http://thejudens.com/eric/2008/02/windows-mobile-event-viewer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
