Question
· Feb 22, 2019

Cannot set filename for Stream.FileCharacter object

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

Discussion (10)2
Log in or sign up to continue

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