I have a path with over 260 characters and tried to retreive file informations from the file from this path with FileInfo. But I was getting a PathTooLongException
. I have shortened it with following code:
if (longName.Length >= 247)
{
longName = @"\\?\" + longName;
}
StringBuilder shortPath = new StringBuilder(300);
GetShortPathName(longName, shortPath, shortPath.Capacity);
return shortPath.ToString();
Now my path have only 139 characters but I still get a PathTooLongException
from FileInfo. Does anyone knows why?
Is the shortened path just a placeholder like a conjunction for the long path and FileInfo is using the long path instead?
EDIT: The Execption occurs here:
string fileName = ToShortPathName(_path);
fileName = fileName.Replace(@"\\?\", "");
fileInformations.FileName = fileName;
fileInformations.FullPath = _path;
=> fileInformations.FileLastChanged = File.GetLastWriteTime(fileName);
EDIT2: fileName at the position of error is:
D:\\06PROJ~1\\1094IH~1\\FACHBE~1\\IT\\Azubi\\KH\\PROJEK~1\\VISUAL~1\\USB_BA~1\\packages\\NUNIT3~1.0\\lib\\PORTAB~1.IOS\\NUNITF~1.DLL