Skip to content

Commit 5ce1c26

Browse files
authored
Merge pull request #105 from Numpsy/users/rw/user_defined_1
When writing user defined properties, add a DictionaryProperty before…
2 parents 7d8129f + 3a2aff0 commit 5ce1c26

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

sources/OpenMcdf.Extensions/OLEProperties/OLEPropertiesContainer.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ public void Save(CFStream cfStream)
242242

243243
ps.PropertySet1 = new PropertySet
244244
{
245-
NumProperties = (uint)this.UserDefinedProperties.Properties.Count(),
245+
// Number of user defined properties, plus 1 for the name dictionary
246+
NumProperties = (uint)this.UserDefinedProperties.Properties.Count() + 1,
246247
PropertyIdentifierAndOffsets = new List<PropertyIdentifierAndOffset>(),
247248
Properties = new List<Interfaces.IProperty>(),
248249
PropertyContext = UserDefinedProperties.Context
@@ -251,13 +252,21 @@ public void Save(CFStream cfStream)
251252
ps.FMTID1 = new Guid(WellKnownFMTID.FMTID_UserDefinedProperties);
252253
ps.Offset1 = 0;
253254

255+
// Add the dictionary containing the property names
256+
IDictionaryProperty dictionaryProperty = new DictionaryProperty(ps.PropertySet1.PropertyContext.CodePage)
257+
{
258+
Value = this.UserDefinedProperties.PropertyNames
259+
};
260+
ps.PropertySet1.Properties.Add(dictionaryProperty);
261+
ps.PropertySet1.PropertyIdentifierAndOffsets.Add(new PropertyIdentifierAndOffset() { PropertyIdentifier = 0, Offset = 0 });
262+
263+
// Add the properties themselves
254264
foreach (var op in this.UserDefinedProperties.Properties)
255265
{
256266
ITypedPropertyValue p = PropertyFactory.Instance.NewProperty(op.VTType, ps.PropertySet1.PropertyContext.CodePage);
257267
p.Value = op.Value;
258268
ps.PropertySet1.Properties.Add(p);
259269
ps.PropertySet1.PropertyIdentifierAndOffsets.Add(new PropertyIdentifierAndOffset() { PropertyIdentifier = op.PropertyIdentifier, Offset = 0 });
260-
261270
}
262271
}
263272

0 commit comments

Comments
 (0)