0

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.

Nitesh Kothari
  • 890
  • 12
  • 27
  • The error occurs from which line of code? and what is the exception type? – kennyzx Sep 17 '14 at 10:21
  • @kennyzx error is not occuring in between codes, after I click on document for opening, a message box appears and give me message like this: "Can't be open". Thank you. Please suggest me – Nitesh Kothari Sep 17 '14 at 10:44
  • @kennyzx see my edit and screen shot. thank you brother!!! – Nitesh Kothari Sep 17 '14 at 10:49
  • `it is created in other software`, how other software writes to the app's local folder? From your code, I see this file is created by the app: `var filerun = await ApplicationData.Current.LocalFolder.CreateFileAsync(file);` – kennyzx Sep 17 '14 at 13:01
  • @kennyzx, yes, I meant it is created in "Open Office Software" and I want to open this document, I do not know much about this issue, so I am sorry about it. But how to solve it? Please tell me!! – Nitesh Kothari Sep 17 '14 at 13:09
  • OK, I understand your question and I can recreate it on my side. It looks like a limitation, ironically, you cannot launch a file created with Office hub, but only open _within_ the hub. – kennyzx Sep 17 '14 at 15:52
  • similar question: [http://stackoverflow.com/questions/25052194/how-to-open-documents-and-images-using-launcher-in-windows-phone-8](http://stackoverflow.com/questions/25052194/how-to-open-documents-and-images-using-launcher-in-windows-phone-8) – kennyzx Sep 17 '14 at 15:55

1 Answers1

2

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

kennyzx
  • 12,845
  • 6
  • 39
  • 83