Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8955225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:30:08+00:00 2026-06-15T14:30:08+00:00

I have an asp.net website that writes some data to a TXT file using

  • 0

I have an asp.net website that writes some data to a TXT file using a relative path. It does so with this command:

string currentDirectory = "./";
string individualDeviceTxt = "myfile.txt";    

System.IO.StreamWriter fileW3 = new System.IO.StreamWriter(currentDirectory + individualDeviceTxt);

The file writes successfully to the following path:

C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0

however, later on, when I try to transmit this file to the user, the relative directory ./ is pointed at a different path. Here is the code:

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.AddHeader("Content-Disposition", "attachment; filename=" + currentDirectory + individualDeviceTxt + ";");
response.TransmitFile(currentDirectory + individualDeviceTxt);
response.End();

it is trying to send the file FROM ‘C:\Users\user\documents\visual studio 2010\Projects\myproject\myfile.txt which is not correct (it doesn’t exist there.)

So it’s apparent that “./” is pointed to a different folder for my second code snippet, but I want to be pointed to the same “./” used in the first snippet. What do I need to do to make this happen? I want to continue using ./ as the directory for myfile.txt in both spots.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:30:10+00:00Added an answer on June 15, 2026 at 2:30 pm

    Getting a path can be tricky in asp.net.

    Here are four different ways to get your current path most only two provide the same results. Put this below in server side code. I like using the AppDomain it seems the most reliable in finding where your .aspx pages are located.

    string paths = " Runtime Path "  + System.Reflection.Assembly.GetExecutingAssembly().Location + "<br>" +
                " Using Root " + new DirectoryInfo("./").FullName + "<br>" +
                " Appdomain " + Path.GetDirectoryName(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile) + "<br>" +
                " Environment " + System.Environment.CurrentDirectory;
    

    The results I got were. Hope this helps.

    Runtime Path C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e333f875\41caca57\assembly\dl3\9d915b4e\ee11a5b0_20d4cd01\MvcTutorial.DLL

    Using Root C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\

    Appdomain C:\Users\Robert\documents\visual studio 2010\Projects\MvcTutorial\MvcTutorial

    Environment C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have a page in an ASP.NET (website) project that writes a file
So I have this ASP.Net 2.0 website that uses functions contained within a JS
I have an Asp.Net 4.0 website/control interface that uses an update panel and some
We have a data driven ASP.NET website which has been written using the standard
I have a website in asp.net 2.0 which write some thing on a file.
I have an ASP.NET website and a seperate C# application. The application writes data
I have an ASP.NET website that is contacting a webservice. Everything works fine connecting
I have an ASP.NET MVC website that works in tandem with a Windows Service
I have an asp.net mvc website that returns a JSON result to certain pages
I have an ASP.NET MVC 3 website that works perfectly in IIS7 integrated mode.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.