# InteractionFile Methods

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

Represents a file selected by the user for an [InputType.File](/reference/api/csharp/aspire.hosting/inputtype/fields.md) input.

<a id="openread"></a>

## OpenRead

- Name: `OpenRead`
- Returns: `Stream`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62/src/Aspire.Hosting/IInteractionService.cs#L633-L634)

Opens a read-only stream for the file content.

```csharp
public sealed class InteractionFile
{
    public Stream OpenRead()
    {
        // ...
    }
}
```

## Returns

`Stream` -- A `IO.Stream` for reading the file.

## Exceptions

- `ObjectDisposedException` -- The owning [InteractionFileCollection](/reference/api/csharp/aspire.hosting/interactionfilecollection.md) has been disposed.

## Remarks

The returned stream remains usable if the owning [InteractionFileCollection](/reference/api/csharp/aspire.hosting/interactionfilecollection.md) is disposed. Dispose the stream when reading is complete so the operating system can finish reclaiming the deleted file.

<a id="readallbytesasync"></a>
<a id="readallbytesasync-cancellationtoken"></a>

## ReadAllBytesAsync(CancellationToken)

- Name: `ReadAllBytesAsync(CancellationToken)`
- Returns: `Task<byte[]>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62/src/Aspire.Hosting/IInteractionService.cs#L647-L648)

Reads all bytes of the file asynchronously.

```csharp
public sealed class InteractionFile
{
    public Task<byte[]> ReadAllBytesAsync(
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `cancellationToken` (`CancellationToken`) `optional`
  A token to monitor for cancellation requests.

## Returns

`Task<byte[]>` -- A byte array containing the file content.

## Exceptions

- `ObjectDisposedException` -- The owning [InteractionFileCollection](/reference/api/csharp/aspire.hosting/interactionfilecollection.md) has been disposed.
