wsturdev
asked on
Write field to a file of type html
I have HTML text in a field. I need to get it into a file on my server.
I am using the attached SQL code in a SPROC and need help getting it running. By now I have completely screwed it up, so please set me straight. At present I am getting an error -2146828212 on the 'OpenTextFile' and an error -2147211483 on the WriteLine
@AttachmentHTMLContent has already been correctly loaded with the data I want to write
@EmailAttachmentFileLocati on has the full path to the filename I want to use (e.g. "D:\Folder1\Folder2\Folder 3\Folder4\ Folder5\Sa mple Doc.html")
I am using the attached SQL code in a SPROC and need help getting it running. By now I have completely screwed it up, so please set me straight. At present I am getting an error -2146828212 on the 'OpenTextFile' and an error -2147211483 on the WriteLine
@AttachmentHTMLContent has already been correctly loaded with the data I want to write
@EmailAttachmentFileLocati
EXECUTE @OLEResult = sp_OACreate 'Scripting.FileSystemObject', @FS OUT
PRINT @OLEResult
IF @OLEResult <> 0 PRINT 'Scripting.FileSystemObject got an error'
--Open a file
execute @OLEResult = sp_OAMethod @FS, 'OpenTextFile', @FileID OUT, @EmailAttachmentFileLocation, 8, 1
PRINT @OLEResult
IF @OLEResult <> 0 PRINT 'OpenTextFile got an error'
--Write Text1
execute @OLEResult = sp_OAMethod @FileID, 'WriteLine', Null, @AttachmentHTMLContent
PRINT @OLEResult
IF @OLEResult <> 0 PRINT 'WriteLine got an error'
EXECUTE @OLEResult = sp_OADestroy @FileID
EXECUTE @OLEResult = sp_OADestroy @FS
ASKER
Sorry - can't change.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm glad it worked out for you :)
It's really just 5 lines of code in C#.