Nitesh Kothari
Nitesh Kothari

Reputation: 888

Document opening issue in Windows Phone 8.1

enter image description hereenter image description here

I am creating Windows Phone 8.1 application, I am trying to open document using launcher, but getting exception, and document is not MS OFFICE document, it is created in other software. Here is my code.

string file = "readme.txt";
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();

if (isf.FileExists(file))
{
   isf.DeleteFile(file);
}

var filerun = await ApplicationData.Current.LocalFolder.CreateFileAsync(file);
await Launcher.LaunchFileAsync(await ApplicationData.Current.LocalFolder.GetFileAsync(file));

I am getting error like this:

"Can't be Open, File Format doesn't recognize"

and sometimes like this:

"Document has been damaged"

I do not know how to deal with this, I am stuck here, Any help would be greatly appreciated.

Upvotes: 0

Views: 1016

Answers (1)

kennyzx
kennyzx

Reputation: 12993

The file name without extension is "campaign rev 2", so the file pass to the launcher is definitely not "readme.txt".

You can pass a LauncherOptions.DisplayApplicationPicker to the LaunchFileAsync method.

var filerun = await ApplicationData.Current.LocalFolder.CreateFileAsync(file);
var options = new Windows.System.LauncherOptions(){ DisplayApplicationPicker = true};
await Launcher.LaunchFileAsync(filerun, options);

It will open a list of applications for you to choose from, so you can examine the file extension is actually .txt or .xls/.xlsx (Excel).

According to the documentation, this overload is available on Windows Phone 8.1. But I have not upgraded to 8.1 yet, so I can not give you a screenshot of the Application Picker.

Screenshot from the web. Hope this helps.

enter image description here

Upvotes: 2

Related Questions