473,473 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Open word doc from asp.net app?

CK
Sorry for x-posting. I am really not sure where to post this question. Is it
possible to open a Word document from a asp.net page? I need to pass
parameters from a web form to a word document. Then inside Word I would need
to use those parameters. Also I want to make a new document from an
exisiting template. Does anyone have any examples of this?

Thanks in Advance,
~CK

May 30 '06 #1
9 2606
CK,

The only way I know of to do this is to have a COM Reference to the Word
object model on the server, and use the Word Object model's methods to open
Word and manipulate / save documents.

This is fraught with complications since Word was never designed to be a
Web-server - side COM server. In particular, you may find it very difficult
to get all the COM Interop references released with the result usually being
123 instances of Word.EXE clogging up your machine, which can be all seen in
Task Mgr.

Several vendors produce server-safe .NET assemblies for doing this, one that
I have seen is the Aspose product.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"CK" wrote:
Sorry for x-posting. I am really not sure where to post this question. Is it
possible to open a Word document from a asp.net page? I need to pass
parameters from a web form to a word document. Then inside Word I would need
to use those parameters. Also I want to make a new document from an
exisiting template. Does anyone have any examples of this?

Thanks in Advance,
~CK

May 30 '06 #2
CK wrote:
Sorry for x-posting. I am really not sure where to post this question. Is it
possible to open a Word document from a asp.net page? I need to pass
parameters from a web form to a word document. Then inside Word I would need
to use those parameters. Also I want to make a new document from an
exisiting template. Does anyone have any examples of this?

Thanks in Advance,
~CK

You would need to use word automation to achieve this.
You would also need read/write permissions on the file server.

Check out the google search below:
http://www.google.com.au/search?clie...=Google+Search

JB
May 31 '06 #3

"John B" <jb******@yahoo.com> wrote in message
news:44**********@news.iprimus.com.au...
| CK wrote:
| > Sorry for x-posting. I am really not sure where to post this question.
Is it
| > possible to open a Word document from a asp.net page? I need to pass
| > parameters from a web form to a word document. Then inside Word I would
need
| > to use those parameters. Also I want to make a new document from an
| > exisiting template. Does anyone have any examples of this?
| >
| > Thanks in Advance,
| > ~CK
| >
| >
| >
| You would need to use word automation to achieve this.
| You would also need read/write permissions on the file server.
|
| Check out the google search below:
|
http://www.google.com.au/search?clie...=Google+Search
|
| JB

Such articles gives you the false impression that you can use Office in a
server context like ASP, which is not the case. Such articles should start
by referring to the Q257757 KB article, those brave souls who still think
they want Office server-side should keep in mind that it only talks about
ASP, ASP.NET is even more problematic because of the non deterministic
nature of the GC/Finalizer.

Willy.
May 31 '06 #4
Find some good articles here :

http://www.geocities.com/dixit_d_a/dotnet.htm

May 31 '06 #5
> Such articles gives you the false impression that you can use Office in a
server context like ASP, which is not the case. Such articles should start
by referring to the Q257757 KB article, those brave souls who still think
they want Office server-side should keep in mind that it only talks about
ASP, ASP.NET is even more problematic because of the non deterministic
nature of the GC/Finalizer.
Willy, isn't that one of the features that Visual Studio Tools for Office 2005 provides -- server-based Word and Excel document applications?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message news:uL**************@TK2MSFTNGP03.phx.gbl...
"John B" <jb******@yahoo.com> wrote in message
news:44**********@news.iprimus.com.au...
| CK wrote:
| > Sorry for x-posting. I am really not sure where to post this question.
Is it
| > possible to open a Word document from a asp.net page? I need to pass
| > parameters from a web form to a word document. Then inside Word I would
need
| > to use those parameters. Also I want to make a new document from an
| > exisiting template. Does anyone have any examples of this?
| >
| > Thanks in Advance,
| > ~CK
| >
| >
| >
| You would need to use word automation to achieve this.
| You would also need read/write permissions on the file server.
|
| Check out the google search below:
|
http://www.google.com.au/search?clie...=Google+Search
|
| JB


May 31 '06 #6
Excel Services is a new feature of Office 12 that can be deployed to a web
server.

http://techtalkpt.wordpress.com/2006...007-resources/

--
Regards

John Timney
Microsoft MVP

"Sue Mosher [MVP-Outlook]" <su****@outlookcode.com> wrote in message
news:uw**************@TK2MSFTNGP03.phx.gbl...
Such articles gives you the false impression that you can use Office in a
server context like ASP, which is not the case. Such articles should start
by referring to the Q257757 KB article, those brave souls who still think
they want Office server-side should keep in mind that it only talks about
ASP, ASP.NET is even more problematic because of the non deterministic
nature of the GC/Finalizer.
Willy, isn't that one of the features that Visual Studio Tools for Office
2005 provides -- server-based Word and Excel document applications?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:uL**************@TK2MSFTNGP03.phx.gbl...
"John B" <jb******@yahoo.com> wrote in message
news:44**********@news.iprimus.com.au...
| CK wrote:
| > Sorry for x-posting. I am really not sure where to post this question.
Is it
| > possible to open a Word document from a asp.net page? I need to pass
| > parameters from a web form to a word document. Then inside Word I
would
need
| > to use those parameters. Also I want to make a new document from an
| > exisiting template. Does anyone have any examples of this?
| >
| > Thanks in Advance,
| > ~CK
| >
| >
| >
| You would need to use word automation to achieve this.
| You would also need read/write permissions on the file server.
|
| Check out the google search below:
|
http://www.google.com.au/search?clie...=Google+Search
|
| JB

May 31 '06 #7
It's really quite simple ...

This sample opens a Word template, uses Find & Replace to change the
content of the document and then saves the document. Hope it helps.

Regards
James

Add the reference to the version of MS Word you are using. Then in the
code behind page ...

Dim MSWord As New Word.ApplicationClass
Dim doc As New Word.DocumentClass

strFile = Server.MapPath("/template.dot")
MSWord = CreateObject("Word.Application")
MSWord.Visible = True
doc = MSWord.Documents.Add(strFile)
selection = MSWord.Selection

MSWord.ActiveWindow.ActivePane.View.SeekView =
Word.WdSeekView.wdSeekMainDocument

strFind = "<date>"
strReplace = Format(DateValue(Now()), "D")

SearchAndReplace(strFind, strReplace)

strFind = "<name>"
strReplace = theName
SearchAndReplace(strFind, strReplace)

strFind = "<address>"
strReplace = address
SearchAndReplace(strFind, strReplace)

strFile = Server.MapPath("") & "filename.doc"

doc.SaveAs(strFile)
doc.Close()
doc = Nothing
MSWord.Quit()
MSWord = Nothing
end sub

Function SearchAndReplace(ByVal strTmpSearchFor, ByVal
strTmpReplaceWith)
selection.Find.ClearFormatting()
selection.Find.Replacement.ClearFormatting()
selection.Find.Text = strTmpSearchFor
selection.Find.Replacement.Text = strTmpReplaceWith
selection.Find.Forward = True
selection.Find.Wrap = Word.WdFindWrap.wdFindContinue
selection.Find.Format = False
selection.Find.MatchCase = False
selection.Find.MatchWholeWord = False
selection.Find.MatchWildcards = False
selection.Find.MatchSoundsLike = False
selection.Find.MatchAllWordForms = False
selection.Find.Execute(, , , , , , , , , ,
Word.WdReplace.wdReplaceAll)
End Function

CK wrote:
Sorry for x-posting. I am really not sure where to post this question. Is it
possible to open a Word document from a asp.net page? I need to pass
parameters from a web form to a word document. Then inside Word I would need
to use those parameters. Also I want to make a new document from an
exisiting template. Does anyone have any examples of this?

Thanks in Advance,
~CK


Jun 1 '06 #8
CK
Do you have an example in C sharp? CreateObject function is not available in
C Sharp.

<ja***@interfacesolutions.net.au> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
It's really quite simple ...

This sample opens a Word template, uses Find & Replace to change the
content of the document and then saves the document. Hope it helps.

Regards
James

Add the reference to the version of MS Word you are using. Then in the
code behind page ...

Dim MSWord As New Word.ApplicationClass
Dim doc As New Word.DocumentClass

strFile = Server.MapPath("/template.dot")
MSWord = CreateObject("Word.Application")
MSWord.Visible = True
doc = MSWord.Documents.Add(strFile)
selection = MSWord.Selection

MSWord.ActiveWindow.ActivePane.View.SeekView =
Word.WdSeekView.wdSeekMainDocument

strFind = "<date>"
strReplace = Format(DateValue(Now()), "D")

SearchAndReplace(strFind, strReplace)

strFind = "<name>"
strReplace = theName
SearchAndReplace(strFind, strReplace)

strFind = "<address>"
strReplace = address
SearchAndReplace(strFind, strReplace)

strFile = Server.MapPath("") & "filename.doc"

doc.SaveAs(strFile)
doc.Close()
doc = Nothing
MSWord.Quit()
MSWord = Nothing
end sub

Function SearchAndReplace(ByVal strTmpSearchFor, ByVal
strTmpReplaceWith)
selection.Find.ClearFormatting()
selection.Find.Replacement.ClearFormatting()
selection.Find.Text = strTmpSearchFor
selection.Find.Replacement.Text = strTmpReplaceWith
selection.Find.Forward = True
selection.Find.Wrap = Word.WdFindWrap.wdFindContinue
selection.Find.Format = False
selection.Find.MatchCase = False
selection.Find.MatchWholeWord = False
selection.Find.MatchWildcards = False
selection.Find.MatchSoundsLike = False
selection.Find.MatchAllWordForms = False
selection.Find.Execute(, , , , , , , , , ,
Word.WdReplace.wdReplaceAll)
End Function

CK wrote:
Sorry for x-posting. I am really not sure where to post this question. Is
it
possible to open a Word document from a asp.net page? I need to pass
parameters from a web form to a word document. Then inside Word I would
need
to use those parameters. Also I want to make a new document from an
exisiting template. Does anyone have any examples of this?

Thanks in Advance,
~CK

Jun 1 '06 #9
CK
Hey James. I got everything going in csharp. I am able to hit the page
locally and open word, but when another user tries to hit my page from their
site, they are prompted for username and password. Any ideas?
I used impersonate = true in the web config and gave the IUSR_MachineName
access to word.
Any other ideas?

<ja***@interfacesolutions.net.au> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
It's really quite simple ...

This sample opens a Word template, uses Find & Replace to change the
content of the document and then saves the document. Hope it helps.

Regards
James

Add the reference to the version of MS Word you are using. Then in the
code behind page ...

Dim MSWord As New Word.ApplicationClass
Dim doc As New Word.DocumentClass

strFile = Server.MapPath("/template.dot")
MSWord = CreateObject("Word.Application")
MSWord.Visible = True
doc = MSWord.Documents.Add(strFile)
selection = MSWord.Selection

MSWord.ActiveWindow.ActivePane.View.SeekView =
Word.WdSeekView.wdSeekMainDocument

strFind = "<date>"
strReplace = Format(DateValue(Now()), "D")

SearchAndReplace(strFind, strReplace)

strFind = "<name>"
strReplace = theName
SearchAndReplace(strFind, strReplace)

strFind = "<address>"
strReplace = address
SearchAndReplace(strFind, strReplace)

strFile = Server.MapPath("") & "filename.doc"

doc.SaveAs(strFile)
doc.Close()
doc = Nothing
MSWord.Quit()
MSWord = Nothing
end sub

Function SearchAndReplace(ByVal strTmpSearchFor, ByVal
strTmpReplaceWith)
selection.Find.ClearFormatting()
selection.Find.Replacement.ClearFormatting()
selection.Find.Text = strTmpSearchFor
selection.Find.Replacement.Text = strTmpReplaceWith
selection.Find.Forward = True
selection.Find.Wrap = Word.WdFindWrap.wdFindContinue
selection.Find.Format = False
selection.Find.MatchCase = False
selection.Find.MatchWholeWord = False
selection.Find.MatchWildcards = False
selection.Find.MatchSoundsLike = False
selection.Find.MatchAllWordForms = False
selection.Find.Execute(, , , , , , , , , ,
Word.WdReplace.wdReplaceAll)
End Function

CK wrote:
Sorry for x-posting. I am really not sure where to post this question. Is
it
possible to open a Word document from a asp.net page? I need to pass
parameters from a web form to a word document. Then inside Word I would
need
to use those parameters. Also I want to make a new document from an
exisiting template. Does anyone have any examples of this?

Thanks in Advance,
~CK

Jun 1 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin Lucas-Smith | last post by:
I am trying to use PHP's COM support to open a URL from within MS Word then save the document. I am using PHP5.0.3/Apache2/WindowsXP. phpinfo() confirms that COM support is enabled. ...
3
by: TLMM | last post by:
I have a Word doc already created that I want to open from an asp page. I want it to open in Word and allow the user to modify if necessary. I currently have it opening (using href), but it is...
3
by: Andy Davis | last post by:
How do i or can I open a word document directly from Access? I would like to be able for the user to click a button on my form to open a word document and then also run a macro in Word. Thanks...
8
by: sudha | last post by:
Hi, To open a word doc from c#, i use the following code : Word.ApplicationClass WordApp = new Word.ApplicationClass (); // give any file name of your choice. object fileName =...
10
by: Åženol Akbulak | last post by:
Hi, I have a form page to print on my web application(asp.net). I want to show the page in WORD. I use that code in asp.net Page_Load event: Response.Clear(); Response.ContentType =...
4
by: Fabian | last post by:
Hello, I want to open a Word Document in my C# Programm. I tried this : Word.Application wordapp = new Word.Application(); object path = "TEST.DOC"; object vk_read_only = false; object...
0
by: Niyazi | last post by:
Hi, I created application that store the data in SQL SERVER that reside on network. The client also use this application to access the resources provided with application. But is the client want...
6
by: Bob Alston | last post by:
Looking for someone with experience building apps with multiple instances of forms open. I am building an app for a nonprofit organizations case workers. They provide services to the elderly. ...
0
by: RKovach | last post by:
I am automating Word and getting the existing instance if available using the following: Word.Application oWord = null; Word.Document oDoc = null; object oMissing =...
7
by: Peter | last post by:
ASP.NET 2.0 I am trying to open a Word document and Excel document from a dialog web page, what's the best way to do that? I have tried the following: Response.Clear();...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.