Replacing Error

Hi

Error image,doc file and source code(global.zip) in the attachment files.

Thanks

Hi Ahmet,

Thanks for your inquiry. Please use following modified code example to achieve your requirements. We suggest you please upgrade to the latest version of Aspose.Words for .NET 16.8.0 and use FindReplaceOptions class as shown in following code snippet. Hope this helps you.

// builder.MoveTo((Run)runs[0]);
// Run newrun = new Run(e.MatchNode.Document as Aspose.Words.Document, replaceText);
//CopyFormatting(((Run)runs[0]).Font, newrun.Font);
((Run)runs[0]).Text = replaceText;
if (withLang)
{
    ((Run)runs[0]).Font.Bidi = true;
}
for (int i = 1; i < runs.Count; i++)
{
    ((Run)runs[i]).Remove();
}
//foreach (Run run in runs)
//{
// //run.Remove();
//}
public static void ReplaceWithEvaluator(Aspose.Words.Document wordDoc, string OldValue, string NewValue, bool withLanguage)
{
    ReplaceEval.ReplaceText = NewValue;//Replace("\n", "");
    ReplaceEval.WithLang = withLanguage;
    ReplaceEval.OldValue = OldValue;
    FindReplaceOptions options = new FindReplaceOptions();
    options.ReplacingCallback = new ReplaceEval();
    wordDoc.Range.Replace(new System.Text.RegularExpressions.Regex(@"\<" + OldValue + @"\>"), "", options);
}

Hi Tahir

Thanks for solution. Promlem is solved but Another problem occurred.

docx file have more than one footer section, first section is replaced but other sections is not repleced

Thanks

Hi Ahmet,

Thanks for your inquiry. Could you please share the parameters’ value of ReplaceWithEvaluator method along with output and expected output documents here for testing? We will investigate the issue on our side and provide you more information.

Hi Tahir

The information and files you want in Additional Attachments

ReplaceWithEvaluator(Aspose.Words.Document wordDoc, string OldValue, string NewValue, bool withLanguage)

OldValue="<DOC_KODU>", NewValue="00H-272aa", withLanguage=True

OldValue="<REV_NO>", NewValue="720_00", withLanguage=True

Hi Ahmet,

Thanks for sharing the detail. We have tested the scenario using latest version of Aspose.Words for .NET 16.11.0 and have not found the shared issue. Please use Aspose.Words for .NET 16.11.0. We have attached the output document with this post for your kind reference.

Hi Tahir

Thanks for solution. Promlem is solved but Another file problem occurred.

The information and files you want in Additional Attachments

ReplaceWithEvaluator(Aspose.Words.Document wordDoc, string OldValue, string NewValue, bool withLanguage)

OldValue="<DOC_KODU>", NewValue="**00H-272aa**", withLanguage=True

OldValue="<REV_NO>", NewValue="**720_00**", withLanguage=True

OldValue="<ONAY_<st1:stockticker w:st=\"on\">TAR</st1:stockticker>>", NewValue="**14.01.2016**", withLanguage=True

Hi Ahmet,

Thanks for your inquiry. Your input document contains the smart tags and some part of OldValue is in SmartTag node. Please use Document.RemoveSmartTags method to remove smart tags from the document. Following code example generates the desired output.

Document document = new Document(MyDir + "parametre.doc");
document.RemoveSmartTags();
ReplaceWithEvaluator(document, "DOC_KODU", "00H-272aa", true);
ReplaceWithEvaluator(document, "REV_NO", "720_00", true);
ReplaceWithEvaluator(document, "ONAY_TAR", "14.01.2016", true);
document.Save(MyDir + "Out v16.12.0.docx");