Free Code Snippets in C#, Net Framework, Office 365, ASP.Net,WPF, Visual Studio, SQL Server, Antivirus free
#

WPF, Bridge: File access with Windows 10 under Win32

 

The functionality of the UWP Windows 10 can be integrated under Windows 32 WPF / WinForms.

Then you can open and manage files with asynchronous access as a storage file.

In contrast to UWP you have the complete access to all files of the computer and does not open the files with URI path directly with GetFileFromPath

async Task<bool> set_UWP_Wallpaper_Async(string sFilename)

    {..

    //----< Profile Setting allowed >----

    string sFilename_with_Path = "C:\\_Daten\\Desktop\\Backgrounds\\" + sFilename ;

 

    //< get File >

    //*file under win32

    //*using Windows.Storage

    StorageFile file = await StorageFile.GetFileFromPathAsync(sFilename_with_Path);

    //</ get File >

..

 

In debug mode you can see that the file has been opened as Windows.Storage.Storagefile and all possibilities of Windows 10 are available.

 

async Task<bool> set_UWP_Wallpaper_Async(string sFilename)

        {

            //------------< set_UWP_Wallpaper_Async() >------------

            bool success = false;

            if (UserProfilePersonalizationSettings.IsSupported())

            {

    //----< Profile Setting allowed >----

    string sFilename_with_Path = "C:\\_Daten\\Desktop\\Backgrounds\\" + sFilename ;

 

    //< get File >

    //*file under win32

    //*using Windows.Storage

    StorageFile file = await StorageFile.GetFileFromPathAsync(sFilename_with_Path);

    //</ get File >

 

    //< set profile >

    UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;

    //</ set profile >

 

    //< change Background >

    success = await profileSettings.TrySetWallpaperImageAsync(file);

    //</ change Background >

 

 

    MessageBox.Show(  DateTime.Now.ToString() + " file=" + file.Path + " success=" + success);

    //----</ Profile Setting allowed >----

    //------------</ set_UWP_Wallpaper_Async() >------------

            }

 

 

To work with Windows 10 API commands on Windows 32 WPF, Winforms, you need to include the Windows 10 Kit files as a reference

 

Under References you have to include the Window 10 references with References-> Add

Windows.winmd

And System.Runtime.WindowsRuntime.dll

 

 

Debug at the holding position

file      {Windows.Storage.StorageFile}   Windows.Storage.StorageFile

 

Mobile
»
WPF, Bridge: StorageFile access with Windows 10 under Win32

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de