I am writing a desktop application using C# with WinForms. The application searches for text and replaces it with the users input.
The problem is when with the textbox that has its multiline property set totrue, if there are more than 254 chars entered a string parameter too long error is returned from System.Runtime.InteropServices.COMException.
Here is the method:
private void FindAndReplace(Word.Application WordApp, object findText, object replaceWithText)
{
object matchCase = true;
object matchWholeWord = true;
object matchWildCards = false;
object matchSoundsLike = false;
object nmatchAllWordForms = false;
object forward = true;
object format = false;
object matchKashida = false;
object matchDiacritics = false;
object matchAlefHamza = false;
object matchControl = false;
object read_only = false;
object visible = true;
object replace = 2;
object wrap = 1;
WordApp.Selection.Find.Execute(ref findText,
ref matchCase, ref matchWholeWord,
ref matchWildCards, ref matchSoundsLike,
ref nmatchAllWordForms, ref forward,
ref wrap, ref format, ref replaceWithText,
ref replace, ref matchKashida,
ref matchDiacritics, ref matchAlefHamza,
ref matchControl);
}
I have read that one possible way to solve this is to break the value into multiple arrays of strings, but is that the only way around this or is there an easier way?
Some other solutions have been in ASP.NET to write a JS wrapper but I dont have server side functionality.
Also why is there a 254 length limit on a multiline textbox when working with Interop.Word anyway?


object? You realize that when you do that, you loose all properties and methods of that type. You cant if do thisif (isTrue)if its an object, so how would you use them? 3. Why not just usevar?varimplicitly detects the type, and retains its properties and methods. 4. Why not just create a parameter object that stores all these variables? - AustinWBryan