Missing backslashes in filename using C#

Posted by CL4NCY on Stack Overflow See other posts from Stack Overflow or by CL4NCY
Published on 2010-03-25T18:11:04Z Indexed on 2010/03/25 18:33 UTC
Read the original article Hit count: 323

Filed under:
|

Hi,

I have a string literal as follows:

string filename = @"C:\myfolder\myfile.jpg";

When I use File.Exists(filename) it works most of the time but sometimes I get an error saying the following file doesn't exist:

C:myfoldermyfile.jpg

Something seems to strip the backslashes out of the filename. This code is sometimes accessed via an ajax request.

Does anyone know why/how this could be happening?

Edit:

Here is a more detailed version of the code.

public class Feeds {

    public static string ftpDir = @"C:\website\Feeds\";

}

public class Feed {

    public static void run(string name) {

        if (!Directory.Exists(Feeds.ftpDir + name)){ 

            Response.Write("Feed doesn't exist '" + Feeds.ftpDir + name + "'"); 

            return; 

        }

        //run feed...

    }

}

© Stack Overflow or respective owner

Related posts about c#

Related posts about string