开发者

Can Path.GetTempFileName() ever cache?

I have an odd problem... and I think I have narrowed it down to a point where we create a temporary file using Page.GetTempFileName().

I sometimes get a error message stating that Cannot create a file when that file already exists.

Is there a chance that using Path.GetTempFilename() could generate the same filename and become cached?

I am changing my code to use:

Path.Combine(System.IO.Path.GetTempPath(), string.Concat(Guid.NewGuid().ToString(), ".xls"));

In the hope that this will generate a unique filename, but I a开发者_运维问答m concerned that the same problem may arise.


Path.GetTempFilename() creates an actual file on disk; depending on what you're doing once you have that filename you could be triggering something. It's written to return an actual file to avoid the race conditions associated with older temp filename methods from the past (notably tmpnam in the C standard library, for example.)

Note that it will throw exceptions if there are more than 65,535 files created with this method without deleting them, or if it can't generate a unique filename.

So, what are you doing with that filename after you get it back from Path.GetTempFilename()?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜