Skip to content

[API Proposal]: Add Path.GetTempFileName(string extension) overload #116033

Closed as duplicate of#72881
@vsfeedback

Description

@vsfeedback

Summary

Currently Path.GetTempFileName() creates a temporary file with a .tmp extension and returns its path as a string. If a user wants a file with a different extension, they have to rename it or create a new file with the extension appended to the name. This issue proposes adding an overload to specify the extension for the created temporary file.

Proposed API

 

namespace System.IO;

public static partial class Path
{
    public static string GetTempFileName(string extension);
}

Related issues: #40414 and #2048

Original issue:

This issue has been moved from a ticket on Developer Community.


[severity:Other]
What Happens to a .TMP File Created Using Path.GetTempFileName()?
The online doc doesn't mention what happens to the temp file - is it eventually deleted by the OS at some point? It would have been very useful if Microsoft had provided an extension parameter. So in using it, you wind up with 2 temp files (when the extension you need is appended to the temp filename because a TMP extension is often useless).


Original Comments

Alison Jin [MSFT] on 4/24/2025, 10:21 PM:

Thank you for your feedback! In order for us to investigate this further, could you please provide repro steps, a more detailed description of the issue to help us better understand this scenario? Does this reproduce for all project or specific project? What is the actual result and which result do you expect to happen? It would be very helpful if you could provide some screenshots that has this problem or record a video for this scenario by using ScreenToGif.

We look forward to hearing from you!

Feedback Bot on 5/6/2025, 07:26 PM:

We will close this report in 14 days because we don’t have enough information to investigate further. To keep the problem open, please provide the requested details.

Eckels, Adam on 5/7/2025, 05:35 AM:

I think you’re making this more complicated than it needs to be. I’m simply suggesting for you to add a file-extension parameter to System.IO.Path.GetTempFileName(). For example: GetTempFileName(“pdf”). By always only creating files with a .tmp extension, you’re causing programmers extra work when they need an extension other than .tmp.

Feedback Bot on 5/15/2025, 00:01 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions