简体   繁体   中英

How to open local file from Tide SDK app

I am building an windows app using Tide SDK. How can I open a local file from my app. For example, I have a pdf file somewhere in my harddisk. I put the link to that file to my app. When I click on the link, I want it to open the pdf file using default programm associated with pdf type file.

If it is not possible then I have one more general question. Is it possible to access local file system by any app that built using html5 and javascript?

we can access local file system in tidesdk application.

See the following code.

var contents;      
var file= 'test.txt';      
var Dir = Ti.Filesystem.getUserDirectory();        
var readfi= Ti.Filesystem.getFile(Dir, file);      
if (readfi.exists())
{     
   var Stream = Ti.Filesystem.getFileStream(readFi);    
   Stream.open(Ti.Filesystem.MODE_READ);     
   contents =Stream.read();  
   alert( contents );  
   Stream.close();    
} 

The above code will read the text file and alert the content. Visit here to know tidesdk file system.

Following code will open the given URL in default browser.

Ti.Platform.openURL('http://stackoverflow.com');

Following code will Open the given application or file in the system's default program.

Ti.Platform.openApplication('C:/Documents and Settings/Thavamani00/Desktop/readme.txt');
Ti.Platform.openApplication('C:/Documents and Settings/Thavamani00/Desktop/cart15.png');

The above code displays the text file in notepad and displays the image in mircosoft picture manager.

it works well for me.i hope its your required answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM