Is there is any way to modify / add new properties?
FoggyFinder opened this issue · 14 comments
I want to have ability modify or add some properties. I tried to do something like that:
var stream = (CFStream)item;
var containter = ((CFStream)item).AsOLEPropertiesContainer();
containter.NewProperty(OpenMcdf.Extensions.OLEProperties.VTPropertyType.VT_INT, 78787878, "Some test property");
var pr = containter.Properties.First(p => p.PropertyName.Contains(name));
pr.Value = "This is a new test value";
But when I'd opened file I didn't see any changes.
Am I doing it in wrong way or it is current library limitation?
Try calling Save on the OLEPropertiesContainer and/or CompoundFile ?
I tried - doesn't work either
@FoggyFinder OLEProperties are currently in development stage. I'll try to give a look at your issue this week but I'm currently involved in other work activities and i can't give a definite time schedule for full implementation. Thank you for your patience.
Hello @ironfede, do you have any update on this? It would be nice to be able to add new properties to the DocumentSummaryInformation. Thank you.
I tried having a go at adding/manipulating properties in the document summary information set, using
using (CompoundFile cf = new CompoundFile("_Test.ppt"))
{
var dsiStream = cf.RootStorage.GetStream("\u0005DocumentSummaryInformation");
var co = dsiStream.AsOLEPropertiesContainer();
co.Properties.First(prop => prop.PropertyName == "PIDDSI_COMPANY").Value = "RHUBARB";
var newProp = co.NewProperty(OpenMcdf.Extensions.OLEProperties.VTPropertyType.VT_LPSTR, 0x0000000E, "PIDDSI_MANAGER");
newProp.Value = "The Boss";
co.AddProperty(newProp);
co.Save(dsiStream);
cf.SaveAs(@"S:\test\test.ppt");
}
And it appeared to work, except that the manager value is displayed ok in structured storage explorer but is shown as The Bos
in power point.
I think the issue is that the strings are supposed to be written into the file with null terminator characters included in the length, and the current OpenMcdf function doesn't do it -
So I guess that powerpoint must be cutting off the last char or something, rather than the last null?
I'll have a go at making
write an extra null byte when i get some time.I think the main functionality for writing properties should be working now, besides the other case with unaligned strings discussed in #98
Many thanks @Numpsy .
I close this issue to mark advancements in this subject.
Thank you!
I have tried this code:
Dim cfg As CFSConfiguration = CFSConfiguration.SectorRecycle Or CFSConfiguration.EraseFreeSectors
Dim fs = New FileStream("C:\Users\stazione41\Documents\cil2.par", FileMode.Open, FileAccess.ReadWrite)
Dim cf As CompoundFile = New CompoundFile(fs, CFSUpdateMode.Update, cfg)
Dim foundStream As CFStream = cf.RootStorage.GetStream("�SummaryInformation")
Dim c As OLEPropertiesContainer = foundStream.AsOLEPropertiesContainer
c.Properties(2).Value = "801050004 MODIFICATO"
'c.Save(foundStream)
'cf.Save(foundStream.AsIOStream)
'cf.Commit()
cf.Close()
I read and modify the property Title correctly, however I'm not able to save it
With cf.Commit the change to the property Title it's not saved
With c.Save(foundStream) the Document properties are no longer visible
With cf.Save(foundStream.AsIOStream) the code never terminate
Any suggestion or there are code changes on their way?
Try doing c.Save(foundStream) followed by cf.Commit() ?
There are some tests that update properties at
and I have apps working with it, though there are still a few bugs in it, e.g. #128That does look to be the problem - If I just use OpenMcdf to open and then save the SummaryInformation section in that file without any other changes then StructuredStorageExplorer gets an error when trying to read it afterwards, and it seems ok when ising the changes from #128.
Many thanks @Numpsy this code works now
Dim cfg As CFSConfiguration = CFSConfiguration.SectorRecycle Or CFSConfiguration.EraseFreeSectors
Dim fs = New FileStream("C:\Users\stazione41\Documents\cil2.par", FileMode.Open, FileAccess.ReadWrite)
Using cf As CompoundFile = New CompoundFile(fs, CFSUpdateMode.Update, cfg)
Dim dsiStream As CFStream = cf.RootStorage.GetStream("�SummaryInformation")
Dim co As OLEPropertiesContainer = dsiStream.AsOLEPropertiesContainer
Dim titleProp = co.Properties.First(Function(Prop) Prop.PropertyName = "PIDSI_TITLE")
titleProp.Value = "XXXX PROVA"
co.Save(dsiStream)
cf.Commit()
End Using