diff --git a/aspnetcore/blazor/file-downloads.md b/aspnetcore/blazor/file-downloads.md index c3d9379f0f..2ff8f39d7a 100644 --- a/aspnetcore/blazor/file-downloads.md +++ b/aspnetcore/blazor/file-downloads.md @@ -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 for a physical file, the component can call , 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.*