473,386 Members | 1,606 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,386 software developers and data experts.

C# with MS Word 2000 - Object Library - Not Saving Template Data

==================
Problem Description
==================
Following code is for
1. Load a Word Template called CustomerInfo1.dot
2. CustomerInfo1.dot is a normal Word Template with Form fields
3. After opening a document on that template, I put "2" in all the fields
for test

Problem is,
4. When I try to sav it, calling SaveAs, it just saves the "2"s and all the
other template contents, mainly text are gone.

==================
Platform
==================
-Win XP Pro
- Office 2000/ Word 2000
- Added Reference to "Microsoft Word 9.0 Object Library" in a C# Windows
Application

==================
Others
==================
Most of the MSDN samples seems to use Bookmarks. That's the way I will go
if there is no resolution

Please guide.

Appreciate that

Thanks

// =========== CODE BLOCK FOR YOUR REFERENCE STARTS ===========
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Word;

// !!! Other ASPX.CS codes !!!!

[STAThread]
static void Main()
{
System.Windows.Forms.Application.Run(new Form1());
}
Word.Application wrdApp;
Word._Document wrdDoc;
Object oMissing = System.Reflection.Missing.Value;
Object oFalse = false;
Object oTrue = true;
Object oTemplate = "C:\\Projects\\AutoWord\\CustomerInfo1.dot";
Object oFileName = "C:\\Projects\\AutoWord\\CustomerInfo.doc";

private void button1_Click(object sender, System.EventArgs e)
{
try{
System.IO.File.Delete("C:\\Projects\\AutoWord\\Cus tomerInfo.doc");
System.IO.File.Create("C:\\Projects\\AutoWord\\Cus tomerInfo.doc");
}
catch(Exception ex){}

wrdApp = new Word.Application( );
wrdApp.Visible = true;
wrdDoc = wrdApp.Documents.Add(ref oTemplate, ref oMissing,ref
oMissing,ref oMissing);

foreach(Word.FormField frmField in wrdDoc.FormFields){
// Just for test I am Setting all form fields to 2
frmField.Result = "2";
}
// This save as saves only the 2s and wipes out the template content
wrdDoc.SaveAs(ref oFileName ,ref oMissing ,ref oTrue ,ref oMissing,ref
oMissing,ref oMissing,ref oMissing,ref oMissing,ref oTru,ref oTrue,ref
oMissing);
wrdDoc.Close(ref oTrue,ref oFalse,ref oMissing);
wrdDoc = null;
wrdApp = null;
}
}
// =========== CODE BLOCK FOR YOUR REFERENCE ENDS=============
Jul 21 '05 #1
0 1524

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

Similar topics

10
by: Neil | last post by:
An article at http://news.com.com/2100-1012-991694.html?tag=fd_top states: "XML would allow easier interchange of data generated in Office documents with back-end systems or existing Web...
6
by: Ryan Muller | last post by:
My company just upgraded from Access 97 to Access 2003 today and we are having some issues in a database that generates a Word document from information selected in a form. Here is the code we...
7
by: Daniel Walzenbach | last post by:
Hello, I want to create a Word XML file based on the input users make in a VB.NET application. I imagine creating a template in Word and saving it as a XML file. I then want to fill the...
2
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to...
0
by: Sudipto Sen | last post by:
================== Problem Description ================== Following code is for 1. Load a Word Template called CustomerInfo1.dot 2. CustomerInfo1.dot is a normal Word Template with Form fields...
3
by: tigrrgrr42 | last post by:
I am working(vb.net03and05) with word documents stored in a sql db and I am currently bringing them from a byte array into a temp file to pop into word and make word do its thing as a com object. ...
7
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the...
5
by: jpr | last post by:
Hello, I have a form with a cbo which get's its data from a table. This combo returns names of MS Word files in the following path: C:\shares\files\*.dot I would like to open these files...
2
by: jmar | last post by:
I am updating a VB4.0 quote generation program to VB.net. The old program takes user inputs, performs calculations, saves the data to Access databases and uses Crystal Reports 5.0 to generate a...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.