Absolute or Relative File Path in web.config
<p>framework: ASP.NET</p>

<p>Say I have my website located in <strong>D:\Webhome</strong>. The structure is like below</p>

<pre><code>D:\Webhome
   |
   |-web.config
   |-default.aspx
   |-folder_1
   |  |- file1
   |
   |-folder_2
</code></pre>

<p>I was wondering is it better to use absolute or relative path in web.config to reference to files. I am using absolute path, but environment in my workstation is different in production server, which has website located in <strong>E:\Web</strong>. So I can just copy web.config on my local to production server. Instead, I just manually copy the difference over. </p>

<p>The other question is how to use relative path. For example:</p>

<pre><code>&lt;entry1 name="key1" file="~/folder1/file1"&gt;
&lt;entry1 name="key1" file="folder1/file1"&gt;
&lt;entry1 name="key1" file="~\folder1\file1"&gt;
&lt;entry1 name="key1" file="folder1\file1"&gt;
</code></pre>

<p>Is there a msdn or document for this? Please advise, thanks.</p>

<p><br/><br/>
<strong>EDIT:</strong><br>
It seems not work for my case. I've checked with HttpContext.Server.MapPath("~/") and it's showing <code>E:\Webhome</code>. And my xml is at <code>E:\Webhome\QueryDictionary\ITEM.xml</code>. Can you please see what's wrong?</p>

<p>This is my web.config</p>

<pre><code>  &lt;queryDictionaries&gt;
    &lt;queryDictionary name="ITEM" file="~/QueryDictionary/ITEM.xml" type="Com.Data.SqlServer"/&gt;
  &lt;/queryDictionaries&gt;
</code></pre>

<p>This is the error I got:</p>

<pre><code>System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\~\QueryDictionary\ITEM.xml'.
  at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
  at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
  at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
  at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
  at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
  at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
  at System.Threading.CompressedStack.runTryCode(Object userData)
  at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
  at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
  at System.Xml.XmlTextReaderImpl.OpenUrl()
  at System.Xml.XmlTextReaderImpl.Read()
  at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
  at System.Xml.XmlDocument.Load(XmlReader reader)
  at System.Xml.XmlDocument.Load(String filename)
  at Com.Data.Query.QueryCommander.LoadDictionaries()
</code></pre>

<p><br/><br/>
<strong>EDIT2:</strong><br>
Looks like in <code>Com.Data.Query.QueryCommander.LoadDictionaries()</code>, I have to use <code>HttpContext.Server.MapPath()</code> to parse the filepath to get the absolute path. Is that the reason?</p>
