Using MSWord in asp.net

D

deepmh

Hi,

I am developing one application in asp.net where I need to use the microsoft word template for creating envelopes, but I am not event able to create the ms word object, it's giving me error the application is busy, I have set the requirement permission for asp.net user. so no problem with security, can anyone help me out in this, This is very urgent.

This is my sample code : ( In this code I am just writing some text in word document not trying for template)



Dim oWordApplic As Word.ApplicationClass
Dim oDoc As Word.Document


Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


Try
oWordApplic = New Word.ApplicationClass()
open("test.doc")
InsertText("This is the text")
InsertLineBreak()
Save()
Quit()
Catch exc As Exception
Response.Write(exc.Message)
End Try
End Sub
Sub open(ByVal strFilename As String)
Dim fileName As Object
Dim readOnly1 As Object
Dim isVisible As Object
Dim missing As Object

fileName = strFilename
readOnly1 = False
isVisible = True
missing = System.Reflection.Missing.Value

oDoc = oWordApplic.Documents.Open(fileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, isVisible)
oDoc.Activate()

End Sub
Sub InsertText(ByVal strText As String)
oWordApplic.Selection.TypeText(strText)
End Sub
Sub InsertLineBreak()
oWordApplic.Selection.TypeParagraph()
End Sub
Sub Save()
oDoc.Save()
End Sub
Sub Quit()
Dim missing As Object
missing = System.Reflection.Missing.Value
oWordApplic.Quit(missing, missing, missing)
End Sub


**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
D

Dino Chiesa [Microsoft]

don't do it.
MS-Word is not meant to be automated by server-side apps.
From time to time it will pop up a dialog box, and then what? your app is
stuck.



Deepak Makhija said:
Hi,

I am developing one application in asp.net where I need to use the
microsoft word template for creating envelopes, but I am not event able to
create the ms word object, it's giving me error the application is busy, I
have set the requirement permission for asp.net user. so no problem with
security, can anyone help me out in this, This is very urgent.
This is my sample code : ( In this code I am just writing some text in
word document not trying for template)
Dim oWordApplic As Word.ApplicationClass
Dim oDoc As Word.Document


Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
oWordApplic = New Word.ApplicationClass()
open("test.doc")
InsertText("This is the text")
InsertLineBreak()
Save()
Quit()
Catch exc As Exception
Response.Write(exc.Message)
End Try
End Sub
Sub open(ByVal strFilename As String)
Dim fileName As Object
Dim readOnly1 As Object
Dim isVisible As Object
Dim missing As Object

fileName = strFilename
readOnly1 = False
isVisible = True
missing = System.Reflection.Missing.Value

oDoc = oWordApplic.Documents.Open(fileName, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing,
isVisible)
oDoc.Activate()

End Sub
Sub InsertText(ByVal strText As String)
oWordApplic.Selection.TypeText(strText)
End Sub
Sub InsertLineBreak()
oWordApplic.Selection.TypeParagraph()
End Sub
Sub Save()
oDoc.Save()
End Sub
Sub Quit()
Dim missing As Object
missing = System.Reflection.Missing.Value
oWordApplic.Quit(missing, missing, missing)
End Sub


**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top