Customer Banners (Ads) - SpiceUp. AX and SpotfireX Disclaimer



If you find this site useful and you want to support, buy me a coffee   to keep this site alive and without ads.

Write to file

from System.IO import Path, StreamWriter
from Spotfire.Dxp.Application.Visuals import CrossTablePlot

#targetFileName = "\\\\company.com\\your\\folder\\test.txt"
#targetFileName = "C:\\temp\\test.txt
targetFileName = Path.GetTempFileName()


#Write to file 
writer = StreamWriter(targetFileName,True) #True to append
aLine = "|".join(("str1","str2","str3"))
writer.Write(aLine)
writer.Close()

#Debug
print targetFileName
print aLine


Note: If using writing to a network folder from Webplayer, make sure the folder has proper permissions for the service account running Webplayer. To check what service account webplayer is using, add these lines to output the result in a Text Area Spotfire Label Control.

#Include dependencies
from System.Security.Principal import NTAccount
from System.IO.File import GetAccessControl

#get owner
owner = GetAccessControl(targetFileName).GetOwner(NTAccount);

#store owner in an existing "whoami" string Document Property  
Document.Properties["whoami"] = str(owner)

7 comments:

The Alexu Boy said...

Is there any way I can read from a file? Using a similar script?

Jose Leviaguirre said...
This comment has been removed by the author.
Jose Leviaguirre said...

checkout this post that writes and reads a file

http://spotfired.blogspot.com/2014/10/cross-table-to-html.html

S Saha said...

Hi Jose,

I'm trying to get input from the users through the input fiekd ( e.g. Text Area -> Property Control -> Input field multiple line) and then write it to a file as you mentioned above.

Can you please help me how to do that? In fact how to assign a value to str1 in the above programming from " Input field".

Thanks,
S Saha

Jose Leviaguirre said...

Hello Sasha,

I guess you could replace the following line:

aLine = "|".join(("str1","str2","str3"))

with:

aLine = Document.Properties["yourMultilineDocPropHere"]

Vara said...

Hi Jose,

In spotfire script, when we use Path.GetTempFileName() , do we need to explicitly delete it at the end of the script?

How are the temp files handled in spotfire webplayer. Please educate me.

Thanks,
Vara

Jose Leviaguirre said...

Hello Vara. When running on webplayer do not expect webplayer to use the client to write files but the local computer where the webplayer instance is running.