Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 6
    some caveats about GetTempFileName The GetTempFileName method will raise an IOException if it is used to create more than 65535 files without deleting previous temporary files. The GetTempFileName method will raise an IOException if no unique temporary file name is available. To resolve this error, delete all unneeded temporary files. Commented Nov 9, 2012 at 7:28
  • 2
    Temporary files are mainly uses for a specific set of conditions. If the file extension is important, I wonder if maybe using the GetTempFileName isn't the write solution. I know it's been a long time, but if you told us more about the context and need for these files, we might be able to suggest a better approach altogether. more here: support.microsoft.com/kb/92635?wa=wsignin1.0 Commented Nov 9, 2012 at 7:33
  • 2
    Keep in mind GetTempFileName() creates a new file each time you call it. -- If you immediately change the string to something else, you just created a new zero byte file in your temp directory (and as others have noted, this will eventually cause it to fail when you hit 65535 files in there...) -- To avoid this, make sure to delete any files that you create in that folder (including the ones returned by GetTempFileName(), ideally in a finally block). Commented Oct 23, 2018 at 23:53