Improve download from stream example (#26384)
parent
541740d234
commit
2787d1dc52
|
@ -76,6 +76,20 @@ The following example component:
|
|||
|
||||
:::code language="razor" source="~/../blazor-samples/6.0/BlazorSample_WebAssembly/Pages/file-downloads/FileDownload1.razor":::
|
||||
|
||||
For a component in a Blazor Server app that must return a <xref:System.IO.Stream> for a physical file, the component can call <xref:System.IO.File.OpenRead%2A?displayProperty=nameWithType>, as the following example demonstrates:
|
||||
|
||||
```csharp
|
||||
private Stream GetFileStream()
|
||||
{
|
||||
return File.OpenRead(@"{PATH}");
|
||||
}
|
||||
```
|
||||
|
||||
In the preceding example, the `{PATH}` placeholder is the path to the file. The `@` prefix indicates that the string is a [*verbatim string literal*](/dotnet/csharp/programming-guide/strings/#verbatim-string-literals), which permits the use of backslashes (`\`) in a Windows OS path and embedded double-quotes (`""`) for a single quote in the path. Alternatively, avoid the string literal (`@`) and use either of the following approaches:
|
||||
|
||||
* Use escaped backslashes (`\\`) and quotes (`\"`).
|
||||
* Use forward slashes (`/`) in the path, which are supported across platforms in ASP.NET Core apps, and escaped quotes (`\"`).
|
||||
|
||||
## Download from a URL
|
||||
|
||||
*This section applies to files that are relatively large, typically 250 MB or larger.*
|
||||
|
|
Loading…
Reference in New Issue