Directory Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I am using the Directory object in the System.IO Namespace. When I use the
following code It gives me Object reference not set to an instance of an
object. Can Anyone tell me what I am doing wrong?

The line is Direcotry.exists("C:\")


Thanks
Kiran Kumar
 
Hi I am using the Directory object in the System.IO Namespace. When I use the
following code It gives me Object reference not set to an instance of an
object. Can Anyone tell me what I am doing wrong?

The line is Direcotry.exists("C:\")


Please post a complete code snippet that reproduces the error you're
getting.



Mattias
 
Hi, Here it is, When I use this in a normal application it works, But I am
writing a windows service, that gets files from a particular directory. It
works on some machines and does not work fine on others like the
Pre-Production server, which is identical to the Integration server.

IF (Directory.Exists("C:\") THEN
'Do Some stuff Here
Else
'Do Some other stuff here.
End If

Thanks
Kiran
 
You must make an instance of the "directory" class before you can use it.

Dim theDirectory As New Directory
If theDirectory.Exists("c:/") Then....
 
Hello Scott M.,

This is false. Directory has no constructors on it and only static methods,
so your code sample shouldnt even compile.

Directory.Exists("c:\") is the correct syntax.
 
Hi, Here it is

I doubt it...
IF (Directory.Exists("C:\") THEN

This doesn't even compile since you're missing a closing parenthesis.

If you don't post your actual code, it's hard to guess what's causing
the exception. From what you've described so far, we don't know for
sure if it actually is the Exists call that fails or if it is some
code before or after it. Please post something that's complete enough
to compile.

http://www.yoda.arachsys.com/csharp/complete.html



Mattias
 
Back
Top