Hi
I have a large collection of documents where the document name needs to be changed.
Inside the document is a bookmark: “titel” where the name is stored, and I need to get that value.
But I am struggling to work out how to get the value inserted at a specific bookmark with the GetContent.GetChildElements.
I have tried something like:
var files = Directory.GetFiles(@"C:\Users\job\Desktop\IFSBRC", "*.docx", SearchOption.AllDirectories);
foreach (string fileName in files)
{
try
{
string path = Path.GetDirectoryName(fileName) + @"\";
var document = DocumentModel.Load(fileName, new DocxLoadOptions { PreserveUnsupportedFeatures = true });
document.Protection.StopProtection();
var titel = document.Bookmarks["titel"].GetContent(false).GetChildElements(ElementType.valueInstertedAtBookmarks??);
// ignore the rest...
document.Save($"{path}{titel}.docx");
Console.WriteLine($"{path}{titel}.docx");
}
catch (Exception e)
{
Console.WriteLine($"Kunne ikke åbne {fileName}");
}
}