469,626 Members | 1,494 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

System.IO.File.Exists - what if network path and not C:\

I'm trying to see if a file exists on a server. I have the below code which
doesn't seem to work. Must I necessarily have a mapped drive to that the
path starts with X:\ or similar?

if (System.IO.File.Exists("\\MyServer\MyFolder\MySubF older\MyFile.txt") ==
true)
{
//Do stuff...
}
Thanks,
Ron

Mar 9 '07 #1
5 14560
PS
"Ronald S. Cook" <rc***@westinis.comwrote in message
news:%2*****************@TK2MSFTNGP04.phx.gbl...
I'm trying to see if a file exists on a server. I have the below code
which doesn't seem to work. Must I necessarily have a mapped drive to
that the path starts with X:\ or similar?

if (System.IO.File.Exists("\\MyServer\MyFolder\MySubF older\MyFile.txt") ==
true)
{
//Do stuff...
}
That code won't compile - you need an @ before the quotes.

Also the == true is not necessary as the Exists method returns true/false
itself
>

Thanks,
Ron

Mar 9 '07 #2
That doesn't seem to do it either.
"PS" <ec***********@hotmail.comwrote in message
news:Yc2Ih.13078$kf.9031@trndny02...
"Ronald S. Cook" <rc***@westinis.comwrote in message
news:%2*****************@TK2MSFTNGP04.phx.gbl...
>I'm trying to see if a file exists on a server. I have the below code
which doesn't seem to work. Must I necessarily have a mapped drive to
that the path starts with X:\ or similar?

if (System.IO.File.Exists("\\MyServer\MyFolder\MySubF older\MyFile.txt")
== true)
{
//Do stuff...
}

That code won't compile - you need an @ before the quotes.

Also the == true is not necessary as the Exists method returns true/false
itself
>>

Thanks,
Ron


Mar 9 '07 #3
PS

"Ronald S. Cook" <rc***@westinis.comwrote in message
news:un**************@TK2MSFTNGP05.phx.gbl...
That doesn't seem to do it either.
If you copy and paste the path into Start / Run and click OK what happens?
>

"PS" <ec***********@hotmail.comwrote in message
news:Yc2Ih.13078$kf.9031@trndny02...
>"Ronald S. Cook" <rc***@westinis.comwrote in message
news:%2*****************@TK2MSFTNGP04.phx.gbl.. .
>>I'm trying to see if a file exists on a server. I have the below code
which doesn't seem to work. Must I necessarily have a mapped drive to
that the path starts with X:\ or similar?

if (System.IO.File.Exists("\\MyServer\MyFolder\MySubF older\MyFile.txt")
== true)
{
//Do stuff...
}

That code won't compile - you need an @ before the quotes.

Also the == true is not necessary as the Exists method returns true/false
itself
>>>

Thanks,
Ron



Mar 9 '07 #4


"Ronald S. Cook" <rc***@westinis.comwrote in message
news:un**************@TK2MSFTNGP05.phx.gbl...
That doesn't seem to do it either.
"PS" <ec***********@hotmail.comwrote in message
news:Yc2Ih.13078$kf.9031@trndny02...
>"Ronald S. Cook" <rc***@westinis.comwrote in message
news:%2*****************@TK2MSFTNGP04.phx.gbl.. .
>>I'm trying to see if a file exists on a server. I have the below code
which doesn't seem to work. Must I necessarily have a mapped drive to
that the path starts with X:\ or similar?

if (System.IO.File.Exists("\\MyServer\MyFolder\MySubF older\MyFile.txt")
== true)
{
//Do stuff...
}

That code won't compile - you need an @ before the quotes.

Also the == true is not necessary as the Exists method returns true/false
itself
>>>

Thanks,
Ron


try...

if (System.IO.File.Exists(@"\\MyServer\MyFolder\MySub Folder\MyFile.txt")) {
// Do Stuff...
}

If this doesn't exist, the user of the process executing this code may not
have read rights for the specified file or....the file may not exist in that
location.

HTH,
Mythran
Mar 9 '07 #5
Ahh.. I think that may be it. -thx

"Mythran" <ki********@hotmail.comwrote in message
news:2E**********************************@microsof t.com...
>

"Ronald S. Cook" <rc***@westinis.comwrote in message
news:un**************@TK2MSFTNGP05.phx.gbl...
>That doesn't seem to do it either.
"PS" <ec***********@hotmail.comwrote in message
news:Yc2Ih.13078$kf.9031@trndny02...
>>"Ronald S. Cook" <rc***@westinis.comwrote in message
news:%2*****************@TK2MSFTNGP04.phx.gbl. ..
I'm trying to see if a file exists on a server. I have the below code
which doesn't seem to work. Must I necessarily have a mapped drive to
that the path starts with X:\ or similar?

if (System.IO.File.Exists("\\MyServer\MyFolder\MySubF older\MyFile.txt")
== true)
{
//Do stuff...
}

That code won't compile - you need an @ before the quotes.

Also the == true is not necessary as the Exists method returns
true/false itself

Thanks,
Ron




try...

if (System.IO.File.Exists(@"\\MyServer\MyFolder\MySub Folder\MyFile.txt"))
{
// Do Stuff...
}

If this doesn't exist, the user of the process executing this code may not
have read rights for the specified file or....the file may not exist in
that location.

HTH,
Mythran


Mar 9 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Alex Chan | last post: by
4 posts views Thread by raibeart | last post: by
7 posts views Thread by Stephen E. Weber | last post: by
7 posts views Thread by George Lake | last post: by
4 posts views Thread by Italian Pete | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.