Search code examples
c#asp.net-mvc-3network-programmingfile-exists

How to check existence of a file in network with c# in .net mvc 3


I'm trying to reach a file in network but it gives me the error the path is not found. What should i do to check existence of a file in network with c# in .net MVC 3

File.Exists("\\102.102.112.250\\some_pictures\\" + apicturename + ".jpg")

This is the network adress \\102.102.112.250\some_pictures

did my research but still couldnt find a proper answer..


Solution

  • You probably just need to escape the \ at the beginning of your path:

    File.Exists("\\\\102.102.112.250\\some_pictures\\" + apicturename + ".jpg")
    

    Alternatively you could probably use:

    File.Exists(@"\\102.102.112.250\some_pictures\" + apicturename + ".jpg")
    

    Which is a little easier to read since you are not needing to escape the \ in a verbatim string.