Custom extension file not showing contents

I use custom extension in my desktop app.
When I open file with saved data, data is not showing however data is showing when I open using app means data is not showing when I open respective file.

Using ‘opendocument’ event?
is item = nil?
does item exist?

Its a method

Custom file Extension do not matter (IMHO).

There are examples to load data ferom file in the LR.

Some questions to help formulate a credible answer:
What kind of data are there (Text, Images, Binary).

Can you share the code you use to load the data from the file ?

Or
 you can simply share a project with only the load data code.

With these, people can try to help. Otherwise, it is just betting on what can go wrong.

The original question is far from helping to give an answer.

At last, Xojo version, OS platform and Version are welcome too.

Code to load data

var FileDialog As FolderItem
FileDialog = FolderItem.ShowOpenFileDialog(FileExt.NoteDocument)

if FileDialog <> nil then
var UserSelect As TextInputStream
UserSelect = TextInputStream.Open(FileDialog)
UserSelect.Encoding = Encodings.UTF8

var ReadData As String
ReadData = UserSelect.ReadAll()

var NewWindow As new MainWindow

// -------------- TITLE BOX ----------------

NewWindow.TitleBox_1.Text = ReadData.NthField(“field_divider”, 1)
NewWindow.TitleBox_2.Text = ReadData.NthField(“field_divider”, 2)
NewWindow.TitleBox_3.Text = ReadData.NthField(“field_divider”, 3)

// -------------- TEXT BOX ----------------

NewWindow.TextBox_1.Text = ReadData.NthField(“field_divider”, 4)
NewWindow.TextBox_2.Text = ReadData.NthField(“field_divider”, 5)
NewWindow.TextBox_3.Text = ReadData.NthField(“field_divider”, 6)

NewWindow.Title="Note++ - "+FileDialog.Name
NewWindow.NameFile = FileDialog

UserSelect.Close

end if

If that works, what code is in the area that does NOT work?

if your app is registered as the editor of files with FileExt.NoteDocument extension,
then double clicking the file will cause the OpenDocument EVENT to fire.
That passes a folderitem as ‘item’, without a need to browse for it.

You would need something like this in OpenDocument


var UserSelect As TextInputStream
UserSelect = TextInputStream.Open(item)
UserSelect.Encoding = Encodings.UTF8

var ReadData As String
ReadData = UserSelect.ReadAll()

var NewWindow As new MainWindow

// -------------- TITLE BOX ----------------

NewWindow.TitleBox_1.Text = ReadData.NthField(“field_divider”, 1)
NewWindow.TitleBox_2.Text = ReadData.NthField(“field_divider”, 2)
NewWindow.TitleBox_3.Text = ReadData.NthField(“field_divider”, 3)

// -------------- TEXT BOX ----------------

NewWindow.TextBox_1.Text = ReadData.NthField(“field_divider”, 4)
NewWindow.TextBox_2.Text = ReadData.NthField(“field_divider”, 5)
NewWindow.TextBox_3.Text = ReadData.NthField(“field_divider”, 6)

NewWindow.Title="Note++ - "+FileDialog.Name
NewWindow.NameFile = FileDialog

UserSelect.Close

Please help me with code as I am beginner.

It is not working.

'something like this ’ does not mean ‘here is the entire solution’

Looking at it (I cannot edit it now), the last two lines should not be there

NewWindow.Title="Note++ - "+FileDialog.Name
NewWindow.NameFile = FileDialog

But I cannot guess what you are trying to do, and I cannot guess what code you have.
Nor can I guess what error you see.

‘It does not work’ is not enough - you have not even said if you get an error or what it is.

Please post your code at least.

I am not getting an error.
Only content of the file is not showing.

Remove the quotes ?
Unless your field devider is “field_divider”


1 Like

When I double click on my app file, content is not showing.
My desktop app has custom extension
It have three text fields.

Vansaj,

First, use String.NthField

http://documentation.xojo.com/api/data_types/string.html.NthField

Second:
The result of the operation is empty if Xojo is unable to get a field OR if the separator (you name it field devider) is not found.

Add a Variable named Foo to your code,
Modify your line:

NewWindow.TitleBox_1.Text = ReadData.NthField(“field_divider”, 1)

to

Foo = ReadData.NthField("field_divider", 1)

Add a bread Point to that line (a red rectangle will be added in that line left margin).

In the Debugger, search Foo and read its contents. If it is empty, your ReadData.NthField is wrong as I wrote earlier.

You now have to learn the hardest part of developing software: where is the problem? EVERY one of us has been in your place. The darn code doesn’t work and you have no clue.

You need to check each part of your code what is working and what is not working. That is easier to do when your code has some sort of structure. Is the file not working? Is reading the file not working? Does the file processing make problems? You need to check that.

Data is shown when I open file using dialog box. But when I open file directly, data is not showing.

What does “open file directly” mean? Find out what the difference to your dialog is.

Why are you responding to me, Beatrix? I’m not a beginner and already know what you tell me.

I’ve responded to the OP.

What you wrote means you have two different set of code that is called:

one that works,
one that do not.

Have-you read “ Introduction to Xojo Programming Book” ?

Page 166 (mid of the page) have code ans explanations


Also (you can read that in the above book), instead of using a .ReadAll, then NthField
 you can use

NewWindow.TextBox_1.Text = UserSelect.ReadLine

etc.

Hint: what is TextBox
 A TextField (one line only) or a TextArea (many lines
) ?

BTW: if you do not try the given advices, why asking ?

At last, the example here:
http://documentation.xojo.com/api/files/textinputstream.html

Use some kind of error handling (and you skipped it in your above code).
You also do not shared what is “field_divider”
 Clarifuy that, please.

When I use open dialog box, data is shown and hen I double click on the saved file, file open but no data is shown.