Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions hub/apps/develop/data-access/mongodb-database.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ This will allow you to programmatically access MongoDB databases.
The following sample code gets a collection from a remote MongoDB client, then adds a new document to that collection. Then it uses MongoDB APIs to retrieve the new size of the collection as well as the inserted document, and prints them out.

``` csharp
using MongoDB.Bson;
using MongoDB.Driver;

var client = new MongoClient("mongodb://10.xxx.xx.xxx:27017");
IMongoDatabase database = client.GetDatabase("foo");
IMongoCollection<BsonDocument> collection = database.GetCollection<BsonDocument>("bar");
Expand Down
2 changes: 2 additions & 0 deletions hub/apps/develop/data-access/mysql-database.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ This will allow you to programmatically access MySQL databases.
The following is an example of connecting to and reading from a remote MySQL database. Note that the server address and database name will need to be customized.

``` csharp
using MySql.Data.MySqlClient;

const string M_str_sqlcon = "Server=myServerAddress;Database=myDataBase;IntegratedSecurity=yes;Uid=auth_windows;";
using (var mySqlCn = new MySqlConnection(M_str_sqlcon))
{
Expand Down
5 changes: 4 additions & 1 deletion hub/apps/develop/data-access/sql-server-database.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The snippets that appear in this guide are based on this [sample app](https://gi
To connect your app directly to a SQL Server database, your app can target any minimum version of Windows supported by Windows App SDK. You can find that information in the properties page of your project.

1. Open the **Package.appxmanifest** file of your Windows App SDK project in the manifest designer.
1. Install the SQL client package for current .NET project templates. In the **Package Manager Console**, run `Install-Package System.Data.SqlClient`.
1. In the **Capabilities** tab, select the **Enterprise Authentication** checkbox if you are using Windows Authentication for authenticating your SQL Server.

![Enterprise Authentication Capability](images/enterprise-authentication.png)
Expand Down Expand Up @@ -104,6 +105,8 @@ public class Product : INotifyPropertyChanged
In the **MainWindow.xaml.cs** file of the Windows App SDK project, create a method that gets products from the Northwind sample database, and then returns them as an [ObservableCollection](/dotnet/api/system.collections.objectmodel.observablecollection-1) collection of `Product` instances.

```csharp
using System.Data.SqlClient;

public ObservableCollection<Product> GetProducts(string connectionString)
{
const string GetProductsQuery = "select ProductID, ProductName, QuantityPerUnit," +
Expand Down Expand Up @@ -203,7 +206,7 @@ This XAML creates a [ListView](/windows/windows-app-sdk/api/winrt/microsoft.ui.x

### Show products in the ListView

Open the **MainWindow.xaml.cs** file, and add code to the constructor of the `MainWindow` class that sets the **ItemSource** property of the [ListView](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.listview) to the [ObservableCollection](/dotnet/api/system.collections.objectmodel.observablecollection-1) of `Product` instances.
Open the **MainWindow.xaml.cs** file, and add code to the constructor of the `MainWindow` class that sets the **ItemsSource** property of the [ListView](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.listview) to the [ObservableCollection](/dotnet/api/system.collections.objectmodel.observablecollection-1) of `Product` instances.

```csharp
public MainWindow()
Expand Down
11 changes: 6 additions & 5 deletions hub/apps/develop/data-access/sqlite-data-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This tutorial shows you how to integrate SQLite into your WinUI application usin

In this tutorial, you'll learn how to:

- Configure your Windows app to use SQLite with the Microsoft.Data.SQLite library
- Configure your Windows app to use SQLite with the Microsoft.Data.Sqlite library
- Create and initialize a local database
- Implement secure data insertion and retrieval methods
- Build a simple user interface to interact with your data
Expand Down Expand Up @@ -74,7 +74,7 @@ The [Microsoft.Data.Sqlite](/dotnet/api/microsoft.data.sqlite) library implement

The rest of this guide helps you to use this library.

## Set up your solution to use the Microsoft.Data.SQLite library
## Set up your solution to use the Microsoft.Data.Sqlite library

We'll start with a basic WinUI project, and then install the SQLite NuGet package. See [Create a WinUI app](/windows/apps/tutorials/winui-notes/intro) for instructions on how to create your first WinUI project.

Expand All @@ -94,7 +94,7 @@ Let's start by adding a class to your project named **DataAccess**. If you plan

At this point, you have a choice. You can use the version of SQLite that is included with Windows or if you have some reason to use a specific version of SQLite, you can include the SQLite library in your package. We are going to use the version of SQLite that's included with Windows.

1. Choose the **Browse** tab, search for the **Microsoft.Data.SQLite** package, and then install the latest stable version.
1. Choose the **Browse** tab, search for the **Microsoft.Data.Sqlite** package, and then install the latest stable version.

![SQLite NuGet package](images/sqlite-nuget-package.png)

Expand Down Expand Up @@ -130,6 +130,7 @@ Add the following `using` statements to the top of this file.
```csharp
using Microsoft.Data.Sqlite;
using System.Collections.Generic;
using Windows.Storage;
```

### Initialize the SQLite database
Expand Down Expand Up @@ -163,7 +164,7 @@ public async static void InitializeDatabase()

This code creates the SQLite database and stores it in the application's local data store.

In this example, we name the database `sqlliteSample.db` but you can use whatever name you want as long as you use that name in all [SqliteConnection](/dotnet/api/microsoft.data.sqlite.sqliteconnection) objects that you instantiate. In a production application, connection information such as the database filename should be stored in app configuration rather than hard-coded (see [**Adding Azure App Configuration by using Visual Studio Connected Services**](/visualstudio/azure/vs-azure-tools-connected-services-app-configuration)).
In this example, we name the database `sqliteSample.db` but you can use whatever name you want as long as you use that name in all [SqliteConnection](/dotnet/api/microsoft.data.sqlite.sqliteconnection) objects that you instantiate. In a production application, connection information such as the database filename should be stored in app configuration rather than hard-coded (see [**Adding Azure App Configuration by using Visual Studio Connected Services**](/visualstudio/azure/vs-azure-tools-connected-services-app-configuration)).

In the constructor of the **App.xaml.cs** file of your project, call the `InitializeDatabase` method of the `DataAccess` class. This will ensure that the database is created or opened each time the app starts.

Expand Down Expand Up @@ -232,7 +233,7 @@ public static List<string> GetData()

The [Read](/dotnet/api/microsoft.data.sqlite.sqlitedatareader.read#Microsoft_Data_Sqlite_SqliteDataReader_Read) method advances through the rows of returned data. It returns `true` if there are rows left, otherwise it returns `false`.

The [GetString](/dotnet/api/microsoft.data.sqlite.sqlitedatareader.getstring#Microsoft_Data_Sqlite_SqliteDataReader_GetString_System_Int32_) method returns the value of the specified column as a string. It accepts an integer value that represents the zero-based column ordinal of the data that you want. You can use similar methods such as [GetDataTime](/dotnet/api/microsoft.data.sqlite.sqlitedatareader.getdatetime#Microsoft_Data_Sqlite_SqliteDataReader_GetDateTime_System_Int32_) and [GetBoolean](/dotnet/api/microsoft.data.sqlite.sqlitedatareader.getboolean#Microsoft_Data_Sqlite_SqliteDataReader_GetBoolean_System_Int32_). Choose a method based on what type of data the column contains.
The [GetString](/dotnet/api/microsoft.data.sqlite.sqlitedatareader.getstring#Microsoft_Data_Sqlite_SqliteDataReader_GetString_System_Int32_) method returns the value of the specified column as a string. It accepts an integer value that represents the zero-based column ordinal of the data that you want. You can use similar methods such as [GetDateTime](/dotnet/api/microsoft.data.sqlite.sqlitedatareader.getdatetime#Microsoft_Data_Sqlite_SqliteDataReader_GetDateTime_System_Int32_) and [GetBoolean](/dotnet/api/microsoft.data.sqlite.sqlitedatareader.getboolean#Microsoft_Data_Sqlite_SqliteDataReader_GetBoolean_System_Int32_). Choose a method based on what type of data the column contains.

The ordinal parameter isn't as important in this example because we are selecting all of the entries in a single column. However, if multiple columns are part of your query, use the ordinal value to obtain the column you want to pull data from.

Expand Down
4 changes: 2 additions & 2 deletions hub/apps/develop/files/change-tracking-filesystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ms.localizationpriority: medium

- [StorageLibraryChangeTracker](/uwp/api/Windows.Storage.StorageLibraryChangeTracker)
- [StorageLibraryChangeReader](/uwp/api/windows.storage.storagelibrarychangereader)
- [StorageLibraryChangedTrigger](/uwp/api/Windows.ApplicationModel.Background.StorageLibraryContentChangedTrigger)
- [StorageLibraryContentChangedTrigger](/uwp/api/Windows.ApplicationModel.Background.StorageLibraryContentChangedTrigger)
- [StorageLibrary](/uwp/api/windows.storage.storagelibrary)

The [StorageLibraryChangeTracker](/uwp/api/Windows.Storage.StorageLibraryChangeTracker) class allows apps to track changes in files and folders as users move them around the system. These WinRT APIs can be used from WinUI 3 apps built with the Windows App SDK targeting Windows 10, version 1809 (build 17763) or later. The underlying `StorageLibraryChangeTracker` API is available starting with Windows 10, version 1803 (build 17134). Using the StorageLibraryChangeTracker class, an app can track:
Expand Down Expand Up @@ -70,7 +70,7 @@ A few important notes:

### Wait for changes

After the change tracker is initialized, it will begin to record all of the operations that occur within a library, even while the app isn’t running. Apps can register to be activated any time there is a change by registering for the [StorageLibraryChangedTrigger](/uwp/api/Windows.ApplicationModel.Background.StorageLibraryContentChangedTrigger) event.
After the change tracker is initialized, it will begin to record all of the operations that occur within a library, even while the app isn’t running. Apps can register a background task that uses the [StorageLibraryContentChangedTrigger](/uwp/api/Windows.ApplicationModel.Background.StorageLibraryContentChangedTrigger) trigger to be activated any time there is a change.

![Changes being added to the change tracker without the app reading them](images/changetracker-waiting.png)

Expand Down
6 changes: 3 additions & 3 deletions hub/apps/develop/files/create-read-write-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Windows::Foundation::IAsyncAction ExampleCoroutineAsync()
```

```cppwinrt
Windows::Storage::Streams::DataWriter dataWriter;
Windows::Storage::Streams::DataWriter dataWriter{ outputStream };
dataWriter.WriteString(L"DataWriter has methods to write to various types, such as DataTimeOffset.");
// The code in step 4 goes here.
```
Expand All @@ -212,8 +212,8 @@ Windows::Foundation::IAsyncAction ExampleCoroutineAsync()
```

```cppwinrt
dataWriter.StoreAsync();
outputStream.FlushAsync();
co_await dataWriter.StoreAsync();
co_await outputStream.FlushAsync();
```


Expand Down
2 changes: 1 addition & 1 deletion hub/apps/develop/files/music-pictures-videos-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ To get notified about changes to the list of folders in a library, register a ha


```csharp
myPictures.DefinitionChanged += MyPictures_DefinitionChanged;
myPictures.DefinitionChanged += HandleDefinitionChanged;

void HandleDefinitionChanged(Windows.Storage.StorageLibrary sender, object args)
{
Expand Down
10 changes: 5 additions & 5 deletions hub/apps/develop/files/pickers-save-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ Before you start, make sure you have:
The following APIs are used in this topic:

- [FileSavePicker](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.filesavepicker)
- [StorageFile](/uwp/api/Windows.Storage.StorageFile)
- [PickFileResult](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.pickfileresult)

Use the [FileSavePicker](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.filesavepicker) to allow users to specify the name and location where they want your app to save a file.

## Save a document with FileSavePicker

Use a [FileSavePicker](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.filesavepicker) so that your users can specify the name, type, and location of a file to save. Create, customize, and show a file picker object, and then save data via the returned [StorageFile](/uwp/api/Windows.Storage.StorageFile) object that represents the file picked.
Use a [FileSavePicker](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.filesavepicker) so that your users can specify the name, type, and location of a file to save. Create, customize, and show a file picker object, and then save data by using the returned [PickFileResult](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.pickfileresult), which contains the picked file path. If you need the file name, derive it from that path.

1. Create and customize the FileSavePicker. Start by creating a new [FileSavePicker](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.filesavepicker) object, and then set properties on the object to customize the file picker for your app and your users:

Expand Down Expand Up @@ -93,7 +93,7 @@ Use a [FileSavePicker](/windows/windows-app-sdk/api/winrt/microsoft.windows.stor

// (Optional) Sets the folder that the file save dialog displays when it opens.
// If not specified or the specified path doesn't exist, defaults to the last folder the user visited.
savePicker.SuggestedFolder = L"C:\\MyFiles",
savePicker.SuggestedFolder = L"C:\\MyFiles";

// (Optional) specify the text displayed on the commit button.
// If not specified, the system uses a default label of "Save" (suitably translated).
Expand Down Expand Up @@ -122,7 +122,7 @@ Use the [FileTypeChoices](/windows/windows-app-sdk/api/winrt/microsoft.windows.s
> [!NOTE]
> [FileSavePicker](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.filesavepicker) objects display the file picker using the [PickerViewMode.List](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.pickerviewmode) view mode.

2. Next, show the **FileSavePicker** and save to the picked file location. Display the file picker by calling [PickSaveFileAsync](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.filesavepicker.picksavefileasync). After the user specifies the name, file type, and location, and confirms to save the file, **PickSaveFileAsync** returns a lightweight [FilePickResult](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.pickfileresult) object that contains the path to the saved file and the filename. You can capture and process this file if you have read and write access to it.
2. Next, show the **FileSavePicker** and save to the picked file location. Display the file picker by calling [PickSaveFileAsync](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.filesavepicker.picksavefileasync). After the user specifies the name, file type, and location, and confirms to save the file, **PickSaveFileAsync** returns a lightweight [PickFileResult](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.pickfileresult) object that contains the path to the saved file. If you need the file name, derive it from that path. You can capture and process this file if you have read and write access to it.

```csharp
using Microsoft.Windows.Storage.Pickers;
Expand Down Expand Up @@ -186,7 +186,7 @@ The example checks if the file exists and either creates a new file or appends t

## Related content

[Windows.Storage.Pickers](/uwp/api/windows.storage.pickers)
[Microsoft.Windows.Storage.Pickers](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers)

[Files, folders, and libraries with Windows App SDK](index.md)

Expand Down
6 changes: 2 additions & 4 deletions hub/apps/develop/files/using-file-folder-pickers.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ else

## Pick multiple files to open example

You can also let the user pick multiple files. The following code shows how to use the [FileOpenPicker](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.fileopenpicker) class to let the user pick multiple files, such as photos. The process is the same but the [PickMultipleFilesAsync](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.fileopenpicker.pickmultiplefilesasync) method returns a collection of file paths instead of a single path.
You can also let the user pick multiple files. The following code shows how to use the [FileOpenPicker](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.fileopenpicker) class to let the user pick multiple files, such as photos. The process is the same but the [PickMultipleFilesAsync](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.fileopenpicker.pickmultiplefilesasync) method returns a collection of [PickFileResult](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.pickfileresult) objects. Each result exposes a `Path` property when you need the raw file path.

```csharp
using Microsoft.Windows.Storage.Pickers;
Expand Down Expand Up @@ -242,8 +242,6 @@ The folder picker UI looks like this:

## Related content

[Windows.Storage.Pickers](/uwp/api/windows.storage.pickers)
[Microsoft.Windows.Storage.Pickers namespace](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers)

[Files, folders, and libraries with Windows App SDK](index.md)

[Microsoft.Windows.Storage.Pickers namespace](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers)
2 changes: 1 addition & 1 deletion hub/apps/develop/launch/handle-uri-activation.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ The following code programmatically launches the app via its URI:
```csharp
// Launch the URI
var uri = new Uri("alsdk:");
var success = await Windows.System.Launcher.LaunchUriAsync(uri)
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
```

For more details about how to launch an app via a URI, see [Launch the default app for a URI](launch-default-app.md).
Expand Down
Loading