# ITempFileSystemService Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [ITempFileSystemService](/reference/api/csharp/aspire.hosting/itempfilesystemservice.md)
- Kind: `Methods`
- Members: `2`

Service for managing temporary directories and files within Aspire.

## CreateTempFile(string?)

- Name: `CreateTempFile(string?)`
- Modifiers: `abstract`
- Returns: [TempFile](/reference/api/csharp/aspire.hosting/tempfile.md)

Creates a new temporary file and returns it.

```csharp
public interface ITempFileSystemService
{
    public abstract TempFile CreateTempFile(
        string? fileName = null)
    {
        // ...
    }
}
```

## Parameters

- `fileName` (`string?`) `optional`
  Optional file name for the temporary file (e.g., "config.json", "script.sh"). If null, uses a random name.

## Returns

[TempFile](/reference/api/csharp/aspire.hosting/tempfile.md) -- A [TempFile](/reference/api/csharp/aspire.hosting/tempfile.md) representing the created temporary file. Dispose to delete.

## Remarks

This method creates a new temporary file. If a file name is specified, it creates a temporary subdirectory and places the file with that name inside it. If no file name is specified, it uses `Path.GetTempFileName`. Dispose the returned object to delete the file.

Use this instead of calling `Path.GetTempFileName` directly.

## CreateTempSubdirectory(string?)

- Name: `CreateTempSubdirectory(string?)`
- Modifiers: `abstract`
- Returns: [TempDirectory](/reference/api/csharp/aspire.hosting/tempdirectory.md)

Creates and returns a temporary subdirectory.

```csharp
public interface ITempFileSystemService
{
    public abstract TempDirectory CreateTempSubdirectory(
        string? prefix = null)
    {
        // ...
    }
}
```

## Parameters

- `prefix` (`string?`) `optional`
  Optional prefix for the subdirectory name (e.g., "aspire").

## Returns

[TempDirectory](/reference/api/csharp/aspire.hosting/tempdirectory.md) -- A [TempDirectory](/reference/api/csharp/aspire.hosting/tempdirectory.md) representing the created temporary subdirectory. Dispose to delete.

## Remarks

This method creates a unique temporary subdirectory using the system temp folder. The directory is created immediately. Dispose the returned object to delete the directory.

Use this instead of calling `Directory.CreateTempSubdirectory` directly.
