2

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?

moshfiqur
  • 2,065
  • 3
  • 24
  • 27

1 Answers1

6

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.

Thavamani
  • 2,096
  • 1
  • 14
  • 13
  • your solution will read the file content and show it. What I need is clicking a file link, it will be open by associated application. For example, clicking on a pdf file link will open the file with adobe acrobat reader, text file with notepad, html file with firefox browser and so on... – moshfiqur May 05 '13 at 13:54
  • Mr sparrow its possible.i edited my post there you can get solution to your problem. – Thavamani May 06 '13 at 05:31
  • Ti.Filesystem.getFileStream(readFi); this line has typo 'readfi' it should be. :) – Abibullah Rahamathulah Oct 07 '13 at 08:42
  • Is it possible to edit this to get an images' src data as opposed to just reading a text file? – Ark-of-Ice Nov 15 '13 at 20:04