What is default directory of File.Open?
Asked Answered
D

5

6

I have this code:

Stream f = File.Open("data.majid", FileMode.OpenOrCreate, FileAccess.ReadWrite);

Where will be file created?

Decani answered 14/4, 2013 at 15:35 Comment(1)
Don't use relative paths unless you are in total control of the working directory. Always safer to use an absolute path. The main exception is console apps where the working directory should be considered an input parameter to the program.Duralumin
H
7

From the File.Open MSDN documentation:

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see GetCurrentDirectory.

Hesychast answered 14/4, 2013 at 15:36 Comment(0)
F
1

Usually the directory where the process was started from. This is the current working directory.

From MSDN

The current directory is distinct from the original directory, which is the one from which the process was started.

Flapper answered 14/4, 2013 at 15:36 Comment(1)
No it is not! Relative paths are resolved relative to the process working directory. End of story.Duralumin
V
1

From MSDN;

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see GetCurrentDirectory.

Check out Directory.GetCurrentDirectory

The current directory is distinct from the original directory, which is the one from which the process was started.

Varnish answered 14/4, 2013 at 15:38 Comment(0)
N
0

it will store in current directory . that your application will run

e.g :

if you call Directory.GetCurrentDirectory(); it will return :

"C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0"

Nomination answered 17/4, 2013 at 7:59 Comment(0)
C
0

Additionally:

  • the working directory can be changed in VisualStudio project settings Project | Properties | Debug

  • if you create a shortcut to the application for a user you can specify the "Start in" property

Cupp answered 5/12, 2016 at 14:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.