Skip to content
Merged
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
9 changes: 9 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@
</config-file>
<source-file src="src/android/FileOpener.java" target-dir="src/com/phonegap/plugins/fileopener" />
</platform>

<platform name="wp8">
<config-file target="config.xml" parent="/*">
<feature name="FileOpener">
<param name="wp-package" value="FileOpener"/>
</feature>
</config-file>
<source-file src="src/wp/FileOpener.cs" />
</platform>
</plugin>
50 changes: 50 additions & 0 deletions src/wp/FileOpener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Sergey Grebnov. Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using WPCordovaClassLib.Cordova.Commands;

namespace WPCordovaClassLib.Cordova.Commands
{
public class FileOpener : BaseCommand
{
async public void openFile(string options)
{
var optStings = JSON.JsonHelper.Deserialize<string[]>(options);

string filePath = optStings[0].Replace('/', '\\').Substring(2);

try
{

StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile file = await local.GetFileAsync(filePath);

if (file == null)
{
this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "File not found: " + filePath));
return;
}

var success = await Windows.System.Launcher.LaunchFileAsync(file);

if (success)
{
this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
}
else
{
this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Unable to start the app associated with the following file: " + filePath));
}
}
catch (Exception ex) {
this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ex.Message));
}
}
}
}