Link to home
Start Free TrialLog in
Avatar of wsturdev
wsturdevFlag for United States of America

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
@EmailAttachmentFileLocation has the full path to the filename I want to use (e.g. "D:\Folder1\Folder2\Folder3\Folder4\Folder5\Sample Doc.html")


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

Open in new window

Avatar of alexpercsi
alexpercsi
Flag of Romania image

Do you have to use SQL Server for this? Couldn't you use ASP.NET or another web server technology?
It's really just 5 lines of code in C#.
Avatar of wsturdev

ASKER

Sorry - can't change.
ASKER CERTIFIED SOLUTION
Avatar of wsturdev
wsturdev
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm glad it worked out for you :)