diff --git a/hub/apps/develop/data-access/mongodb-database.md b/hub/apps/develop/data-access/mongodb-database.md index d575a7afec..b99c9df4b1 100644 --- a/hub/apps/develop/data-access/mongodb-database.md +++ b/hub/apps/develop/data-access/mongodb-database.md @@ -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 collection = database.GetCollection("bar"); diff --git a/hub/apps/develop/data-access/mysql-database.md b/hub/apps/develop/data-access/mysql-database.md index 5a8b0fe560..0b8490d5b2 100644 --- a/hub/apps/develop/data-access/mysql-database.md +++ b/hub/apps/develop/data-access/mysql-database.md @@ -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)) { diff --git a/hub/apps/develop/data-access/sql-server-database.md b/hub/apps/develop/data-access/sql-server-database.md index 11faa03d1e..33c41ebf89 100644 --- a/hub/apps/develop/data-access/sql-server-database.md +++ b/hub/apps/develop/data-access/sql-server-database.md @@ -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) @@ -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 GetProducts(string connectionString) { const string GetProductsQuery = "select ProductID, ProductName, QuantityPerUnit," + @@ -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() diff --git a/hub/apps/develop/data-access/sqlite-data-access.md b/hub/apps/develop/data-access/sqlite-data-access.md index fe662de6b0..466f868a66 100644 --- a/hub/apps/develop/data-access/sqlite-data-access.md +++ b/hub/apps/develop/data-access/sqlite-data-access.md @@ -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 @@ -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. @@ -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) @@ -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 @@ -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. @@ -232,7 +233,7 @@ public static List 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. diff --git a/hub/apps/develop/files/change-tracking-filesystem.md b/hub/apps/develop/files/change-tracking-filesystem.md index d4f50bad51..a9e26e86bd 100644 --- a/hub/apps/develop/files/change-tracking-filesystem.md +++ b/hub/apps/develop/files/change-tracking-filesystem.md @@ -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: @@ -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) diff --git a/hub/apps/develop/files/create-read-write-files.md b/hub/apps/develop/files/create-read-write-files.md index d85acf8ba8..41770b5c97 100644 --- a/hub/apps/develop/files/create-read-write-files.md +++ b/hub/apps/develop/files/create-read-write-files.md @@ -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. ``` @@ -212,8 +212,8 @@ Windows::Foundation::IAsyncAction ExampleCoroutineAsync() ``` ```cppwinrt - dataWriter.StoreAsync(); - outputStream.FlushAsync(); + co_await dataWriter.StoreAsync(); + co_await outputStream.FlushAsync(); ``` diff --git a/hub/apps/develop/files/music-pictures-videos-libraries.md b/hub/apps/develop/files/music-pictures-videos-libraries.md index b4351c76ae..a304acfc07 100644 --- a/hub/apps/develop/files/music-pictures-videos-libraries.md +++ b/hub/apps/develop/files/music-pictures-videos-libraries.md @@ -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) { diff --git a/hub/apps/develop/files/pickers-save-file.md b/hub/apps/develop/files/pickers-save-file.md index 925857e73e..ece5e9022a 100644 --- a/hub/apps/develop/files/pickers-save-file.md +++ b/hub/apps/develop/files/pickers-save-file.md @@ -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: @@ -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). @@ -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; @@ -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) diff --git a/hub/apps/develop/files/using-file-folder-pickers.md b/hub/apps/develop/files/using-file-folder-pickers.md index b05e20c4cf..ec3fc73492 100644 --- a/hub/apps/develop/files/using-file-folder-pickers.md +++ b/hub/apps/develop/files/using-file-folder-pickers.md @@ -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; @@ -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) diff --git a/hub/apps/develop/launch/handle-uri-activation.md b/hub/apps/develop/launch/handle-uri-activation.md index 178f9fb009..ffe51f0b7e 100644 --- a/hub/apps/develop/launch/handle-uri-activation.md +++ b/hub/apps/develop/launch/handle-uri-activation.md @@ -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). diff --git a/hub/apps/develop/launch/launch-default-apps-settings.md b/hub/apps/develop/launch/launch-default-apps-settings.md index 92b7aae200..f23bfac57d 100644 --- a/hub/apps/develop/launch/launch-default-apps-settings.md +++ b/hub/apps/develop/launch/launch-default-apps-settings.md @@ -32,7 +32,7 @@ There are three query string parameters. The query string parameter to be used d >[!NOTE] >To get the registeredAUMID query string parameter to work after an OS upgrade, an app may need to increment its TargetDeviceFamily...MaxVersionTested value in its manifest. This will ensure that the app is reindexed for the user, which in turn will update the appropriate definitions used to process the deep link via protocol activation. MaxVersionTested should be updated to `10.0.22000.1817` for Windows 11, version 21H2 or `10.0.22621.1555` for Windows 11, version 22H2. -In the following example, `LaunchUriAsync` is called to launch Windows Settings. The `ms-settings:defaultapps` Uri specifies that the Default Apps settings page should be shown. Next, the app that should be launched is determined. As an example, “Microsoft Edge” was registered by the app in HKEY_LOCAL_MACHINE\Software\RegisteredApplications. Since it is a per machine installed app, `registeredAppMachine` is the query string parameter that should be used. The optional query string parameter `registeredAppMachine` is set to the registered name, escaped with a call to `Url.EscapeDataString`, to specify that the page for **Microsoft Edge** should be shown. +In the following example, `LaunchUriAsync` is called to launch Windows Settings. The `ms-settings:defaultapps` Uri specifies that the Default Apps settings page should be shown. Next, the app that should be launched is determined. As an example, “Microsoft Edge” was registered by the app in HKEY_LOCAL_MACHINE\Software\RegisteredApplications. Since it is a per machine installed app, `registeredAppMachine` is the query string parameter that should be used. The optional query string parameter `registeredAppMachine` is set to the registered name, escaped with a URI escaping helper, to specify that the page for **Microsoft Edge** should be shown. ```csharp private async void LaunchSettingsPage_Click(object sender, RoutedEventArgs e) @@ -42,7 +42,7 @@ private async void LaunchSettingsPage_Click(object sender, RoutedEventArgs e) ``` ```cppwinrt -bool result = co_await Windows::System::Launcher::LaunchUriAsync(Windows::Foundation::Uri(L"ms-settings:defaultapps?registeredAppMachine=" + Uri::EscapeDataString(L"Microsoft Edge"))); +bool result = co_await Windows::System::Launcher::LaunchUriAsync(Windows::Foundation::Uri(L"ms-settings:defaultapps?registeredAppMachine=" + Windows::Foundation::Uri::EscapeComponent(L"Microsoft Edge"))); ``` ## Related content diff --git a/hub/apps/develop/launch/launch-the-default-app-for-a-file.md b/hub/apps/develop/launch/launch-the-default-app-for-a-file.md index 663bcdfeed..34dc2512bf 100644 --- a/hub/apps/develop/launch/launch-the-default-app-for-a-file.md +++ b/hub/apps/develop/launch/launch-the-default-app-for-a-file.md @@ -105,7 +105,7 @@ void MainPage::DefaultLaunch() { auto installFolder = Windows::ApplicationModel::Package::Current->InstalledLocation; - concurrency::taskGetFileAsync("images\\test.png")); + concurrency::task getFileOperation(installFolder->GetFileAsync("images\\test.png")); getFileOperation.then([](Windows::Storage::StorageFile^ file) { if (file != nullptr)