S
Santhosh
Hi,
I am working on creating a .doc file by using .dot(Template) file using
Word.ApplicationClass. In this process I am having few tags in the template
file which I am trying to replace with some content. But when I am trying to
insert large text as the replacement text, I am getting an error "String too
long".
Following are the piece of code that I am using:
private void button1_Click(object sender, System.EventArgs e)
{
WordDoc wd = new WordDoc();
wd.Open("D:\\PTS\\Test1.dot");
object str = textBox1.Text; // It is a multiline text box where large text
is inserted
wd.FindAndReplacement("<<Body>>", str);
wd.SaveAs("D:\\PTS\\Test.doc");
wd.Quit();
}
public void FindAndReplacement(string strFind, object strReplace)
{
Word.ApplicationClass oWordAppl = new Word.ApplicationClass();
object missing = System.Reflection.Missing.Value;
object story = Word.WdUnits.wdStory;
object ext = Word.WdMovementType.wdExtend;
object rp = Word.WdReplace.wdReplaceAll;
object strf = strFind;
object strr = strReplace;
oWordAppl.Selection.HomeKey(ref story,ref ext);
oWordAppl.Selection.Find.Execute(ref strf, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref strr, ref rp, ref missing,ref missing,ref missing, ref missing);
}
This code is however working for smaller texts. Please let me know if there
is anything wrong I m doing in this code. If the code is fine, then please
let me know how to fix the issue.
Note: I am using MS Word 2000 component in my C# aplication.
Thanx & regards,
Santhosh.B
I am working on creating a .doc file by using .dot(Template) file using
Word.ApplicationClass. In this process I am having few tags in the template
file which I am trying to replace with some content. But when I am trying to
insert large text as the replacement text, I am getting an error "String too
long".
Following are the piece of code that I am using:
private void button1_Click(object sender, System.EventArgs e)
{
WordDoc wd = new WordDoc();
wd.Open("D:\\PTS\\Test1.dot");
object str = textBox1.Text; // It is a multiline text box where large text
is inserted
wd.FindAndReplacement("<<Body>>", str);
wd.SaveAs("D:\\PTS\\Test.doc");
wd.Quit();
}
public void FindAndReplacement(string strFind, object strReplace)
{
Word.ApplicationClass oWordAppl = new Word.ApplicationClass();
object missing = System.Reflection.Missing.Value;
object story = Word.WdUnits.wdStory;
object ext = Word.WdMovementType.wdExtend;
object rp = Word.WdReplace.wdReplaceAll;
object strf = strFind;
object strr = strReplace;
oWordAppl.Selection.HomeKey(ref story,ref ext);
oWordAppl.Selection.Find.Execute(ref strf, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref strr, ref rp, ref missing,ref missing,ref missing, ref missing);
}
This code is however working for smaller texts. Please let me know if there
is anything wrong I m doing in this code. If the code is fine, then please
let me know how to fix the issue.
Note: I am using MS Word 2000 component in my C# aplication.
Thanx & regards,
Santhosh.B