Hi Aspose team,
I am testing replacement of hyperlinks in Word documents. By using following code after replacement links are broken:
public void ReplaceHyperlinksNew()
{
Console.WriteLine("1." + DateTime.Now.ToString());
Aspose.Words.Document doc = new Aspose.Words.Document("UNCHyperlinks.docx");
Console.WriteLine("2." + DateTime.Now.ToString());
{
Console.WriteLine("1." + DateTime.Now.ToString());
Aspose.Words.Document doc = new Aspose.Words.Document("UNCHyperlinks.docx");
Console.WriteLine("2." + DateTime.Now.ToString());
foreach (Field field in doc.Range.Fields)
{
if (field.Type.Equals(FieldType.FieldHyperlink))
{
FieldHyperlink hpl = (FieldHyperlink)field;
Console.WriteLine("1. Hyperlink: " + hpl.Address);
hpl.Address = hpl.Address.Replace(OldUrl,NewUrl);
hpl.Result = hpl.Result.Replace("NewUrl", "NewName");
Console.WriteLine("2. Hyperlink: " + hpl.Address);
}
}
Console.WriteLine("3." + DateTime.Now.ToString());
doc.Save("output111.docx");
Console.WriteLine("4." + DateTime.Now.ToString());
}
{
if (field.Type.Equals(FieldType.FieldHyperlink))
{
FieldHyperlink hpl = (FieldHyperlink)field;
Console.WriteLine("1. Hyperlink: " + hpl.Address);
hpl.Address = hpl.Address.Replace(OldUrl,NewUrl);
hpl.Result = hpl.Result.Replace("NewUrl", "NewName");
Console.WriteLine("2. Hyperlink: " + hpl.Address);
}
}
Console.WriteLine("3." + DateTime.Now.ToString());
doc.Save("output111.docx");
Console.WriteLine("4." + DateTime.Now.ToString());
}
private const string OldUrl = @"\\sion-n08\usr\DATA\EPV\GROUP\";
private const string NewUrl = @"\\infra.vs.ch\dfs\SAPEM-DSMV\";
private const string NewName = @"\\infra.vs.ch\dfs\SAPEM-DSMV\";
private const string NewUrl = @"\\infra.vs.ch\dfs\SAPEM-DSMV\";
private const string NewName = @"\\infra.vs.ch\dfs\SAPEM-DSMV\";
Expected result is \\infra.vs.ch\dfs\SAPEM-DSMV\ but real result is \infra.vs.chdfsSAPEM-DSMV
Can you please check?
Sample project and test document are attached.
Thanks,
Oliver
Oliver