7 Replies - 238 Views - Last Post: 04 December 2018 - 08:01 AM Rate Topic: -----

#1 aspfun   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 103
  • Joined: 16-January 13

Path to a file

Posted 04 December 2018 - 06:43 AM

My project Order is saved in d:\myproject\order\.
I added a new text file error.txt under project Order, script, error.txt.
In code file, how to point at to error.txt?
I tried the code below but no luck.

.\.\script\error.txt

.\script\error.txt
Is This A Good Question/Topic? 0
  • +

Replies To: Path to a file

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14691
  • View blog
  • Posts: 58,718
  • Joined: 12-June 08

Re: Path to a file

Posted 04 December 2018 - 07:47 AM

Console, win form, web form, asp.net page, wpf? What is this?
Was This Post Helpful? 0
  • +
  • -

#3 aspfun   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 103
  • Joined: 16-January 13

Re: Path to a file

Posted 04 December 2018 - 07:49 AM

View Postmodi123_1, on 04 December 2018 - 07:47 AM, said:

Console, win form, web form, asp.net page, wpf? What is this?

Sorry, it is winform
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14691
  • View blog
  • Posts: 58,718
  • Joined: 12-June 08

Re: Path to a file

Posted 04 December 2018 - 07:53 AM

You should look at 'System.Environment.CurrentDirectory' and build from there.

https://docs.microso...framework-4.7.2
Was This Post Helpful? 0
  • +
  • -

#5 TechnoBear   User is online

  • Lady A
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,149
  • Joined: 02-November 11

Re: Path to a file

Posted 04 December 2018 - 07:53 AM

Relative Paths tend to begin from the executable, which will likely be in bin\{Configuration}. However, you are going to want to verify what the path is that it is creating.

Also, .\ means "Current Folder", ..\ means "Current Folder's Parent"

The following will get the full path to the executing assembly:

System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)


As will:

System.Environment.CurrentDirectory


Maybe evaluate the path into a variable and see what path it is giving you, then go from there.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • dependency injected
  • member icon

Reputation: 6668
  • View blog
  • Posts: 27,308
  • Joined: 12-December 12

Re: Path to a file

Posted 04 December 2018 - 07:54 AM

It also depends on what you are attempting to do with the file, which of many methods you are attempting to use.

Please, in future, spend more time on your initial question so that we don't have to keep asking for fairly obvious information (or guess).
Was This Post Helpful? 0
  • +
  • -

#7 TechnoBear   User is online

  • Lady A
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,149
  • Joined: 02-November 11

Re: Path to a file

Posted 04 December 2018 - 07:55 AM

View Postandrewsw, on 04 December 2018 - 08:54 AM, said:

Please, in future, spend more time on your initial question so that we don't have to keep asking for fairly obvious information.


Credit where it's due, it may be super obvious to us though if they are just starting they may not realize the fact there is always more than one way to skin a cat.
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw   User is offline

  • dependency injected
  • member icon

Reputation: 6668
  • View blog
  • Posts: 27,308
  • Joined: 12-December 12

Re: Path to a file

Posted 04 December 2018 - 08:01 AM

My encouragement to spend a little more time on the opening post still stands ;) - the OP has been here for a while.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1