locked
how to call c# function from javascript

    Question

  • Hi,

     how to call this c#(windows runtime component) function from javascript/html5 windows store app.
    public IAsyncOperationWithProgress<int, double> Uncompress(StorageFile File,StorageFolder Destination)
            {
               // StorageFile File1=new StorageFile();
    
                return AsyncInfo.Run<int, double>((Token, Progress) =>
                {
                    return Task.Run(async () =>
                    {
                        Progress.Report(0);
                        await UnZipFile(File,Destination);
                        Token.ThrowIfCancellationRequested();
                        Progress.Report(100.0);
                        return 0;
                    }, Token
                      );
    
                });
            }

    Wednesday, December 11, 2013 10:11 AM

Answers

  • getFileFromPathAsync or getFileFromApplicationUriAsync can be used to get storage file. 

    Windows.Storage.ApplicationData.localFolder etc. can be used to get be used to get storage folder depending on what folder is needed.


    -sushil

    Thursday, December 12, 2013 3:56 AM
  • Hi suganthe,

    Without the user permission(filepicker), you can only access the KnownFolders class, see this for more: File access and permissions.

    Windows.Storage classes is also available in WinJS, therefore you could directly use StorageFile or StorageFolder.

    var folder = Windows.Storage.KnownFolders.documentsLibrary;
    var file = folder.getFileAsync(name);

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, December 12, 2013 6:00 AM
    Moderator

All replies

  • Check this walkthrough: http://msdn.microsoft.com/en-us/library/windows/apps/hh779077.aspx

    It shows how you can use the .NET Framework with Visual Basic or C# to create your own Windows Runtime types, packaged in a Windows Runtime component, and how to call the component from your Windows Store app built for Windows using JavaScript.


    Kunal G

    Wednesday, December 11, 2013 10:43 AM
  • Hi kunal,

         I have read that walkthrough.could you tell me how to give input for (storagefile File,storageFolder Destination) from javascript without using filepicker

    Wednesday, December 11, 2013 10:52 AM
  • getFileFromPathAsync or getFileFromApplicationUriAsync can be used to get storage file. 

    Windows.Storage.ApplicationData.localFolder etc. can be used to get be used to get storage folder depending on what folder is needed.


    -sushil

    Thursday, December 12, 2013 3:56 AM
  • Hi suganthe,

    Without the user permission(filepicker), you can only access the KnownFolders class, see this for more: File access and permissions.

    Windows.Storage classes is also available in WinJS, therefore you could directly use StorageFile or StorageFolder.

    var folder = Windows.Storage.KnownFolders.documentsLibrary;
    var file = folder.getFileAsync(name);

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, December 12, 2013 6:00 AM
    Moderator