c# - How can I open a file I've added to my Windows Store App project programatically? -


i want load pdf file in response tapped event.

i added file project (add > existing item), set "build action" "content" , "copy output directory" "copy if newer"

i'm thinking code need may this:

async task loadtutorial() {     await launcher.launchuriasync(new uri("what should here access output folder?")); } 

if i'm right, need pass uri? otherwise, how accomplished?

update

on related note, add image xaml using suggested scheme, thought work:

<image source="ms-appx:///assets/axxandspacelogo.jpg"></image> 

...but doesn't.

update 2

trying open pdf file (which located in root of project, not in subfolder):

async private void opentutorial() {     istoragefolder folder = windows.applicationmodel.package.current.installedlocation;     istoragefile file = await folder.getfileasync("ms-appx:///platypustutorial.pdf");     await launcher.launchfileasync(file); } 

...resulted in runtime exception, thrown on first line above:

enter image description here

update 3

and this, adapted link provided:

var uri = new system.uri("ms-appx:///clayshannonresume.pdf"); var file = windows.storage.storagefile.getfilefromapplicationuriasync(uri); await launcher.launchfileasync(file); 

...i compile time errors:

the best overloaded method match 'windows.system.launcher.launchfileasync(windows.storage.istoragefile)' has invalid arguments

-and:

argument 1: cannot convert 'windows.foundation.iasyncoperation' 'windows.storage.istoragefile'

...on last line.

update 4

according page 76 of "pro windows 8 programming" lecrenski, netherlands, sanders, , ashely, should work:

<image source="assets/axxandspacelogo.jpg" stretch="none"></image> 

...(iow, "ms-appx:///" jazz unnecessary), , more or less does. in particular case, (large) image, had this:

<image source="assets/axxandspacelogo.jpg" width="120" height="80" horizontalalignment="left"></image> 

without width , height settings, image displayed bigger rhinoceros, , hugging right side of flyout.

update 5

i find works open pdf file ("platypustut.pdf" has been added project, "build action" set "content" , "copy output diretory" set "copy if newer"):

istoragefolder folder = windows.applicationmodel.package.current.installedlocation; istoragefile file = await folder.getfileasync("platypustut.pdf"); bool success = await launcher.launchfileasync(file); if (!success) {     messagedialog dlgdone = new messagedialog("unable open tutorial @ time. try again later.");     await dlgdone.showasync(); } 

...but wonder if work @ design-time, locally. work when installed on user's machines, too? iow, enough pass "platypustut.pdf" getfileasync()?

use ms-appx protocol (e.g. ms-appx:///assets/image.png )to reference items in apps package. see how load file resources (xaml)

update:

use getfilefromapplicationuriasync ms-appx find file in app package. if file marked content , included in app package available once deployed , not in debugger. ms-appx:///platypustut.pdf find platypustut.pdf in root of app package.

storagefile file = await storagefile.getfilefromapplicationuriasync(new uri("ms-appx:///platypustut.pdf")); await launcher.launchfileasync(file); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -