Jump to content

Accessing folder in project from code in VS

- - - - -

  • Please log in to reply
6 replies to this topic

#1
sonar87

sonar87

    Newbie

  • Members
  • PipPip
  • 15 posts
This is probably going to be a very stupid question as I've been away from coding for quite a while and am sure I'm missing something basic, but.. When working on a new project in Visual Studio I, as usual, started grouping some of my .cs files into folders to make the solution explorer more maneuverable. For one folder, I can access it in code like normal - foldername.filename.method. Every other folder, however, does not show up in the auto-correct when I type it's name, and it says that they don't exist in the current context. Does anyone have any clue what I'm missing or that could be wrong?

#2
taburetka

taburetka

    Newbie

  • Members
  • PipPip
  • 11 posts
As far as I know in C# putting source files in directories doesn't make a difference for their "visibility" in code, it's just for your convinience. But what does make a difference - is namespaces :)

#3
sonar87

sonar87

    Newbie

  • Members
  • PipPip
  • 15 posts
That was one of the first things I thought of, but I checked and all the namespaces match.

#4
taburetka

taburetka

    Newbie

  • Members
  • PipPip
  • 11 posts

sonar87 said:

For one folder, I can access it in code like normal - foldername.filename.method.
There is no need to call filenames also. If all namespaces are the same just "classname.method" must work everywhere.

#5
sonar87

sonar87

    Newbie

  • Members
  • PipPip
  • 15 posts
Well how it always worked before was calling the name of the folder I had everything in, then .classname.method Only now its acting like the folders aren't there.

#6
Momerath

Momerath

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 243 posts
That's because the folders were part of the namespace the files were in. Now you say they aren't, so you don't need it.

If you create a project and call it 'Fred' it will have a namespace of 'Fred'. If you now create a folder in this project called 'MyFolder' and then create a file under that folder (all in the IDE, of course), it will have a namespace of 'Fred.MyFolder'. In the original file you'll have a 'using Fred' line, and you can use stuff from MyFolder by writing 'MyFolder.ClassName' or by adding a 'using Fred.MyFolder' and then you can just use the ClassName.

#7
sonar87

sonar87

    Newbie

  • Members
  • PipPip
  • 15 posts

Momerath said:

and you can use stuff from MyFolder by writing 'MyFolder.ClassName'

And, under the circumstances you've just stated this ^ is exactly what I'm trying to do, and it is not working.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users