Using a relative path to a file in an .ashx page
<p>Double apologies - first, I'm completely new to ASP.net so I'm sure that this is a very naive question, and second, it looks like there's already a hundred questions on SO about relative paths in ASP.NET. Unfortunately - I can't find one that answers my question.</p>

<p>Background - I'm working on an <code>.ashx</code> file that needs to be able to access an Excel file.</p>

<p>When I'm running locally and using an absolute path to the file, everything works great. Here's my code:</p>

<pre><code>&lt;%@ WebHandler Language="C#" Class="MyHandler" %&gt;
using System;
... [a bunch more "usings..."]
using Microsoft.Office.Interop.Excel;

public class MyHandler : IHttpHandler {
    public void ProcessRequest(HttpContext context) {
        string path = @"C:\Users\[...]\myExcelFile.xls";
        Workbook theWorkbook;
        Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
        theWorkbook = app.Workbooks.Open(path);
</code></pre>

<p>However, I want to run this on a server, and use a relative path to the <code>myExcelFile.xls</code>.</p>

<p>My project is set up like this:</p>

<pre><code>Main folder:
 - Default.aspx
 - myExcelFile.xls
 - Web.config
 - Global.asax
Styles folder
Scripts folder
Handler folder
 - MyHandler.ashx (that's reading the Excel File)
bin folder
</code></pre>

<p>So - you can see that the Excel file is in the "root" of the application.</p>

<p>To make the path relative, I've tried the following with no success:</p>

<p>Assuming that "relative" is from myHandler.ashx:</p>

<pre><code>string path = @"..\myExcelFile.xls":
</code></pre>

<p>Assuming that <code>~</code> refers to the "root":</p>

<pre><code>string path = @"~\myExcelFile.xls";
</code></pre>

<p>Just guessing:</p>

<pre><code>string path = @".\myExcelFile.xls";
</code></pre>

<p>Just desperate:</p>

<pre><code>string path = "myExcelFile.xls";
</code></pre>

<p>None of these worked.</p>

<p>So I did a little research here on SO, and found <code>System.IO.Path.GetFullPath</code>. So I tried:</p>

<pre><code>string path = System.IO.Path.GetFullPath("myExcelFile.xls");
</code></pre>

<p>That didn't work, but at least I could see that the value of <code>path</code> was <code>C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\11.0\PinpointTool-DC.xls</code></p>

<p>Of course - I don't understand that at all - that path is nowhere near where my project is (which means I don't understand what <code>System.IO.Path.GetFullPath</code> does...)</p>

<p>Last, I tried <code>Server.MapPath("myExcelFile.xls")</code>, but that doesn't work at all (locally, at least):</p>

<pre><code>Compiler Error Message: CS0103: The name 'Server' does not exist in the current context
</code></pre>

<p>So, how can I get this to work (ideally both locally and on a server?)</p>
