WinPhone accessing local file - windows-phone-8

In Windows Phone I have a PDF stored here:
ApplicationData.Current.LocalFolder / myfile.pdf
How can I open that PDF for viewing?

You have to use the LaunchFileAsync method of Launcher class. Example:
// Access the file.
StorageFile pdfFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("file.pdf");
Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("file.pdf");
Windows.System.Launcher.LaunchFileAsync(pdfFile);

Did you try using LaunchFileAsyncto open your PDFfile?
How to open pdf file in Windows Phone 8?

Related

write and read html file from webview windows 8 store app

I have a requirement to produce reports in html (So they can be styles via css etc...) The application is a Windows 8 Store App.
I have created a template and am able to produce the html file. I initially saved it here
Windows.ApplicationModel.Package.Current.InstalledLocation
Great right? wrong! The WebView control will not read from that location!
I also tried writing to the Assets folder of my app. Nope! Permission Denied.
Windows 8 store apps have limited rights to the folder system.
Question:
Where can I put dynamically generated html files (run time) so that they can be read by the WebView Control?
Thanks for any feedback.
In case anyone else has had this problem, or like me you are new to windows store development. Here is the answer (Got help from pluralsight)
Code:
StorageFile file = await destFolder.GetFileAsync(fileName);
string url = "ms-appdata:///local/Estimates/" + fileName;

How To Open PDFdocument Through Windows Phone 8 App Which Is From Asset Folder

I need to open a pdf document file from the asset folder from windows phone 8 app. First I need to check whether any pdf reader is available or not and if available, the pdf document should be opened from the asset folder.
There are two ways of using a file. You can mark it as
Resource Files: Data files that are compiled into either an executable or library assembly. To access a resource,
Example :
Stream jsStream = Application.GetResourceStream(new Uri("folder\\e_data.pdf",UriKind.Relative)).Stream;
Content Files: Standalone data files that have an explicit association with an executable assembly.
To access content file, use
Uri filePath = new Uri(#"ms-appx:///example.pdf");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync();
EXAMPLE
Mark the pdf file as content in properties -> build action.
async void openPDF()
{
Uri filePath = new Uri(#"ms-appx:///example.pdf");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(filePath);
//For opening that file,
if (file != null)
await Launcher.LaunchFileAsync(file);
}

Windowsphone - How to Make App can open Some Fileformats

i have a question
i want to know how can i open downloaded file in my app (like when you download .PDF File in Internet Explorer it shows apps that can open .PDF files )
please help me snippet of codes !
first you have to save your file in isolated storage and you need to use launcher this code would help you:
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
// Access the bug query file.
StorageFile yourfile = await local.GetFileAsync("Pradeep.pdf");
// Launch the bug query file.
Windows.System.Launcher.LaunchFileAsync(yourfile);
}
this launcher is available in windows phone 8 only.
As stated in MSDN :
"You can use file and URI associations in Windows Phone 8 to automatically launch your app when another app launches a specific file type or URI scheme. When launched, a deep link URI is used to send the file (a reference to the file) or URI to your app."
Basically you need to do following steps :
Register your application to be associated to a specific file type, for example .pdf file extension in this case. This step done by adding <Extension> in WMAppManifest.xml.
When your application get launched upon user opening a .pdf file, get file id from query string then get the physical file using SharedStorageAccessManager based on file id.
The rest is to handle opening the file in your application.
I found this very nice blog explaining the detail of every steps, accompanied with downloadable source code.
PART I: explaining background concept and creating application to launch associated file
PART II: explaining details of step 1-3 above with sample application

Opening html file from IsolatedStorage in a WebBrowser componenet in Windows Phone

I have stored an HTML file in IsolatedStorage as test.html.
In UI I have a WebBrowser component called browser. I'm using the following code to show the webpage in the browser:
browser.Navigate(new Uri("isostore:/test.html", UriKind.Absolute));
However it's giving me the prompt to search for an app in store, as if I'm trying to use LaunchUriAsync or LaunchFileAsync API.
I guess the problem is with the Uri format. What should be the correct Uri format in this case?
I have solved it, by removing 'isostore:/' prefix from the Uri string. I know that without any prefix the file path would refer to the application folder, not the isolated storage. It seems they've made an exception for the WebBrowser component.
This is what works now:
browser.Navigate(new Uri("test.html", UriKind.Relative));
C:/Data/Users/DefApps/AppData/{43F7CB8F-D4CF-425D-96BD-CD96D3FF44DC}/Local/test.html
The path above is an alternative and absolute path to the isolated storage. This string, {43F7CB8F-D4CF-425D-96BD-CD96D3FF44DC}, is unique to the app but can be set/found from within the properties folder of your visual studio project. You can also obtain it by using the following lines in the C# code:
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
String mystring = localFolder.Path;

Is it possible to save pdf file in media library in Windows phone8

Is it possible to save a PDF file to the media library in Windows Phone 8? If it is, how do I do that?
Media Library allows you to save Images. That's it. No PDFs and nothing else