You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Save the bookmarkId to a local file for later use.
58
58
// ... (code to save bookmarkId)
59
-
CurrentActiveBookmarkId=bookmarkId;
60
59
}
61
60
}
62
61
```
63
62
64
-
You can use the `OpenFolderBookmarkAsync()` methods to open a bookmarked folder via a `bookmark ID`. This will return the bookmarked file or folder or null if the operating system denies the request.
63
+
You can use the `OpenFolderBookmarkAsync()` methods to open a bookmarked folder via a `bookmark ID`. This will return the bookmarked folder or null if the operating system denies the request.
### Reading and Writing File Content from a Bookmark
114
+
115
+
`OpenFileBookmarkAsync()`: This method is used to open a bookmarked file from a stored `bookmark ID`. It will return the bookmarked file or null if the operating system denies the request.
116
+
117
+
118
+
Once you retrieve a bookmarked file using `OpenFileBookmarkAsync()`, you can read its content with `OpenReadAsync()` or modify it with `OpenWriteAsync()`.
119
+
120
+
`OpenReadAsync()`: Opens a stream for read access to the bookmarked file.
Once a bookmark is loaded, you can use the inherited methods from `IStorageItem` to manipulate the file or folder.
113
169
@@ -164,7 +220,7 @@ The way a `bookmark ID` is represented can vary by platform:
164
220
165
221
**Windows**: A bookmark is a simple absolute path string, so a bookmark might look like `C:\Documents\Avalonia\bookmarks.pdf`
166
222
167
-
**Android**: Think of the content provider like a waiter that your apps can ask for a certain file/folder through a Content URI. The URI format looks like `content://[Authority]/[path]/[id]`. For example, `com.android.externalstorage.documents` is an `Authority` for accessing External Storage providers, so a bookmark might look like `content://com.android.externalstorage.documents/tree/[your folder path]`.
223
+
**Android**: Think of the content provider like a waiter that your apps can ask for a certain file/folder through a Content URI. The URI format looks like `content://[Authority]/[path]/[id]`. For example, `com.android.externalstorage.documents` is an `Authority` for accessing External Storage providers, so a bookmark might look like `content://com.android.externalstorage.documents/tree/[your folder path]`(Reference: [Create a content provider | Android Developers](https://developer.android.com/guide/topics/providers/content-provider-creating)).
168
224
169
225
:::note
170
226
The exact behavior and capabilities can depend on the specific operating system and its security policies. For instance, on some platforms, a bookmark might become invalid if the user moves or renames the file or folder that it points to.
Copy file name to clipboardExpand all lines: i18n/ru/docusaurus-plugin-content-docs/current/concepts/services/storage-provider/bookmarks.md
+213-4Lines changed: 213 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,223 @@ title: Bookmarks
4
4
---
5
5
6
6
# Bookmarks
7
-
8
7
Bookmarks are particularly important for maintaining access to files and folders in modern operating systems that have strict security and privacy controls. For instance, on platforms like iOS and newer versions of macOS, direct file system access is heavily restricted. Instead, applications request the user to select a file or folder through a system-provided file picker, and the operating system then gives the application a security-scoped bookmark that it can use to access that file or folder in the future.
9
8
10
9
In Avalonia's `StorageProvider`, these bookmarks are represented as `IStorageBookmarkFile` and `IStorageBookmarkFolder` interfaces.
11
10
12
-
To get bookmark ID from the specific folder or file, please use `SaveBookmarkAsync` async method on storage item.
13
-
After retrieving bookmark ID, it can be saved in a local database for the further use instead of asking user to pick a folder each time.
14
-
You can use the `OpenFileBookmarkAsync` and `OpenFolderBookmarkAsync` methods to open a bookmarked file or folder using its bookmark ID. This will return the bookmarked file or folder, or null if the operating system denies the request.
11
+
## Avalonia.Platform.Storage
12
+
### IStorageBookmarkItem Interface
13
+
The `IStorageBookmarkItem` interface represents a bookmarked storage item. It inherits from IStorageItem and IDisposable. This interface is not client implementable, meaning you cannot create your own classes that implement it without special permissions.
14
+
15
+
Here are the key properties and methods it provides:
16
+
17
+
#### Properties:
18
+
19
+
`CanBookmark`: A property that indicates if the item can be bookmarked and reused later.
This section provides a practical guide on using `bookmark`.
40
+
41
+
### Saving and Loading Bookmarks
42
+
To get a bookmark ID for a specific folder or file, use the `SaveBookmarkAsync()` asynchronous method on a storage item. Once you have a bookmark ID, you can save it to a local database for future use instead of requiring the user to select a folder every time.
43
+
44
+
`SaveBookmarkAsync()`: This method is used to get a `bookmark ID` for a selected file or folder, which can be stored for future use.
// Save the bookmarkId to a local file for later use.
58
+
// ... (code to save bookmarkId)
59
+
}
60
+
}
61
+
```
62
+
63
+
You can use the `OpenFolderBookmarkAsync()` methods to open a bookmarked folder via a `bookmark ID`. This will return the bookmarked folder or null if the operating system denies the request.
`ReleaseBookmarkAsync()`: This method is used to revoke the security-scoped access granted by the operating system. You should call this when you no longer need access to the bookmarked item.
### Reading and Writing File Content from a Bookmark
114
+
115
+
`OpenFileBookmarkAsync()`: This method is used to open a bookmarked file from a stored `bookmark ID`. It will return the bookmarked file or null if the operating system denies the request.
116
+
117
+
118
+
Once you retrieve a bookmarked file using `OpenFileBookmarkAsync()`, you can read its content with `OpenReadAsync()` or modify it with `OpenWriteAsync()`.
119
+
120
+
`OpenReadAsync()`: Opens a stream for read access to the bookmarked file.
`TryGetLocalPath()`: This extension method attempts to get the local file system path as a string. It's useful for platform-specific operations where a local path is required.
211
+
212
+
```csharp
213
+
// This will work on Windows but may return null on other platforms
The way a `bookmark ID` is represented can vary by platform:
220
+
221
+
**Windows**: A bookmark is a simple absolute path string, so a bookmark might look like `C:\Documents\Avalonia\bookmarks.pdf`
222
+
223
+
**Android**: Think of the content provider like a waiter that your apps can ask for a certain file/folder through a Content URI. The URI format looks like `content://[Authority]/[path]/[id]`. For example, `com.android.externalstorage.documents` is an `Authority` for accessing External Storage providers, so a bookmark might look like `content://com.android.externalstorage.documents/tree/[your folder path]`(Reference: [Create a content provider | Android Developers](https://developer.android.com/guide/topics/providers/content-provider-creating)).
15
224
16
225
:::note
17
226
The exact behavior and capabilities can depend on the specific operating system and its security policies. For instance, on some platforms, a bookmark might become invalid if the user moves or renames the file or folder that it points to.
0 commit comments