title: asp .net browse local or any drive ang getting exact file path
body: <p>I was asked to create a program that a user can browse from his local or any network drive some txt file, parse it per line with delimiter and store it in DB. The problem is my code can not get the exact URL, instead it returns the URL where the solution of the app is installed thus, returning error saying file not found. I have been looking around and I am aware asp .net can not get the exact file path, the best there is file upload. Is there a way that I do not have to save it in the solution folder/server before I can read it?</p>
  
  <p>my code is this:</p>
  
  <pre><code>protected void btnUploadSave_Click(object sender, EventArgs e)
      {
          string path =
                  string.Format(
                      CultureInfo.InvariantCulture,
                      Strings.NewObjectPath,
                      _root,
                      fuUpload.FileName);
          //string x = fuUpload.PostedFile.FileName;
  
          OpenFile(path);
  
  
  
      }
  </code></pre>
  
  <p>it returns the path but not the actual location of the project.
  ex. the actual location is c:\my docs\download\someFile.txt, it returns c:\my docs\vs 2010\Project\myAppSoltn\someFile.txt</p>
  
  <p>If it is not possible to get the exact file loc because of security issues, is there a way I can open the file by just knowing the filename? lcode below does not work but I would liek to get something like that?</p>
  
  <pre><code>private void OpenFile(String path)
      {
          path = @"~\someFile.txt";
  
          // Delete the file if it exists. 
  
          AirDataAccess access = new AirDataAccess();
          using (TextFieldParser parser = new TextFieldParser(path))
          {
              parser.Delimiters = new string[] { "," };
              while (true)
              {
                  string[] words = parser.ReadFields();
                  if (words == null)
                        break;
                  else
                  {
                      AirData airData = null;
                      if (words != null)
                      {
  
                          airData = new AirData();
                          airData.DateAired = Convert.ToDateTime(words[0]);
  
                          if (adBusiness.isValidUniqueCode(airData.UniqueCode))
                              access.InsertAirData(airData);
  
                      }
                  }
  
              }
          }
  
      }
  </code></pre>
  
  <p>here is myp page:</p>
  
  <pre><code>    &lt;asp:View ID="vUpload" runat="server"&gt;
  &lt;asp:Panel ID="pnlUpload" runat="server" DefaultButton="btnUploadSave"&gt;
  &lt;table border="0" cellpadding="5" cellspacing="0"&gt;
  &lt;thead&gt;
  &lt;tr&gt;
      &lt;td class="header"&gt;Upload a File&lt;/td&gt;   
  &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
  &lt;tr&gt;
      &lt;td&gt;
          &lt;asp:RequiredFieldValidator ID="rfvUpload" runat="server" ErrorMessage="A file name is required" ControlToValidate="fuUpload" SetFocusOnError="true"&gt;*&amp;nbsp;&lt;/asp:RequiredFieldValidator&gt;
          &lt;asp:FileUpload ID="fuUpload" runat="server" CssClass="button" Width="400px" /&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;tfoot&gt;
  &lt;tr&gt;
      &lt;td align="right"&gt;
          &lt;asp:Button ID="btnUploadCancel" runat="server" CausesValidation="false" CssClass="button" Text="Cancel" UseSubmitBehavior="false" onclick="Cancel" /&gt;
          &lt;asp:Button ID="btnUploadSave" runat="server" CssClass="button" Text="Upload" onclick="btnUploadSave_Click" /&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tfoot&gt;
  &lt;/table&gt;
  &lt;/asp:Panel&gt;
  &lt;/asp:View&gt;
  </code></pre>