ASPOSE.Words in ASP | Error

Received : 2007/10/15 04:20:41
Message : Hi There,

I am using the following code to gernerate a .doc file.
I get a template and fill the data in that template and save it as .doc file.

<%
dim SECTION_NAME
SECTION_NAME = "COMPLIANCE"
Response.Buffer=true
%>
<!--#include file="connection.inc"-->
<!--#include file="rights.inc" -->
<%

	CVId = Request("CVID")
	if (CVID <>"") then
		sql = " SELECT cv.*, GetMEProducts(cv.meid) products, cvt.NAME compliance,  "&_
			  " case cv.STATUS WHEN 'A' THEN 'Active' WHEN 'I' THEN 'Inactive' END CVStatus, cvg.NAME cv_group " &_
			  " FROM COMPLIANCE_VIOLATION cv, compliance_violation_type cvt, compliance_violation_group cvg where cvg.id=cvt.group_id and cv.VIOLATION_TYPE=cvt.ID "&_
			  " and cv.ID = '"&CVID&"'"								
				
		
		set rs = server.CreateObject("ADODB.Recordset")		
		rs.Open sql, conn
		If rs.Fields("DESCRIPTION").value <> Null Or rs.Fields("DESCRIPTION").value <> "NULL" Then
            			DESCRIPTION = rs.Fields("DESCRIPTION").value
		Else
			DESCRIPTION = ""
		End If
		
		If rs.Fields("VIOLATION_DATE").value <> Null Or rs.Fields("VIOLATION_DATE").value <> "NULL" Then
			VIOLATION_DATE = rs.Fields("VIOLATION_DATE").value
		Else
			VIOLATION_DATE = ""
		End If

		If rs.Fields("AGENCY").value <> Null Or rs.Fields("AGENCY").value <> "NULL" Then
			AGENCY = rs.Fields("AGENCY").value
		Else
			AGENCY = ""
		End If

		If rs.Fields("VIOLATION_OTHER").value <> Null Or rs.Fields("VIOLATION_OTHER").value <> "NULL" Then
			VIOLATION_OTHER = rs.Fields("VIOLATION_OTHER").value
		Else
			VIOLATION_OTHER = ""
		End If

		If rs.Fields("cv_group").value <> Null Or rs.Fields("cv_group").value <> "NULL" Then
			VIOLATION_GROUP = rs.Fields("cv_group").value
		Else
			VIOLATION_GROUP = ""
		End If

		If rs.Fields("compliance").value <> Null Or rs.Fields("compliance").value <> "NULL" Then
		   	compliance = rs.Fields("compliance").value
		Else
			compliance = ""
		End If

		If rs.Fields("NAME").value <> Null Or rs.Fields("NAME").value <> "NULL" Then
		                NAME = rs.Fields("NAME").value
		Else
			NAME = ""
		End If

		If rs.Fields("COMMENTS").value <> Null Or rs.Fields("COMMENTS").value <> "NULL" Then
		   	COMMENTS = rs.Fields("COMMENTS").value
		Else
			COMMENTS = ""
		End If

		If rs.Fields("MEID").value <> Null Or rs.Fields("MEID").value <> "NULL" Then
		                MEID = rs.Fields("MEID").value
		Else
			MEID = ""
		End If

		If rs.Fields("CVStatus").value <> Null Or rs.Fields("CVStatus").value <> "NULL" Then
		                CVStatus = rs.Fields("CVStatus").value
		Else
			CVStatus = ""
		End If

		If rs.Fields("PRODUCTS").value <> Null Or rs.Fields("PRODUCTS").value <> "NULL" Then
			PRODUCTS = rs.Fields("PRODUCTS").value
		Else
			PRODUCTS = ""
		End If

		rs.close()		
			
		sql = " select sponsor, us.firstname||' '|| us.lastname  Planner, meetingname name , project_id , (SELECT LOCATION FROM ME_CACHE mc where mc.meid = me.meetingid) location "&_
		  " from meeting me "&_
		  "	INNER JOIN TBLUsers us on (us.PMID = me.PMID) "&_
		  "	where me.meetingid = '"&MEID&"' "&_
		  "	UNION "&_
		  "	select sponsor, us.firstname||' '|| us.lastname  Planner , eventname name, project_id, (ev.city || ' ' || ev.state) location  "&_
		  " from event ev  "&_
		  "	INNER JOIN TBLUsers us on (us.PMID = ev.PMID) "&_
		  "	where ev.eventid = '"&MEID&"' "
		  
		rs.open sql, conn
		if not rs.eof then
			If rs.Fields("sponsor").value <> Null Or rs.Fields("sponsor").value <> "NULL" Then
			SPONSOR = rs.Fields("sponsor").value
		Else
			SPONSOR = ""
		End If
		
		If rs.Fields("planner").value <> Null Or rs.Fields("planner").value <> "NULL" Then
		                PLANNER = rs.Fields("planner").value
		Else
			PLANNER = ""
		End If
		
		If rs.Fields("name").value <> Null Or rs.Fields("name").value <> "NULL" Then
		       	MENAME = rs.Fields("name").value
		Else
		      	MENAME = ""
		End If
		
		If rs.Fields("project_id").value <> Null Or rs.Fields("project_id").value <> "NULL" Then
		       	ProjectId = rs.Fields("project_id").value
		Else
			ProjectId = ""
		End If
		
		If rs.Fields("location").value <> Null Or rs.Fields("location").value <> "NULL" Then
			location = rs.Fields("location").value
		Else
			location = ""
		End If
		
		End if
		rs.close()
		  
		sql = "select project_name from project where project_id = '"&ProjectId&"'"
		
		rs.Open sql,conn
		if not rs.eof then			
		If rs.Fields("project_name").value <> Null Or rs.Fields("project_name").value <> "NULL" Then
			PROJECTNAME = rs.Fields("project_name").value
		Else
			PROJECTNAME = ""
		End If
		
		end if
		rs.close()
		  
	end if


Dim License
Set License = CreateObject("Aspose.Words.License")
License.SetLicense "C:\Program Files\Aspose\Aspose.Words\License\Aspose.Total.lic"

Dim WordTempl
Dim helper

Set helper =  CreateObject("Aspose.Words.ComHelper")

Dim rsParam

Set rsParam = CreateObject("ADODB.Recordset")

    rsParam.Fields.Append "short_name", CInt(129), CInt(40), False
    rsParam.Fields.Append "program_name", CInt(129), CInt(40), False
    rsParam.Fields.Append "location", CInt(129), CInt(40), False
    rsParam.Fields.Append "date_of_incident", CInt(129), CInt(40), False
    rsParam.Fields.Append "meeting_event", CInt(129), CInt(40), False
    rsParam.Fields.Append "agency", CInt(129), CInt(40), False
    rsParam.Fields.Append "contact_host", CInt(129), CInt(40), False
    rsParam.Fields.Append "meeting_planner", CInt(129), CInt(40), False
    rsParam.Fields.Append "products", CInt(129), CInt(40), False
    rsParam.Fields.Append "status", CInt(129), CInt(40), False
    rsParam.Fields.Append "incident_to_report", CInt(129), CInt(40), False
    rsParam.Fields.Append "cv_type", CInt(129), CInt(40), False
    rsParam.Fields.Append "other", CInt(129), CInt(40), False
    rsParam.Fields.Append "action_taken", CInt(129), CInt(40), False
    rsParam.Fields.Append "cv_group", CInt(129), CInt(40), False
    rsParam.Open' sql,conn 

'====This is line 223====='
rsParam.AddNew Array("short_name","program_name","location","date_of_incident","meeting_event","agency","contact_host","meeting_planner","products","status","incident_to_report","cv_type","other","action_taken","cv_group"),Array(NAME, PROJECTNAME,location,VIOLATION_DATE,MENAME,AGENCY,SPONSOR,PLANNER,PRODUCTS,CVStatus,DESCRIPTION,compliance,VIOLATION_OTHER,COMMENTS,VIOLATION_GROUP)
'====This is line 223====='

Set WordTempl = helper.Open(Server.MapPath("WordWriter/complianceviolationform.doc"))

'Fill template

WordTempl.MailMerge.ExecuteADO rsParam

rsParam.Close()

Dim stream

Set stream = CreateObject("System.IO.MemoryStream")

WordTempl.Save Response, "HCPPaymentForm.doc", True

WordTempl.Save_4 stream, 1

Response.Clear

'Specify the document type.

Response.ContentType = "application/msword"

'Specify how the document is sent to the browser.

Response.AddHeader "content-disposition","attachment; filename=complianceviolationform.doc"

'Get data bytes from the stream and send it to the response.

Dim bytes

bytes = stream.ToArray()

Response.BinaryWrite(bytes)

Response.End
	
%>

And I am getting the following Error:

Microsoft Cursor Engine error ‘80040e21’

Multiple-step operation generated errors. Check each status value.

/ComplianceViolation_print.asp, line 223

Also, I have tried this code:

rsParam.Fields.Append "short_name", dbVarChar, 500 

in place of

rsParam.Fields.Append "short_name", CInt(129), CInt(40), False code.

Please let me know what should I change in order to deal with this error.

Hi
Thanks for your request. I have tried to use the following code, and it seems that all works fine on my side.

Dim WordTempl
Dim helper
Set helper = CreateObject("Aspose.Words.ComHelper")
Dim rsParam
Set rsParam = CreateObject("ADODB.Recordset")
rsParam.Fields.Append "short_name", CInt(129), CInt(40), False
rsParam.Fields.Append "program_name", CInt(129), CInt(40), False
rsParam.Fields.Append "location", CInt(129), CInt(40), False
rsParam.Fields.Append "date_of_incident", CInt(129), CInt(40), False
rsParam.Fields.Append "meeting_event", CInt(129), CInt(40), False
rsParam.Fields.Append "agency", CInt(129), CInt(40), False
rsParam.Fields.Append "contact_host", CInt(129), CInt(40), False
rsParam.Fields.Append "meeting_planner", CInt(129), CInt(40), False
rsParam.Fields.Append "products", CInt(129), CInt(40), False
rsParam.Fields.Append "status", CInt(129), CInt(40), False
rsParam.Fields.Append "incident_to_report", CInt(129), CInt(40), False
rsParam.Fields.Append "cv_type", CInt(129), CInt(40), False
rsParam.Fields.Append "other", CInt(129), CInt(40), False
rsParam.Fields.Append "action_taken", CInt(129), CInt(40), False
rsParam.Fields.Append "cv_group", CInt(129), CInt(40), False
rsParam.Open' sql,conn
'====This is line 223====='
rsParam.AddNew Array("short_name","program_name","location","date_of_incident","meeting_event","agency","contact_host","meeting_planner","products","status","incident_to_report","cv_type","other","action_taken","cv_group"),Array(NAME, PROJECTNAME,location,VIOLATION_DATE,MENAME,AGENCY,SPONSOR,PLANNER,PRODUCTS,CVStatus,DESCRIPTION,compliance,VIOLATION_OTHER,COMMENTS,VIOLATION_GROUP)
'====This is line 223====='
Set WordTempl = helper.Open(Server.MapPath("complianceviolationform.doc"))
'Fill template
WordTempl.MailMerge.ExecuteADO rsParam
rsParam.Close()
'Create a .NET memory stream to save the document to.
Dim stream
Set stream = CreateObject("System.IO.MemoryStream")
'Save the document to the stream.
'We use an overloaded version of the Save method: Document.Save(object, SaveFormat)
'SaveFormat.Doc = 1
WordTempl.Save_4 stream, 1
Response.Clear
'Specify the document type.
Response.ContentType = "application/msword"
'Other options:
'Response.ContentType = "text/plain"
'Response.ContentType = "text/html"
'Specify how the document is sent to the browser.
Response.AddHeader "content-disposition","attachment; filename=MyDocument.doc"
'Another option could be:
'Response.AddHeader "content-disposition","inline; filename=MyDocument.doc"; 
'Get data bytes from the stream and send it to the response.
Dim bytes
bytes = stream.ToArray()
Response.BinaryWrite(bytes)
Response.End

Please provide more information about this error and attach the template file. I will try to reproduce your problem and help you.

Best regards.

Hi
Thanks for your request. I have tried to use the following code, and it seems that all works fine on my side.

Dim WordTempl
Dim helper
Set helper = CreateObject("Aspose.Words.ComHelper")
Dim rsParam
Set rsParam = CreateObject("ADODB.Recordset")
rsParam.Fields.Append "short_name", CInt(129), CInt(40), False
rsParam.Fields.Append "program_name", CInt(129), CInt(40), False
rsParam.Fields.Append "location", CInt(129), CInt(40), False
rsParam.Fields.Append "date_of_incident", CInt(129), CInt(40), False
rsParam.Fields.Append "meeting_event", CInt(129), CInt(40), False
rsParam.Fields.Append "agency", CInt(129), CInt(40), False
rsParam.Fields.Append "contact_host", CInt(129), CInt(40), False
rsParam.Fields.Append "meeting_planner", CInt(129), CInt(40), False
rsParam.Fields.Append "products", CInt(129), CInt(40), False
rsParam.Fields.Append "status", CInt(129), CInt(40), False
rsParam.Fields.Append "incident_to_report", CInt(129), CInt(40), False
rsParam.Fields.Append "cv_type", CInt(129), CInt(40), False
rsParam.Fields.Append "other", CInt(129), CInt(40), False
rsParam.Fields.Append "action_taken", CInt(129), CInt(40), False
rsParam.Fields.Append "cv_group", CInt(129), CInt(40), False
rsParam.Open' sql,conn
'====This is line 223====='
rsParam.AddNew Array("short_name","program_name","location","date_of_incident","meeting_event","agency","contact_host","meeting_planner","products","status","incident_to_report","cv_type","other","action_taken","cv_group"),Array(NAME, PROJECTNAME,location,VIOLATION_DATE,MENAME,AGENCY,SPONSOR,PLANNER,PRODUCTS,CVStatus,DESCRIPTION,compliance,VIOLATION_OTHER,COMMENTS,VIOLATION_GROUP)
'====This is line 223====='
Set WordTempl = helper.Open(Server.MapPath("complianceviolationform.doc"))
'Fill template
WordTempl.MailMerge.ExecuteADO rsParam
rsParam.Close()
'Create a .NET memory stream to save the document to.
Dim stream
Set stream = CreateObject("System.IO.MemoryStream")
'Save the document to the stream.
'We use an overloaded version of the Save method: Document.Save(object, SaveFormat)
'SaveFormat.Doc = 1
WordTempl.Save_4 stream, 1
Response.Clear
'Specify the document type.
Response.ContentType = "application/msword"
'Other options:
'Response.ContentType = "text/plain"
'Response.ContentType = "text/html"
'Specify how the document is sent to the browser.
Response.AddHeader "content-disposition","attachment; filename=MyDocument.doc"
'Another option could be:
'Response.AddHeader "content-disposition","inline; filename=MyDocument.doc"; 
'Get data bytes from the stream and send it to the response.
Dim bytes
bytes = stream.ToArray()
Response.BinaryWrite(bytes)
Response.End

Best regards.

Hi,
In the above code when I try to use the line:

Response.AddHeader "content-disposition","attachment; filename=MyDocument.doc"

The document does not open, I mean I see a window getting opened and then it vanishes (gets closed).
Where as when I use:

Response.AddHeader "content-disposition","inline; filename=MyDocument.doc"

Then I am able to see the documnet with the details filled.
Please let me know how can I solve this problem.

Hi,
Its been nearly 3 Hours I have placed a query, can you please look into this and let me know as I am running out of time.
Many Thanks

Hi
I have tried to reproduce this problem, but this works fine on my side. Please, provide me information how I can reproduce this problem.
Best regards.

Hi,
Can you suggest me some other ways of implementing the same functionality using ASPOSE.Words.
I can ry the same on my side.
Thanks.

Hi

You can save the document on the server and then transfer this file to the client. Also, please, tell me how I can reproduce this. Then I will try to find solution for you.

Best regards.

HI,
I didn’t get your point, you have seen my code, can you suggest me the code changes to be done for the point you made above…that is saving file on server and then transfering.
Because I am not clear with what you said.
Many Thanks.

Hi
You can try to use the following code.

'Save document on the server
Doc.Save (Server.MapPath("out11.doc"))
Dim objFSO
Dim objFile
Dim intFileSize
Dim strFileName
Dim objStream
Dim strFilePath
strFileName = "out11.doc"
strFilePath = Server.MapPath(strFileName)
'Clear response 
Response.Clear()
'get file info
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFilePath) Then
Set objFile = objFSO.GetFile(strFilePath)
intFileSize = objFile.Size
Set objFile = Nothing
'Write header
Response.AddHeader "Content-Disposition","attachment; filename=" & strFileName
Response.ContentType = "application/msword"
Response.AddHeader "Content-Length", intFileSize
'create stream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1 'adTypeBinary
'read file
objStream.LoadFromFile strFilePath
'save file to the client browser
Do While Not objStream.EOS And Response.IsClientConnected
Response.BinaryWrite objStream.Read(1024)
Response.Flush()
Loop
objStream.Close
Set objStream = Nothing
Else
Response.write "Error finding file."
End if
Set objFSO = Nothing

I hope that this code will help you. Also see the following link.
http://blog.netnerds.net/2007/01/classic-asp-push-file-downloads-from-directory-outside-of-the-web-root/
Best regards.