Answer the question
In order to leave comments, you need to log in
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);
}
Answer the question
In order to leave comments, you need to log in
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");
Here they seem to decide
String Parameter too long - writing to a Word doc ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question