473,385 Members | 1,562 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,385 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 1523

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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.