3 Replies - 923 Views - Last Post: 20 January 2012 - 10:11 AM Rate Topic: -----

#1 JizzaDaMan  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 139
  • Joined: 23-May 11

get the current file location

Posted 18 January 2012 - 01:42 PM

I am using a streamreader and writer to write to files.
I was wondering if there is a way to get the location of the project so I can run it on any computer.

e.g. so I can put something like: CurrentLocation + "FileName.txt";

thanks for any help

:boat:
Is This A Good Question/Topic? 0
  • +

Replies To: get the current file location

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,355
  • Joined: 02-June 10

Re: get the current file location

Posted 18 January 2012 - 01:49 PM

string appPath = Path.GetDirectoryName(Application.ExecutablePath);


Finding answers to specific problems:
Sometimes just knowing where to look can make all the difference. Google is your friend.
Search with either "C#" or "MSDN" as the first word: "MSDN Picturebox", "C# Custom Events", "MSDN timer" etc.
How to do a good search that will get you targeted answers.
Was This Post Helpful? 2
  • +
  • -

#3 blogwhodle  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 49
  • Joined: 18-January 12

Re: get the current file location

Posted 19 January 2012 - 09:04 PM

View PosttlhIn`toq, on 18 January 2012 - 01:49 PM, said:

string appPath = Path.GetDirectoryName(Application.ExecutablePath);


Finding answers to specific problems:
Sometimes just knowing where to look can make all the difference. Google is your friend.
Search with either "C#" or "MSDN" as the first word: "MSDN Picturebox", "C# Custom Events", "MSDN timer" etc.
How to do a good search that will get you targeted answers.

This is also what I badly needed. :)
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4310
  • View blog
  • Posts: 7,463
  • Joined: 08-June 10

Re: get the current file location

Posted 20 January 2012 - 10:11 AM

For the record, if you do not specify an absolute path, the path will be relative to the application itself. So if you just provided a file name, it'd look for the file in the executable's directory.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1