c# - How to detect whether a file exists? -


can 1 suggest me best way see if file exists? file.exists not working me.

string abc = "me_label.deploy"; file.exists(abc) 

the file, abc, coming streamreader.readline();.

i used full path. don't want include files in project. if include in project working fine.

my code:

ftpwebrequest ftp = (ftpwebrequest)ftpwebrequest.create("me@localhost/"; + ab); //ab=newfolder/newfolder1 ftp.credentials = new networkcredential(user, pass); ftp.method = webrequestmethods.ftp.listdirectory; streamreader sr = new streamreader(ftp.getresponse().getresponsestream()); stringbuilder result = new stringbuilder(); string abc = sr.readline(); while (abc != null) {     result.append(abc);     //abc=file     result.append("\n");     if (file.exists(ab+abc))     {         //file     } }  

any relative path in .net default relative bin/debug subdirectory of project. so, unless me_label.deploy in folder, program not able find it. if include it, copied folder , works.

but have make path absolute instead. use methods path class.

string filename = "me_label.deploy"; string basepath = @"c:\my documents\"; string absolutepath = path.combine(basepath, filename); // c:\my documents\me_label.deploy console.writeline(file.exists(absolutepath)); 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -