1

In my application during Debugging I want to check if the file was created in the application directory.

This file exists under path. The if (! File.Exists (pathFile)) method always returns false.

How to fix it?

EDIT: https://media.discordapp.net/attachments/580708522589683722/640902364903112734/unknown.png

Deivid.PL
  • 31
  • 6
  • check the content of `pathFile` does it have the entire path? like `C:\foo\innerFoo\File.txt` ? On the second glance at it : Why the negation with `! `? Your checking basically: IF does not exist, but the file exists, so the return value is false. Looks like everything is working as it should – Mong Zhu Nov 04 '19 at 13:43
  • This is path: "D:\Xamarin Projects\XamarinDev\DzisUzbieramNa\DzisUzbieramNa\DzisUzbieramNa\Language\Languages.xlsx" "D:\Xamarin Projects\XamarinDev\DzisUzbieramNa\" - Is project solution path. If I open this path in the windows explorer, the file opens. – Deivid.PL Nov 04 '19 at 13:45
  • "method always returns false" or do you want to say, that it even returns false when you remove the file from the directory? – Mong Zhu Nov 04 '19 at 13:46
  • 1
    If the file exists under this patch, returns false. If not, it also returns false. – Deivid.PL Nov 04 '19 at 13:50
  • I edited the post. I added a link to the photo with proof that the file exists. – Deivid.PL Nov 04 '19 at 13:54
  • ah it returns `true` even though the file exists – Mong Zhu Nov 04 '19 at 13:56
  • 1
    https://cdn.discordapp.com/attachments/640912174973321216/640912190487920660/unknown.png When file not exists. – Deivid.PL Nov 04 '19 at 13:56
  • did you check the returning value by pulling it out of the if and catch the resulting value in an extra `bool ret = File.Exists (pathFile)` variable – Mong Zhu Nov 04 '19 at 14:02
  • Yes, this is value of bool _checkedValue. https://cdn.discordapp.com/attachments/640912174973321216/640914253439696916/unknown.png – Deivid.PL Nov 04 '19 at 14:04
  • wow, that's interesting, did you try to read out the directory and print the names of the files? looking for weird hidden characters in the filename? – Mong Zhu Nov 04 '19 at 14:07
  • is this the entire path that I see in the windows file explorer? or is it may be shortened down by windows? did you copy paste it from the address bar? – Mong Zhu Nov 04 '19 at 14:10
  • Path is correct. Next photo: https://cdn.discordapp.com/attachments/640912174973321216/640918497404387330/unknown.png – Deivid.PL Nov 04 '19 at 14:21
  • 1
    Problem is "Access denied": https://cdn.discordapp.com/attachments/640912174973321216/640921357277855754/unknown.png – Deivid.PL Nov 04 '19 at 14:33
  • seems like we are getting closer. have you tried to run your .exe as admin? or even running visual studio as admin? – Mong Zhu Nov 04 '19 at 14:52
  • seems like [this answer](https://stackoverflow.com/a/34890188/5174469) would be a fitting duplicate – Mong Zhu Nov 04 '19 at 14:54

0 Answers0