Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions doc/external/StorageFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,51 @@ You need to load app data files on all platforms. Traditional file access method

Use the `Windows.Storage.StorageFile` API to read files from your app package. This works the same way on all Uno Platform targets, including WASM.

- Move your data files to be included as `Content` in your project, and use `StorageFile.GetFileFromApplicationUriAsync` to load them by path.
- Move your data files to be included as `Content` in your project's output directory, and use `StorageFile.GetFileFromApplicationUriAsync` to load them by path. To ensure that you will always have the latest changes included, set the appropriate Property: `CopyToOutputDirectory="PreserveNewest"`.

```xml
<ItemGroup>
<Content Include="AppData\*.json" />
<Content Include="AppData\*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
```

- If you want to not just have these files in your app's output directory with latest changes, then also have your IDE showing them in your **Solution Explorer** and enable you editing them easily as if those would be directly nested in your specific project, you may want to also set another property on the xml element we just added: `LinkBase="AppData"` (or any other Name you want it to show to you as folder name).

So this will make the full Content Element look like this:

```xml
<ItemGroup>
<Content Include="AppData\*.json" CopyToOutputDirectory="PreserveNewest" LinkBase="AppData" />
</ItemGroup>
```

And in your Solution Explorer, this will show up like with the below shown grey text (VS Code) or with a Link Arrow like you may know it from .ink files on your Desktop (Visual Studio 2022).

```markdown
root
|-AppData
| |-yourDataContainingFile.json
|-ClientApp/
| |-ClientApp.csproj
| |-AppData/ *(Linked File)*
| |-yourDataContainingFile.json *(Linked File)*
|-ClientApp.Api/
| |-ClientApp.Api.csproj
| |-AppData/ *(Linked File)*
| |-yourDataContainingFile.json *(Linked File)*
|-ClientApp.IntegrationTests/...
|-ClientApp.UITests/...
|-ClientApp.UnitTests/...
```

> [!TIP]
> Another advantage of setting the LinkBase Property like shown above is, that you can do this on every project in your Solution you like to, without being required to:
>
> - duplicate the Folder or Files
> - if you edit a file in there, its state will always be synced
> [!TIP]
> If you may not want to have those files in your output directory of the Project, but showing up in your Solution Explorer, you can set the `CopyToOutputDirectory` property shown before, to **Never**.

Comment on lines +23 to +59
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't spend too much detail surrounding explaining this as it is not specific to Uno or the StorageFile properties. This is something coming from MSBuild and we can offload all of this explanation to their docs on the subject: https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#linkbase

- Loading a JSON File Using StorageFile

```csharp
Expand Down
Loading