Cannot set filename for Stream.FileCharacter object

ObjectScript, Caché

In my routine when I call set filestream.FileName = filename, I get an error

"cn_iptcp://localhost:56773/USER/%Stream.FileBinary.1.INT" does not exist on the Server

I successfully instantiate the %Stream.FileCharacter object. 'filestream' value is '1@%Stream.FileCharacter'. But when I debug the code, the step where I try to set the file name fails. 

The port number for local host looks good for my current instance. I have tried a few variations, such as using the method FileNameSet(). But this did not work either. 

My routine exists in the USER namespace, as indicated in the error. I am very new to Cache and InterSystems, so I could be wrong, but I would expect that my call to instantiate the class would fail if I do not have access to the class property. Yet, the error message seems to indicate that FileBinary intermediate file does not exist in this namespace. 

I believe the error references FileBinary because FileCharacter Extends FileBinary. 

Do I need to add any type of 'include' to have access to %Stream.FileBinary.1.INT? The documentations and the examples I have found online do not seem to indicate that this is needed. I also tried exporting my code from the USERS namespace and importing it into a new ADMINCODE namespace but I get the same behavior. 

Thank you.

EDIT: 

GOAL: I want to write to a file

set myLogFile = ##class(%Stream.FileCharacter).%New()
    set myLogFile.FileName = filename
    Do myLogFile.Write("This is a test")
    Do myLogFile.%Save()

Daniel Lee
Amazing Charts | Harris CareTracker

  • 0
  • 0
  • 157
  • 7
  • 3

Answers

The property is Filename, not FileName.

Wow, I am not sure how I missed that. Thank you.

It's normal that you don't have INT code for library classes such as %Stream.FileBinary. When InterSystems builds the CACHELIB database that contains these classes they don't set the "k" compile-flag.

Hi Daniel,

Try instantiating the object with the filename as parameter. The filename property is just there for Cache to set and use, as far as I'm aware.

If the goal is just to write to a file try this:

set file=##class(%File).%New(filename)

do file.Open("WSN")

do file.WriteLine("Writing this to a file")

do file.Close()

You can look up the %File in the docs for usage on the open parameter

Comments

What is it that you're trying to do? Can you post some of the code that you're trying to execute

Thank you for the reply Adrian. I updated the original post with a clearly stated goal and code segment. 

filename is set to c:\InterSystems\testfile.txt.  The error occurs when I call set myLogFile.FileName = filename. 

I tried this process in terminal as well. I get a similar error. "<PROPERTY DOES NOT EXIST> *FileName,%Stream.FileCharacter". I have no idea what I am missing. Why would the property for the class not exist? I have checked and rechecked the documentation and it should exist. 

The following will work.  Note, the directory must already exist. If the the file exists, it will be overwritten.

Do myLogFile.LinkToFile(filename)

There must be something wrong with my development system Scott. I am using 2013.1 and I get the same problem trying your suggestion. I may try running repair on this instance to see if that fixes the problem.