473,439 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,439 software developers and data experts.

Word.ApplicationClass

Hai,
Has any one used Microsoft Office Word in C# Application.
How can i combine two word files into a single word file
using the Word.Application and Word.Document classes.

I know how to autogenerate a word doc but how to combine two
existing documents into a single doc file.

Any Ideas | code samples ?

S.Kartikeyan
Nov 15 '05 #1
2 15916
I am trying to do the exact same thing. Have you had any luck with
it? I am trying to dynamically create a cover page and attach it to
the beginning of an existing document.

If I figure anything out I will post back to this thread.

Regards,
Eric

in*******@yahoo.com (S.Kartikeyan) wrote in message news:<6d**************************@posting.google. com>...
Hai,
Has any one used Microsoft Office Word in C# Application.
How can i combine two word files into a single word file
using the Word.Application and Word.Document classes.

I know how to autogenerate a word doc but how to combine two
existing documents into a single doc file.

Any Ideas | code samples ?

S.Kartikeyan

Nov 15 '05 #2
I finally figured this out. The sample code is below.

/// <summary>
/// Prepends the <code>newDocURI</code> document to the beginning
/// of the <code>originalDocURI</code> and saves the output as the
/// <code>outputFileURI</code>.
/// </summary>
/// <param name="originalDocURI">The original main document</param>
/// <param name="newDocURI">The new document, cover page, etc.
/// that you want to prepend to the beginning of the main
document</param>
/// <param name="outputFileURI">The combination output file</param>
/// <returns></returns>
public string prependDoc(string originalDocURI, string newDocURI,
string outputFileURI)
{
object oFirstDoc = originalDocURI;
object oOutputDoc = outputFileURI;
object oPageBreak = Word.WdBreakType.wdPageBreak;

try
{
Word.Application wordApp = new Word.Application();

Word.Document origDoc = wordApp.Documents.Open(ref oFirstDoc,
ref missing, ref oTrue, ref missing, ref missing, ref
missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing);
origDoc.Activate();
wordApp.Selection.InsertFile(newDocURI, ref missing, ref
oFalse,
ref oFalse, ref oFalse);
wordApp.Selection.InsertBreak(ref oPageBreak);
wordApp.ActiveDocument.SaveAs(ref oOutputDoc, ref missing, ref
missing,
ref missing, ref missing, ref missing, ref missing, ref
missing,
ref missing, ref missing, ref missing);
wordApp.ActiveDocument.Close(ref oFalse, ref missing, ref
missing);
return outputFileURI;
}
catch (Exception ex)
{
throw ex;
}
}

Regards,
Eric

er********@yahoo.com (Eric) wrote in message news:<8c**************************@posting.google. com>...
I am trying to do the exact same thing. Have you had any luck with
it? I am trying to dynamically create a cover page and attach it to
the beginning of an existing document.

If I figure anything out I will post back to this thread.

Regards,
Eric

in*******@yahoo.com (S.Kartikeyan) wrote in message news:<6d**************************@posting.google. com>...
Hai,
Has any one used Microsoft Office Word in C# Application.
How can i combine two word files into a single word file
using the Word.Application and Word.Document classes.

I know how to autogenerate a word doc but how to combine two
existing documents into a single doc file.

Any Ideas | code samples ?

S.Kartikeyan

Nov 15 '05 #3

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

Similar topics

1
by: MSNEWS | last post by:
Hi I'm using the word.applicationclass within my vb.net application to convert some word documents to text files. Is there anyway I can disable macros whilst loading the document, in Word I...
3
by: selen | last post by:
Hello I add Microsoft Word 10.0 Object Library from reference com. and I am writing my code to create an instance of a Word application.My code is Word.ApplicationClass oWordApp = new...
3
by: Yohancef Chin | last post by:
Hi, Being fairly new to .NET I am looking for a way to call MS Word from an event on a webform, and after the user is finished save that created document to an SQL Server database. Has anyone...
1
by: Markusek Peter | last post by:
I got this error: Exception Details: System.Runtime.InteropServices.COMException: Server execution failed Source Error: Line 29: protected System.Web.UI.HtmlControls.HtmlGenericControl zzz;...
14
by: Alan T | last post by:
These are the codes I created a document: _WordApp = new Interop.Word.Application(); _WordApp.Visible = false; _WordDoc = new Document(); _Missing = System.Reflection.Missing.Value;
2
by: Alan T | last post by:
private Interop.Word.Application _wordApp; What is the differences betwenn _wordApp.Quit(...) and _wordApp.Application.Quit(...) ?
1
by: Shar Shar | last post by:
Hi All, Actually I want to use "Word.ApplicationClass" class for opening a word file. And do following things, 1) Open word file. 2) Insert text in bookmark field. 3) Print resultant file as...
1
by: inxanu | last post by:
First of all, I am unsure as to where to post it, so please let me know (or move it) to where it should be. I create an instance of word as follows Word.ApplicationClass wd = new...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
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...

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.