open a file

how do you open a file on the mac using XOJO, I don’t need to use getfolderitem that brings up a dialog box. I know where the file is. How do I point XOJO to the file.

GetFolderItem works well for this.

As Paul mentioned, GetFolderItem is what you want. It’s GetOpenFolderItem that shows the dialog.

I made a Service you can use in Finder
Download

  • unzip and copy or move NativePath-Xojo.workflow to ~/Library/Services
    -in Finder - select file - right click - Sevices - NativePath-Xojo
    -set the cursor in Xojo to the place where you want to insert the text
    -hit cmd + v

then the text is inserted, for example

[code]dim f as FolderItem = GetFolderItem _
("/Volumes/Axel_1/Lyrics/PDF.zip", FolderItem.PathTypeNative)
If f <> Nil And f.Exists Then

End If[/code]

First, you need to know the location of the file (the path). If the path is unknown you have to use the open dialog to select the file you want to want to open. (a file can be text, image, whatever)

Once you have the path, you can use the contents of the file in your application or open the file along with its handler (Example: open an excel spreadsheet, opens excel and inside it your spreadsheet), meaning you “launch” it.

To open a png file I have in my desktop and see it on an image well component inside my Xojo App.

Dim f As FolderItem f = GetFolderItem("/Users/MyName/Desktop/mypic.png", FolderItem.PathTypeShell) If f.Exists Then ImageWell1.image = Picture.Open(f) Else MsgBox("The FolderItem does not exist.") End If

To launch it (it opens in preview or whatever default handler you have for pictures in your mac)

Dim f As FolderItem f = GetFolderItem("/Users/MyName/Desktop/mypic.png", FolderItem.PathTypeShell) If f.Exists Then f.Launch Else MsgBox("The FolderItem does not exist.") End If

Hi,

In reply to the original question I like to post the following code :

[code]
Using Xojo.Core
Using Xojo.IO

Dim f_MyFile As FolderItem
Dim tosWrite As TextOutputStream
Dim tisRead As TextInputStream
Dim textRecord As Text
Dim textFileName As Text

// Get a valid FolderItem to create File
textFileName = “MyFile_Chris.txt”
f_MyFile = SpecialFolder.Documents.Child(textFileName)

// Now create the file in encoding UTF16
tosWrite = TextOutputStream.Create(f_MyFile, TextEncoding.UTF16)
tosWrite.WriteLine “First read”
tosWrite.WriteLine “Second read”
tosWrite.close

// Now read those lines back in using UTF16 encoding
tisRead = TextInputStream.Open(f_MyFile, TextEncoding.UTF16)
textRecord = tisRead.ReadLine
MsgBox textRecord
textRecord = tisRead.ReadLine
MsgBox textRecord
tisRead.Close[/code]

This code creates a file in UTF16 encoding and writes two lines to the file. Then it closes and is back opened for reading. Then it reads those two lines back in and make sure the encoding is UTF16.

I download a lot of Paul Lefebvre his webinars because I do not have always internet. After reading Fun with files and Text and Encodings many times, I finally grasped the before subjects completely. Using the new framework (Core and IO) and applying it in practice was not easy, because I was so used to the “string” type.

I post this example in case somebody else also has difficulty adapting to the new framework, those new text types and how to use them properly together with encodings. For me keeping the UTF16 encoding at all times is vital. Not a second may that encoding change in whatever process. The text type gives me that assurance and type of control.

I was very reluctant to change to the text type. I really wanted to stay with String. However despite the fact you can stay with the stringtype, I advice you strongly to make the efforts and adapt to the new framework. It will take some time, however your applications will benefit from it very much.

I want to thank Paul Lefebre for his excellent webinars and also like to thank Kern Tekinay for his excellent post on using text and encodings. I obtained knowledge from both of them.

Wish you all a very nice day.

Chris

How would I open an .ODT (Open Document Text) file?

There’s a few examples on http://documentation.xojo.com/api/files/textinputstream.html for reading text files.

LibreOffice .odt files apparently are binary data (in fact zip files: read the first bytes of the file and you will see , the zip signature).

That zip binary file holds the LibreOffice write data as compressed XML.