AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Clarify GetTempFileName Limitation

Open Habikki opened this issue 8 years ago • 2 comments

Can the following paragraph be clarified?

Warning: The following code uses GetTempFileName, which throws an IOException if more than 65535 files are created without deleting previous temporary files. A real app should either delete temporary files or use GetTempPath and GetRandomFileName to create temporary file names. The 65535 files limit is per server, so another app on the server can use up all 65535 files.

I'm curious what actually causes the limiting factor of 65535 files and at what scope. Is this limitation due to the number of files in a directory of a given file system (e.g. FAT), or is this a dotnet limitation?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Habikki avatar Jun 09 '18 12:06 Habikki

API ref didn't help ... https://docs.microsoft.com/dotnet/api/system.io.path.gettempfilename?view=netcore-2.1#System_IO_Path_GetTempFileName

The API shows a Win32 call to GetTempFileNameW ... https://github.com/dotnet/corefx/blob/release/2.1/src/Common/src/CoreLib/System/IO/Path.Windows.cs#L158-L181

... and then I found this MSDN page that has the answer ... https://msdn.microsoft.com/library/windows/desktop/aa364991(v=vs.85).aspx

UINT WINAPI GetTempFileName(
  _In_  LPCTSTR lpPathName,
  _In_  LPCTSTR lpPrefixString,
  _In_  UINT    uUnique,
  _Out_ LPTSTR  lpTempFileName
);

uUnique [in] - An unsigned integer to be used in creating the temporary file name.

Only the lower 16 bits of the uUnique parameter are used. This limits GetTempFileName to a maximum of 65,535 unique file names if the lpPathName and lpPrefixString parameters remain the same.

... so the limit is from the API and not from the file system. You'll be able to get more information by asking on SO.

The file uploads topic is due for an overhaul on #5331. Idk if additional info on the limit will make its way into the doc when its addressed. I'll cross-link this issue over there just in case the info is surfaced.

Thanks for commenting.

guardrex avatar Jun 09 '18 14:06 guardrex

Appreciate the well formed reply @guardrex.

I do a lot of cross platform development on dotnet these days and generally aim for the lowest common limiting factor and was super curious where the origination came from.

Habikki avatar Jun 09 '18 15:06 Habikki