This is related to Jim's post on HTMLAgilityPack. Several of the Methods in that assembly reference a FileStream Object. I know you can issue
oStream = ObjectClrNew('System.IO.FileStream')
but C# code is generally: FileStream sw = new FileStream("FileStream.html", FileMode.Create)
But there is no oStream.Create() method, so the question is how to replicate the above in the WB CLR.
Don't know if this will do what you need but
oStream = ObjectClrNew('System.IO.File')
and
sw = oStream.Create("FileStream.html")
Will get a File Opened. Not sure about the Stream needs.
jim
Seems to initialize objects but need something different on the parameters. Guessing I am way off though.
IntControl(73,1,0,0,0)
gosub udfs
html=""
ObjectClrOption("useany", "System.Data")
oFile = ObjectClrNew('System.IO.File')
oStream = ObjectClrNew('System.IO.FileStream')
;avoid secure channel errors
sw = oFile.Create("FileStream.html")
fs = oStream(sw,1|1)
oWeb=0
oHTML=0
Exit
:WBERRORHANDLER
oWeb=0
oHTML=0
geterror()
Message("Error Encountered",errmsg)
Exit
:udfs
#DefineSubRoutine geterror()
wberroradditionalinfo = wberrorarray[6]
lasterr = wberrorarray[0]
handlerline = wberrorarray[1]
textstring = wberrorarray[5]
linenumber = wberrorarray[8]
errmsg = "Error: ":lasterr:@LF:textstring:@LF:"Line (":linenumber:")":@LF:wberroradditionalinfo
ClipPut(errmsg)
Return(errmsg)
#EndSubRoutine
Return
Exit
Yeah, I tried several options for example
cOutfile = "c:\temp\test.html"
If FileExist(cOutfile) Then FileDelete(cOutfile)
ObjectClrOption("useany", "System.IO")
oStream = ObjectClrNew('System.IO.FileStream',cOutfile,2) ; 2= Create
which errors with 'constructor on type System.IO.FileStream not found.
Would it just be the following? If I read things correctly sw should be a filestream. May need the other assembly for additional stuff you want to do but maybe this gives you the file object you need to get started?
ObjectClrOption("useany", "System.Data")
oFile = ObjectClrNew('System.IO.File')
sw = oFile.Create("FileStream.html")
Guess we can beat this dead horse....
cOutfile = "c:\temp\test.html"
If FileExist(cOutfile) Then FileDelete(cOutfile)
oFile = ObjectClrNew('System.IO.File')
oFile.AppendAllText(cOutfile,html)
;oHTML.Save(cOutfile)
html is the URL data returned with my Agility CLR script. And either of the options above to save the html work. The problem is both methods suggest an optional encoding ObjectCltType() which would imply an encoding enum.
Yes. This what you need?
ObjectClrOption("useany", "System.Data")
oEncode = ObjectClrNew("System.Text.Encoding")
oFile = ObjectClrNew('System.IO.File')
;avoid secure channel errors
html = FileGet(DirScript():"hap_test.html")
cOutfile = DirScript():"test.html"
If FileExist(cOutfile) Then FileDelete(cOutfile)
oFile.AppendAllText(cOutfile,html,oEncode.UTF8)
Yep. Got that. Thought I needed ObjectClrOption("useany", "System.Text") before Encoding and that failed.