/** * Create a new child POIXMLDocumentPart * * @param descriptor the part descriptor * @param factory the factory that will create an instance of the requested relation * @param idx part number * @param noRelation if true, then no relationship is Added. * @return the Created child POIXMLDocumentPart */ protected RelationPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, bool noRelation) { try { PackagePartName ppName = PackagingUriHelper.CreatePartName(descriptor.GetFileName(idx)); PackageRelationship rel = null; PackagePart part = packagePart.Package.CreatePart(ppName, descriptor.ContentType); if (!noRelation) { /* only add to relations, if according relationship is being Created. */ rel = packagePart.AddRelationship(ppName, TargetMode.Internal, descriptor.Relation); } POIXMLDocumentPart doc = factory.NewDocumentPart(descriptor); doc.packageRel = rel; doc.packagePart = part; doc.parent = this; if (!noRelation) { /* only add to relations, if according relationship is being Created. */ AddRelation(rel, doc); } return(new RelationPart(rel, doc)); } catch (PartAlreadyExistsException pae) { // Return the specific exception so the user knows // that the name is already taken throw pae; } catch (Exception e) { // Give a general wrapped exception for the problem throw new POIXMLException(e); } }