Код, который меняет ссылки: < /p>
Код: Выделить всё
bool continueing = true;
toc = WordprocessingDocument.Open(inFile, true);
HashSet seen_hrs = new HashSet();
while (continueing)
{
continueing = false;
IEnumerable all_hr = toc.MainDocumentPart.HyperlinkRelationships;
foreach (HyperlinkRelationship hr in all_hr)
{
if (seen_hrs.Contains(hr.Id))
continue;
seen_hrs.Add(hr.Id);
string link = hr.Uri.OriginalString.Replace("%20", " ");
link = link.Trim();
string link_originalName = link;
if (! (link.EndsWith(".doc") || link.EndsWith(".docx") || link.EndsWith(".dotx")))
continue;
if (link.Contains("http"))
continue;
string filename = Path.GetFileName(hr.Uri.OriginalString);
filename = filename.Replace("%20", " ");
filename = filename.Trim();
link = GetLink(filename);
if (link == "")
continue;
link_originalName = link;
var hyperlinkRelationshipId = hr.Id;
var pos = link.LastIndexOf('/');
if (pos == -1)
pos = link.LastIndexOf("\\");
var pos_point = filename.LastIndexOf('.');
var filestem = filename.Substring(0, pos_point);
string base_path = link.Substring(0, link.Length - Path.GetFileName(link_originalName).Length);
filestem = filestem.Replace('.', '_');
link = base_path + filestem + ".pdf";
toc.MainDocumentPart.DeleteReferenceRelationship(hr);
try
{
toc.MainDocumentPart.AddHyperlinkRelationship(new Uri(link, UriKind.Relative), false, hyperlinkRelationshipId);
dependents.Add(Tuple.Create(path + "\\" + link_originalName, outputPath + "\\" + link));
}
catch (Exception)
{
ui.AddError("Wrong link: " + hr.Uri.OriginalString + " in file: " + pathFile + " that could not be corrected.");
}
continueing = true;
break;
}
}
< /code>
Это по какой -то неизвестной причине не изменяет все ссылки в документе, и я не могу найти, где упоминаются другие документы. < /p>
Это часть документа Word. Все ссылки кажутся одинаковыми, ничего с формами или похожими. src = "https://i.sstatic.net/zstduoms.png"/>
Это ссылки после того, как они показывают их через Alt+f9
Я посмотрел на TOC.maindocumentpart.externalRelectionships.count () = 0 Подробнее здесь: https://stackoverflow.com/questions/796 ... cumentpart