Windowsphone - How to Make App can open Some Fileformats - windows-phone-8

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

Related

UWP - How to read .jpg from Desktop inside of app

The functionality I am needing for my app is that if a user copies an image file (for example, a .jpg file in their Desktop folder), I need to extract that file from the clipboard and display it in my app.
I can already extract the storage file from the clipboard, and get the file path. But when I try to read the file path into a BitmapImage, I received a System.UnauthorizedAccessException error, because the image is not located in the app's folder.
It sounds like you are trying to open the file by path rather than directly using the StorageFile returned by the file picker.
Your app doesn't have direct access to most of the file system (including the downloads directories) and can access such files only indirectly via the file system broker. The StorageFile object works with the broker to open files the use had authorized and provides a stream of the files contents for the app to read and write to.
You can use Xamarin.Plugin.FilePicker or FilePicker-Plugin-for-Xamarin-and-Windows .
You may x:Bind path to XAML Image
<Image>
<Image.Source>
<BitmapImage UriSource="{x:Bind GetAbsoluteUri(Path)}"/>
</Image.Source>
</Image>
Code behind:
private Uri GetAbsoluteUri(string path)
{
return new Uri(Path.GetFullPath(path), UriKind.Absolute);
}
Try, hope it'll work :)

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;

AS3: Download a download embedded file to desktop without browser

I'm creating an flash app where users can select something and download a temple. I'm publishing this file using air application with runtime embedded. In the app I've included a folder called documents with the individual files the user can download. Currently I'm using navigateToURL but I don't want it to rely on the browser. I've also tried this:
function surveyDownload(evt:MouseEvent):void {
var request = new URLRequest("document/template.docx");
var localRef = new FileReference();
try
{
// Prompt and download file
localRef.download( request );
}
catch (error:Error)
{
trace("Unable to download file.");
}
}
but all I get is the trace statement "Unable to download file".
How can I download an embedded file without the browser?
Your question is a little unclear. You want the user to download something from a server? If so then document/template.docx is not a URL so of course that will not work.
If you are talking about copying a file out of the AIR app bundle to the user's hard drive then you don't need URLRequest but rather the methods in the File class (browseForSave and copyTo).
Read the docs for File and search out some tutorials – there are loads and more complete than I would write here.

how to get browsed file location by user when he wants to download a file

this is my html code to make user to download a file and it is hitting controller
window.location.href="#routes.ListManagementController.downloadList("+listName+")?listname="+listName;
this is my controller code:
String listName = Form.form().bindFromRequest().get("listname");
response().setContentType("application/x-download");
response().setHeader("Content-disposition", "attachment;filename="+listName+"_data_export.csv");
The above two respose() statements make a pop up to download a file I want the browsed file location
File file = new File("C:/csv/" + filename);
So, using servlet api we can write the content into browsed file location using respose.getOutputStream() method. In play there are is no support for servlet. I want browsed file location selected by user so that i can give that location to File and write the file over there.
You can't get the location of a directory on the client, and even if you could, your server side could wouldn't be able to write to it (since it would usually be on a different computer).

How can I run a command in windows store app?

I need to run a command from windows store app?
the command is something like this : java -jar abc.jar
How can I do that?
EDIT :
I tried this but with no luck. It says file not found.
string exeFile = #"C:\DATA\start.bat";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(exeFile);
if (file != null)
{
// Set the option to show the picker
var options = new Windows.System.LauncherOptions();
options.DisplayApplicationPicker = true;
// Launch the retrieved file
bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
if (success)
{
// File launched
}
else
{
// File launch failed
}
}
The app container blocks this behavior for Store apps.
First of all, you're attempting to obtain a StorageFile through your package InstalledLocation folder, which will not work. InstalledLocation is a StorageFolder, and its GetFileAsync looks for files only within that immediate folder. This is why it's returning file not found.
The API that takes an arbitrary path is Windows.Storage.StorageFolder.GetFileFromPathAsync. However, your ability to access files is limited by the app container. You can access files in your package folder or app data locations by default, or the various media libraries if you've declared access in the manifest, but otherwise you have to go through the file picker so the user is aware of what you're doing and can grant consent. Simply said, this is the only way you'll get to a file in a location like c:\data. You can play with this using Scenario 1 of the Association launching sample and the "Pick and Launch" button.
If you can get that access permission, then in you'll be able to launch a file if it's not a blocked file type. Data files (like a .docx) that are associated with another app work just fine, but executables are wholly blocked for what should be obvious security reasons. You can try it with the sample I linked to above--pick .bat, .cmd, .exe, .msi, etc. and you'll see that LaunchFileAsync fails.
Also note that the other launcher function, LaunchUriAsync, also blocks file:/// for the same reasons.