Friday, May 10, 2013

Word interop problem : String parameter too long.

Hi


i've changed your code as follow (because i'm using .net 2.0 and office 12) :



private static void FindAndReplaceLargeContent2(Microsoft.Office.Interop.Word.Application wordApp, object strSearch, object strReplace)
{
object missing = System.Reflection.Missing.Value;
object foward = true;
Microsoft.Office.Interop.Word.WdFindWrap wrapFind = Microsoft.Office.Interop.Word.WdFindWrap.wdFindStop;
object replace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
List<string> subs = new List<string>();
int counter = 0;
while (counter <= strReplace.ToString().Length)
{
if (strReplace.ToString().Length < counter + 250)
{
subs.Add(strReplace.ToString().Substring(counter, strReplace.ToString().Length - counter));
}
else
{
subs.Add(strReplace.ToString().Substring(counter, 250) + "#r#");
}
counter += 250;
}
wordApp.ActiveDocument.Content.Find.ClearFormatting();
wordApp.ActiveDocument.Content.Find.Replacement.ClearFormatting();
wordApp.ActiveDocument.Content.Find.Text = strSearch.ToString();
wordApp.ActiveDocument.Content.Find.Wrap = wrapFind;
wordApp.ActiveDocument.Content.Find.Replacement.Text = subs[0];
wordApp.ActiveDocument.Content.Find.Execute(ref strSearch,ref missing,ref missing,ref missing,ref missing,
ref missing,ref foward,ref missing,ref missing,ref strReplace,ref replace,ref missing,ref missing,ref missing,ref missing); // error occured
wordApp.ActiveDocument.Content.Find.Text = "#r#";
for (int i = 1; i < subs.Count; i++)
{
wordApp.ActiveDocument.Content.Find.Replacement.Text = subs[i];
wordApp.ActiveDocument.Content.Find.Execute(ref strSearch, ref missing, ref missing, ref missing, ref missing,
ref missing, ref foward, ref missing, ref missing, ref strReplace, ref replace, ref missing, ref missing, ref missing, ref missing);
}
}



but still i'm facing the same problem (string parameter too long) in the given line!


any help ?




http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx


No comments:

Post a Comment