I am trying to delete file from remote computer like this:
fileinfo undelteablefile = new fileinfo(
@"\\CompName\c$\documents and settings\UserName\local settings\temporary internet files\content.ie5\k9ef0hmj\%d7%a9%d7%a2%a8%20%d7%9c%20%d7%a2%93%d7%9b%d7%95%d7%9f%20%d7%98%d7%9d%a0%d795%d7%9c%d7%d7%95%d7%92%d7%99%20%d7%97%95%d7%93%d7%a9%d7%99 [1] .jpg");
undeleteablefile.delete();
It gave me an exception that the file name or path are too long.
I tried adding \\?\ but it didnt work... Why is this happening and what to do to solve this?
Map a network share to one of the directories closer to the file. Try deleting it with a wildcard.
There are three approaches that I have used, but be warned that they require unmanaged P/Invoke code. Not much, so you can probably copy/paste if you don't understand how it works.
Use the 8.3 filenames (ala DOS compatible filenames)
Use the \?\ syntax that you mention. However, I don't believe that you can use it directly from C# - you will need to invoke the native methods. Note - this has security implications, as the string is not parsed, but passed directly to the filesystem.
Use the unmanaged File APIs.
This is a great series of blog posts that address exactly this issue.
Erick
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With