When creating a temp file System.IO.IOException: The file exists error

If you get the System.IO.IOException: The file exists error, it’s probably because your C:/Windows/Temp folder is absolutely full with temporary files. In fact, if you have more than 65535 files in your temp folder, the method GetTempFileName will throw this error.

To resolve this, just remove all temporary files in C:/Windows/Temp. It might take some time, but it will solve the problem.

Here’s the stack trace I got:

System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)



5 Responses

  1. […] this, I found plenty of blog posts stating this exception is thrown when there are more than 65535 temp files in the %TEMP% folder, […]

  2. I would recomend not using Path.GetTempFileName() at all. You have no guarantee that this method wil work over time. This is explained in detail in my blog:

  3. Run into this problem in Subtitle Edit. Have a bit of stack trace knowledge from Java so copying the topmost error message led me here.

    This trick made it go away so thank you.

  4. If you are running this command under a specific user you could check also the temp direcotry of your user profile usually in c:\Users\AppData\Local\Temp

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: