internal static bool TryGetCustumXMLPart(this Document doc, string namespaceURI, out CustomXMLPart checkedPart) {
checkedPart = null;
using (CustomXMLParts parts = doc.CustomXMLParts) {
foreach (CustomXMLPart part in doc.CustomXMLParts) {
string partNamespaceURI = part.NamespaceURI;
if (partNamespaceURI == namespaceURI) {
checkedPart = new CustomXMLPart(part); << ERROR
return true;
}
}
}
return false;
}
Comments: ** Comment from web user: ekirk0 **
Instead of iterating all the custom xml use this api method and expect to only get one instance. I don't think your supposed to have more than one of the same namespace stored.
CustomXMLParts.SelectByNamespace(classNameSpace)
Have a utility class for Storing and Loading a xml serialized class.
See attached solution.
```
NetOffice.WordApi.Application app = new NetOffice.WordApi.Application();
app.DisplayAlerts = NetOffice.WordApi.Enums.WdAlertLevel.wdAlertsNone;
app.Visible = true;
// add a new document
NetOffice.WordApi.Document doc = app.Documents.Add();
//create a new storage class instance
var info = new InfoStore() { ID = 112233, Name = "hello" };
//store info into the document custom xml parts
CustomXmlPartUtil.Store<InfoStore>(doc.CustomXMLParts, info);
//load the serialized xml infoStore.
var infoSaved = CustomXmlPartUtil.Load<InfoStore>(doc.CustomXMLParts);
app.Quit();
app.Dispose();
```