I try to set different properties in diagram but it seems not to work at all:
var diagramProperties = _diagram.DocumentProps;
diagramProperties.Title = “sample title”;
works
but
diagramProperties.Creator = “test1”;
diagramProperties.Manager = “test2”;
do not work. I did not test all other built in so far…
Also I want to add custom property values which do not work too for me atm:
var customProperties = diagramProperties.CustomProps;
for (var i = 0; i < customProperties.Count; i++)
{
if (customProperties[i].Name == name && customProperties[i].PropType == PropType.String)
customProperties[i].CustomValue.ValueString = value;
}
Something I do wrong ???
Hi Yves,
Hi Yves,
Hello,
thank you for your tests. I downloaded the latest version again and retried. Still same results. So I post some detailed information.
My Test code of my class (attached the visio test files and the visio.cs):
// test visio
Console.WriteLine("*** VISIO ***");
var vsd = new Visio { Company = company };
Console.WriteLine(vsd.Load(testFilesPath + “visio.vsd”));
Console.WriteLine(“Source file type is:” + vsd.FileFormat);
// list available form fields
Console.WriteLine(vsd.FormFields()); // not implemented yet
// set document properties
vsd.SetProperty(“author”, “Mr. Spunt”);
vsd.SetProperty(“manager”, “Sir Pipo”);
vsd.SetProperty(“title”, “sample title”);
vsd.SetProperty(“guid”, Guid.NewGuid().ToString());
// set formfields
vsd.SetFormFieldValue(“FIELD1”, DateTime.Now.ToString()); // not implemented yet
vsd.SetFormFieldValue(“FIELD2”, “SAMPLE TEXT”); // not implemented yet
// save document
vsd.SaveAs(testFilesPath + @“out\visio_output.vsdx”, “vsdx”);
// reload to check values
vsd.Load(testFilesPath + @“out\visio_output.vsdx”);
// show properties
Console.WriteLine("author: " + vsd.GetProperty(“author”));
Console.WriteLine("guid: " + vsd.GetProperty(“guid”));
Console.WriteLine("manager: " + vsd.GetProperty(“manager”));
Console.WriteLine("title: " + vsd.GetProperty(“title”));
// show values
Console.WriteLine("FIELD1: " + vsd.GetFormFieldValue(“FIELD1”));
Console.WriteLine("FIELD2: " + vsd.GetFormFieldValue(“FIELD2”));
// create pdf document
vsd.SaveAs(testFilesPath + @“out\visio_output.pdf”, “pdf”);
Console.WriteLine(“DONE…”);
Console.ReadKey();
Hi Yves,
Aspose.Diagram.License licDiagram = new Aspose.Diagram.License();
licDiagram.SetLicense(licFilePath);
// load VSD diagram and set its properties
Diagram diagram = new Diagram(@“C:\temp\visio.vsd”);
diagram.DocumentProps.Creator = “Mr. Spunt”;
diagram.DocumentProps.Manager = “Sir Pipo”;
diagram.DocumentProps.Title = “sample title”;
for (var i = 0; i < diagram.DocumentProps.CustomProps.Count; i++)
{
if (diagram.DocumentProps.CustomProps[i].Name == “guid” && diagram.DocumentProps.CustomProps[i].PropType == PropType.String)
diagram.DocumentProps.CustomProps[i].CustomValue.ValueString = Guid.NewGuid().ToString();
}
// save in the VSDX format
// load the resultant VSDX diagram and get its properties
Diagram outDiagram = new Diagram(@“C:\temp\visio_output.vsdx”);
Console.WriteLine("author: " + outDiagram.DocumentProps.Creator);
string guide = “”;
for (var i = 0; i < outDiagram.DocumentProps.CustomProps.Count; i++)
{
if (outDiagram.DocumentProps.CustomProps[i].Name == “guid”)
guide = outDiagram.DocumentProps.CustomProps[i].CustomValue.ToString();
}
Console.WriteLine("guid: " + guide);
Console.WriteLine("manager: " + diagram.DocumentProps.Manager);
Console.WriteLine("title: " + diagram.DocumentProps.Title);
Here we go,
for the custom property I forgot to add it before. Me only handled existing ones…
So now I add
customProperties.Add(new CustomProp {Name = name, PropType = PropType.String, CustomValue = {ValueString = value}});
if the custom property name is not found. The document contains the custom property with its value now.
Strange thing is reading it.
return customProperties[i].CustomValue.ToString();
or
return customProperties[i].CustomValue.ValueString;
returns “Aspose.Diagram.CustomProp” instead of the value.
About built in properties it is strange as well:
The following code can e.g. set “author” ( => .Creator ) but not Keywords or Manager:
public void SetProperty(string name, string value)
{
if (string.IsNullOrEmpty(_path)) return;
var diagramProperties = _diagram.DocumentProps;
switch (name.ToLower())
{
case “category”:
diagramProperties.Category = value;
break;
case “author”:
diagramProperties.Creator = value;
break;
case “manager”:
diagramProperties.Manager = value;
break;
case “keywords”:
diagramProperties.Keywords = value;
break;
case “subject”:
diagramProperties.Subject = value;
break;
case “title”:
diagramProperties.Title = value;
break;
// custom property
default:
var customProperties = diagramProperties.CustomProps;
for (var i = 0; i < customProperties.Count; i++)
{
if (customProperties[i].Name != name || customProperties[i].PropType != PropType.String) continue;
customProperties[i].CustomValue.ValueString = value;
break;
}
customProperties.Add(new CustomProp {Name = name, PropType = PropType.String, CustomValue = {ValueString = value}});
break;
}
}
Hi Yves,
rausch:if the custom property name is not found. The document contains the custom property with its value now.Strange thing is reading it.return customProperties[i].CustomValue.ToString();orreturn customProperties[i].CustomValue.ValueString;returns “Aspose.Diagram.CustomProp” instead of the value.
Diagram diagram = new Diagram(@“C:\temp\visio.vsd”);
diagram.DocumentProps.Category = “Some Category”;
diagram.DocumentProps.Creator = “Mr. Spunt”;
diagram.DocumentProps.Manager = “Sir Pipo”;
diagram.DocumentProps.Keywords = “Keywords”;
diagram.DocumentProps.Title = “sample title”;
diagram.DocumentProps.Subject = “Some Subject”;
// save in the VSDX format
diagram.Save(@“C:\temp\Aspose_out.vsdx”, SaveFileFormat.VSDX);
// load the resultant VSDX diagram and get its properties
Diagram outDiagram = new Diagram(@“C:\temp\Aspose_out.vsdx”);
Console.WriteLine("category: " + outDiagram.DocumentProps.Category);
Console.WriteLine("author: " + outDiagram.DocumentProps.Creator);
Console.WriteLine("manager: " + diagram.DocumentProps.Manager);
Console.WriteLine("keywords: " + diagram.DocumentProps.Keywords);
Console.WriteLine("title: " + diagram.DocumentProps.Title);
Console.WriteLine("subject: " + diagram.DocumentProps.Subject);
Hi Yves,
The issues you have found earlier (filed as DIAGRAMNET-50644) have been fixed in Aspose.Diagram for .NET 5.9.0.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
I tested and it works now for me, thank you. Interesting that the history of bugfixes do not list the fix :).
I still facing the problem that manager and keyword can not be set, only author works. But this may be possible problem of my code, when I have more time I will take a deeper look at this.
Hi Yves,
- What is the Operating System name, edition and 32 & 64 bit (e.g. Windows 7 Ultimate 64 bit)
- What is the .NET Framework version?
- Which IDE are you using and what is the build version and edition e.g. Visual Studio Professional 2015
- What is the local language and settings, etc.?
- Any other information that you think is necessary.
Hello,
came back to the project and now found time for this.
System one:
OS: Windows 2008 R2
.NET: Version 4
IDE: VS 2010
Local settings: german locale
System two:
OS: Windows 2012 R2
.NET: Version 4
IDE: VS 2015
Local settings: english locale
Both system same effect.
My test code:
// test visio
Console.WriteLine("*** VISIO ***");
var vsd = new Visio { Company = company };
Console.WriteLine(vsd.Load(testFilesPath + “visio.vsd”));
Console.WriteLine(“Source file type is:” + vsd.FileFormat);
// list available form fields
[//Console.WriteLine](https://console.writeline/)(vsd.FormFields()); // not implemented yet
// set document properties
vsd.SetProperty(“author”, “Mr. Spunt”);
vsd.SetProperty(“manager”, “Sir Pipo”);
vsd.SetProperty(“title”, “sample title”);
vsd.SetProperty(“keywords”, “key1 key2 key3”);
vsd.SetProperty(“guid”, Guid.NewGuid().ToString());
// set formfields
[//vsd.SetFormFieldValue](https://vsd.setformfieldvalue/)(“FIELD1”, DateTime.Now.ToString()); // not implemented yet
[//vsd.SetFormFieldValue](https://vsd.setformfieldvalue/)(“FIELD2”, “SAMPLE TEXT”); // not implemented yet
// save document
vsd.SaveAs(testFilesPath + @“out\visio_output.vsdx”, “vsdx”);
// reload to check values
vsd.Load(testFilesPath + @“out\visio_output.vsdx”);
// show properties
Console.WriteLine("author: " + vsd.GetProperty(“author”));
Console.WriteLine("guid: " + vsd.GetProperty(“guid”));
Console.WriteLine("manager: " + vsd.GetProperty(“manager”));
Console.WriteLine("keywords: " + vsd.GetProperty("keywords "));
Console.WriteLine("title: " + vsd.GetProperty(“title”));
// show values
Console.WriteLine("FIELD1: " + vsd.GetFormFieldValue(“FIELD1”));
Console.WriteLine("FIELD2: " + vsd.GetFormFieldValue(“FIELD2”));
// create pdf document
vsd.SaveAs(testFilesPath + @“out\visio_output.pdf”, “pdf”);
Console.WriteLine(“DONE…”);
Console.ReadKey();
I add the class I use and the test visio file as archive so you can have a look.
Hi Yves,
diagram.DocumentProps.Creator = “Mr. Spunt”;
diagram.DocumentProps.Manager = “Sir Pipo”;
diagram.DocumentProps.Title = “sample title”;
diagram.DocumentProps.Keywords = “key1 key2 key3”;
string value = Guid.NewGuid().ToString();
CustomPropCollection CusProps = diagram.DocumentProps.CustomProps;
for (var i = 0; i < CusProps.Count; i++)
{
if (CusProps[i].Name != “guid” || CusProps[i].PropType != PropType.String) continue;
CusProps[i].CustomValue.ValueString = value;
break;
}
CusProps.Add(new CustomProp { Name = “guid”, PropType = PropType.String, CustomValue = { ValueString = value } });
diagram.Save(@“C:\AD\test613\visio_output.vsdx”, SaveFileFormat.VSDX);
diagram = new Diagram(@“C:\AD\test613\visio_output.vsdx”);
Console.WriteLine("author: " + diagram.DocumentProps.Creator);
CustomPropCollection customProperties = diagram.DocumentProps.CustomProps;
for (var i = 0; i < customProperties.Count; i++)
{
if (customProperties[i].Name == “guid”)
Console.WriteLine("guid: " + customProperties[i].CustomValue.ValueString);
}
Console.WriteLine("manager: " + diagram.DocumentProps.Manager);
Console.WriteLine("keywords: " + diagram.DocumentProps.Keywords);
Console.WriteLine("title: " + diagram.DocumentProps.Title);
diagram.Save(@“C:\AD\test613\visio_output.pdf”, SaveFileFormat.PDF);
Console.WriteLine(“DONE…”);
Console.ReadKey();
With latest DLL from hotfix download I can approve that all values except manager like your result now are printed out with your simplified code as well as my code.
Hi Yves,
Hi Yves,
The issues you have found earlier (filed as DIAGRAMNET-50717) have been fixed in Aspose.Diagram for .NET 6.2.0.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.