Last post Jan 14, 2016 04:54 PM by PatriceSc
Jan 14, 2016 06:45 AM|behera.deepakkumar21|LINK
I was trying out a scenario wherein i passed a random text without extn. e.g. "test path" as parameter to File.Exists method, to a surprise i got the return value as true. Then I tried writing content to that file name
and all worked fine but ideally it should return false in the exists file itself.
None of the below line failed.. neither the File.Exists not the File.OpenWrite
writer = new BinaryWriter(File.OpenWrite(strFilePath));
Please help me clarify my doubt on the same
Jan 14, 2016 07:08 AM|oned_gk|LINK
How if you type the path directly with wrong path?
writer = new BinaryWriter(File.OpenWrite("abc"));
Jan 14, 2016 08:05 AM|Klein Zhang|LINK
e.g. "test path" as parameter to File.Exists method, to a surprise i got the return value as true.
According to your description, when you pass a filename without extension, File.Exists method will return true, i suspect that your application have a file with the same filename, so you get the result, please check if you have the file with the same filename
in your application. I create a file in my applcaiton and its filename is "test path", it also works fine with your code.
string strFilePath = "test path";
BinaryWriter writer = new BinaryWriter(File.OpenWrite(strFilePath));
Jan 14, 2016 09:15 AM|behera.deepakkumar21|LINK
I have checked in my system, there is no file with that name...
what I actually want to say is.. if we are not specifying any extn and if a file with that name doesn't exists then it should return false instead of true
Jan 14, 2016 04:54 PM|PatriceSc|LINK
I tried but it returns false for me. Are you sure
strFilePath is what you think it is? And if the code you shown just "work" what makes you think it enters the if block rather than skipping it.
Do you have *seen* that it returns true or could it be a wrong interpretation of some behavior (what you have seen for now doesn't really allow to know IMO if the file exists or not).
Ah could it be that you wanted actually if(!File.Exists) rather than if(File.Exists) ???
Try to explain the exact behavior you have seen without any interpretation.