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 7771155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:34:48+00:00 2026-06-01T16:34:48+00:00

This question have been asked earlier in StackOverFlow and answers are also marked in

  • 0

This question have been asked earlier in StackOverFlow and answers are also marked in that post. But sadly the solution provided in
Read a file from an unknown location? does not solve my problem.
I am building a website and need to read data from a text file. The actual location of the file in my pc is: C:\Developments\TestProject\PettyCashSolution\PettyCashWeb\DataFile.txt and I
have tried below solutions from above link with no luck.

string sString = string.Empty;
string sStr = "";
StreamReader oStreamReader;
try
{ 

Try1

sStr = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "DataFile.txt");

This returns below:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\pettycashweb\af7f0870\c5ac294a\DataFile.txt

Try2

sStr = Path.Combine(Application.StartupPath, "DataFile.txt");

This returns below:
Compile Error: The name “Application” does not exist in the current context

Try3

oStreamReader = new StreamReader(File.OpenRead(Directory.GetCurrentDirectory().ToString() + "\\DataFile.txt"));

This returns below:
Exception: Could not find file ‘C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\DataFile.txt’

oStreamReader = new StreamReader(sStr);
sString = oStreamReader.ReadLine();

}
catch (Exception ex)
{
}

Please also advice what should I do so that after publishing the web in server (iis) the read data from text file will work properly. Thanks.

  • 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-01T16:34:49+00:00Added an answer on June 1, 2026 at 4:34 pm

    You can get application path by AppDomain.CurrentDomain.BaseDirectory

    Your code must be like this

    sStr = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFile.txt");

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

Sidebar

Related Questions

I asked this question earlier and I have been reading the answers and searched
I realize that this question has been asked 100times but none that I have
I know that this question have been asked several times. But I can't get
Hi I know this question have been asked before but the answers there isn't
I know that this question might have been asked like 100 times, but, believe
I know that variations on this question have been asked, but I've tried all
I'm aware that variants of this question have been asked before, but I do
I know similar permutations of this question have been asked before, but the answers
I'm aware that this question may have been asked before, but I still haven't
Variants of this question have been asked many times, but none of the answers

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.