So we have to use Windows Runtime Component to access Native C# methods as discussed in my previous blog: WinJS application with Windows Runtime Component to access Native C# Code.
Please go through these links.
I will show you how to pass a string as a parameter from our html page to Runtime Component and create a folder with the same name using IAsyncOperation.
Step 1:
Firstly, create a WinJS project as discussed in my previous blog: Create your first WinJS application
Step 2:
We need to do the following things as discussed in my previous article.
Add a Windows Runtime Component project and nameit ‘WinRuntimes’.
Delete default class ‘Class1.cs’.
Add a new class and name it ‘Service’.
Add WinRuntimesreference in WinJS project.
Build the project.
Step 3:
In Service class, we have to create IAsyncOperation with the return type string as:
- public IAsyncOperation<string> CreateFolder(string folderName)
- {
- return CreateFolderHelper(folderName).AsAsyncOperation();
- }
And its helper class as:
- private async Task<string> CreateFolderHelper(string folderName)
- {
- try
- {
- StorageFolder folder = ApplicationData.Current.LocalFolder;
- await folder.CreateFolderAsync(folderName);
- return "success";
- }
- catch (Exception ex)
- {
- return "fail";
- }
- }
Complete code snippet for Service class is:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Windows.Foundation;
- using Windows.Storage;
- namespace WinRuntimes
- {
- public sealed class Service
- {
- #region Asynchronous Interface Methods
- public IAsyncOperation<string> CreateFolder(string folderName)
- {
- return CreateFolderHelper(folderName).AsAsyncOperation();
- }
- #endregion
- #region Helpers
- private async Task<string> CreateFolderHelper(string folderName)
- {
- try
- {
- StorageFolder folder = ApplicationData.Current.LocalFolder;
- await folder.CreateFolderAsync(folderName);
- return "success";
- }
- catch (Exception ex)
- {
- return "fail";
- }
- }
- #endregion
- }
- }



Vignesh ManiPosted Apr 20, 2016, 4:02 PM
Good one
Rahul Kumar SaxenaPosted Apr 19, 2016, 11:05 PM
Good Show
Sr KarthigaPosted Apr 19, 2016, 10:06 PM
good one
Sr KarthigaPosted Apr 19, 2016, 10:06 PM
Nice explanation
Kuppurasu NagarajPosted Apr 19, 2016, 12:56 PM
Nice..
Debasis SahaPosted Apr 19, 2016, 10:31 AM
Good...