System.IO.DirectoryNotFoundException when path is longer than 260 characters [duplicate] - c#

This question already has answers here:
Maximum filename length in NTFS (Windows XP and Windows Vista)?
(15 answers)
Closed 5 years ago.
I have ASP.NET Core MVC project (targeting .NET 4.62) and I'm trying to save files. Everything works while the length of the path is under 260 (or 248 I'm not sure), but when it's longer I get a System.IO.DirectoryNotFoundException. Previously when I was targeting .NET 4.61 I was getting Path too long exception, I've read that the problem is fixed in .NET 4.62 but not for me.
Here's exception that I'm getting while path is too long
File.Copy(file, Path.Combine(path, dbFile.Id.ToString()));
I'm pretty sure that directory exists.

I refer you to this answer on why the ~255 limit filename|folder. Probabaly a probleme because you are on Windows on NTFS. Nothing to do with .NET framework

Related

Why does Path.Combine ignore the first part of a ftp server path? [duplicate]

This question already has answers here:
Why does Path.Combine not properly concatenate filenames that start with Path.DirectorySeparatorChar?
(16 answers)
Closed 5 years ago.
I have two parts of a ftp server path. Let's name the /one and /two.
The full path I want to achieve is /one/two.
When I use System.IO.Path.Combine("/one", "/two"); the output is "/two".
Why is that so? I expected it to be "/one/two" as you would normally with windows paths.
Is this by design, wrong usage by me or a bug in the .net class (unlikely)?
(How) can I use System.IO.Path functionality to produce "/one/two"?
If path2 contains an absolute path, this method returns path2.

Getting Windows Build Number programmatically [duplicate]

This question already has answers here:
Getting Windows OS version programmatically
(6 answers)
Closed 5 years ago.
Using C#, how can I get the Windows build number or OS Build number as shown in the About window? This is different from the version number: for Windows 10 Creator Update, the Build Number would be 1703 and the OS Build would be 15063.296.
I can't find anything relevant in Environment.OSVersion and this linked question (Getting Windows OS version programmatically) is only about getting the version number (10 in this case)
The following gets the Build number:
Environment.OSVersion.Version.Build

Get App Version Number [duplicate]

This question already has answers here:
How to get app version in Windows Phone?
(11 answers)
Closed 8 years ago.
How do you get the app version number? It's clear how to get OS version number etc, but nothing seems to be documented on getting the app version from the manifest?
Getting OS Version number works as such:
var VersionNumber = Environment.OSVersion.Version;
btn.Content = VersionNumber;
You can get the Version from the manifest by loading the .xml like this:
string Version = XDocument.Load("WMAppManifest.xml")
.Root.Element("App").Attribute("Version").Value;

How much is the filename size limit [duplicate]

This question already has answers here:
Maximum filename length in NTFS (Windows XP and Windows Vista)?
(15 answers)
Closed 9 years ago.
I want to rename image files uploaded to my website and give them a bit of description. I'm using ASP.NET, C# and of course Windows hosting. the file names will contain Unicode characters. how much is the filename size limit in these conditions?
Individual components of a filename (i.e. each subdirectory along the
path, and the final filename) are limited to 255 characters, and the
total path length is limited to approximately 32,000 characters.
Source
MSDN more reading
However, the issue will be more due to the browser as the full URL is limited to a number of characters and it's different per browser. Some posts here suggest you should limited to 2000 characters.
To read more about browser limits, I suggest you read here but please note for future proofing, the comments I've made here and posts I've cited will become outdated. You need to do your own research at the time of reading this!

Working out version of windows [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How to detect Windows 64 bit platform with .net?
How do you know if the operating system is x64 or x86 from a c# .net 2.0 windows applicaiton?
Also the applicaiton is 32bit.
Thanks
Use GetEnvironmentVariable to look for the PROCESSOR_ARCHITEW6432 variable. If it doesn't exist, you must be running 32bit:
bool is64bit = !string.IsNullOrEmpty(
Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"));
EDIT:
Thanks to Hans Passant for pointing out the error in using the PROCESSOR_ARCHITECTURE variable.

Categories