P
P
protov2013-12-16 20:01:10
C++ / C#
protov, 2013-12-16 20:01:10

How to overcome "String Parameter too long" error? (C#,Word)

Good afternoon!
Question about pasting text from C# into Word.
When replacing text in a Word file, if the number of characters of the inserted text is greater than 255, a String Parameter too long error occurs.

var worddoc = app.Documents.Open(fileName);
Object replace = Word.WdReplace.wdReplaceAll;
app.Visible = true;
 foreach (var i in Dict)
{
   var range = worddoc.Content;
   range.Find.ClearFormatting();
   range.Find.Execute(FindText: i.Key, ReplaceWith: i.Value, Replace: replace);
}

Dict is a dictionary, where Key is what needs to be replaced and Value is the text to insert.
Couldn't find a solution on google. I read that the problem is in Execute, supposedly it does not allow it to be done, but I don’t understand how to solve the problem without Execute.
Please help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Archer_kzn, 2013-12-16
@Archer_kzn

Using Microsoft.Office.Interop.Word didn't work for me either.
Have you tried third-party frameworks? For example Aspose.Words can, here is an example:

Document doc = new Document(@"D:\text.docx");
doc.Range.Replace("sad", "MyLongLongText", false, true);
doc.Save(@"D:\text.docx");

But he adds this inscription at the beginning of the document: "Evaluation Only. Created with Aspose.Words. Copyright 2003-2013 Aspose Pty Ltd."

I
Ilya Glebov, 2013-12-17
@IljaGlebov

Here they seem to decide
String Parameter too long - writing to a Word doc ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question