473,379 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to access a text file within VS2008 project folder?

132 100+
Hi there.

I have a folder within my asp.net (c#) project in VS2008 called Files. Within this folder is a text file called files.txt.

Is there a way to access this folder from the C# code please?

What I am looking for is to invoke a StreamReader (or other suitable reader) and read in the contents of this folder, so to populate string values in the code.

An example of the code would look something like:

Expand|Select|Wrap|Line Numbers
  1. StreamReader sr = new StreamReader("~\\files.txt");
  2.  
Where the path is hence pointing at the folder within the project.

The above example does not work but any help will be so apprecaited please?

Thank you.

M :o)
Feb 18 '09 #1
1 3877
tlhintoq
3,525 Expert 2GB
Doesn't this approach mean that your program will be hard coded to only work on your machine, and only so long as you keep the project folder? If it is looking for files inside your project folder, which is inside your documents, under your user name... {fragile} Then the program will fail in the real world.

A better approach might be to obtain the designation of the boot drive (generally C:), then look for a file at {bootdrive}\{application.company}\{application.tit le}\files.txt

This will give you a consistent scheme that automatically updates location based on the properties of this, and the next, application you your right.

C:\\SmithProgramming\\MyFirstProgram\\files.txt
G:\\SmithProgramming\\MySecondProgram\\file.txt
etc.
Feb 19 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
1
by: Jody Gelowitz | last post by:
We are having an issue in that when trying to read a file that is on Server2 from Server1 (through our ASP.NET project), we receive the error: Access to the path "\\Server2\MyShare\MyFile.tif" is...
5
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all...
17
by: rdemyan via AccessMonster.com | last post by:
With A2003, I'm having trouble accessing files in a folder on another computer where back-end files, update files, etc are located. Here's the scenario: 1) Computer #1 - A2003 2) Computer #2 -...
6
by: Bob Alston | last post by:
I am looking for others who have built systems to scan documents, index them and then make them accessible from an Access database. My environment is a nonprofit with about 20-25 case workers who...
2
by: CGatto | last post by:
Hi, We have just started getting the following error during compiles of our forms-based application. We are developing in VS2008, VB.Net, with Team Foundation Server-based source control. ...
3
by: =?Utf-8?B?UGF1bCBIYWxl?= | last post by:
Moving all User Controls to a single directory has solved my problem - Thanks Eliyahu. That said, I still got one Circular ref error yesterday, rebuilt again and the build was fine? Far far...
1
by: Ronald S. Cook | last post by:
When I convert a VS2005 web project to VS2008, there is no "Reference" folder. Also, when pou go to project properties, it doesn't look like the properties page like if you started a new VS2008...
5
by: nspader | last post by:
I have a new project that I am working on. Actually just more advanced within the same project. I have the need to carry a .OTM file along with my program in order to have access email through...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.