<?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>Software Development Bits &#187; FileIO</title>
	<atom:link href="http://www.brunellweb.com/index.php/tag/fileio/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brunellweb.com</link>
	<description>Thoughts, tips, and tricks for .NET development</description>
	<lastBuildDate>Wed, 13 Oct 2010 04:13:42 +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>How to tell if a path is relative or absolute</title>
		<link>http://www.brunellweb.com/index.php/2007/10/16/how-to-tell-if-a-path-is-relative-or-absolute/</link>
		<comments>http://www.brunellweb.com/index.php/2007/10/16/how-to-tell-if-a-path-is-relative-or-absolute/#comments</comments>
		<pubDate>Tue, 16 Oct 2007 19:21:07 +0000</pubDate>
		<dc:creator>Matt Brunell</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[FileIO]]></category>

		<guid isPermaLink="false">http://www.brunellweb.com/?p=5</guid>
		<description><![CDATA[There is no function or method in the .NET framework to find this out directly.  I had though that Path.IsPathRooted(string) would do the job, but it seems that paths can be both relative, and rooted.  The path "C:bin\Debug\app.exe" is perfectly valid.  &#8230; <a href="http://www.brunellweb.com/index.php/2007/10/16/how-to-tell-if-a-path-is-relative-or-absolute/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There is no function or method in the .NET framework to find this out directly.  I had though that <code><a href="http://msdn2.microsoft.com/en-us/library/system.io.path.ispathrooted.aspx" target="_blank">Path.IsPathRooted(string)</a> </code>would do the job, but it seems that paths can be both relative, and rooted.  The path <code>"C:bin\Debug\app.exe" </code>is perfectly valid.  So, the only thing to do is to take the input, create the absolute path, and compare them.  Like this:</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;">void</span> CheckDestination<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> destination<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #008080; font-style: italic;">// Ensure that path is absolute.  Ignore case</span>
   <span style="color: #008080; font-style: italic;">// because filesystem is case-insensitive</span>
   <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Compare</span><span style="color: #000000;">&#40;</span>destination.<span style="color: #0000FF;">Trim</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,
      Path.<span style="color: #0000FF;">GetFullPath</span><span style="color: #000000;">&#40;</span>destination<span style="color: #000000;">&#41;</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// path is absolute</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brunellweb.com/index.php/2007/10/16/how-to-tell-if-a-path-is-relative-or-absolute/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

