Free Support Forum - aspose.com

Export/Import of styles

I tried serializing the StylesCollection to XML and got the following error in my ASPX page:
To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. Aspose.Words.StyleCollection does not implement Add(System.Object).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. Aspose.Words.StyleCollection does not implement Add(System.Object).

Is there a recommended way to export/import styles of a document? This is a requirement for a solution we’re building for a client. We need to be able to save the styles to the database and apply those styles to a document.
Thanks,
G

btw, when I try this as a work around:
List<Aspose.Words.Style> styleCollection = new List<Aspose.Words.Style>();
foreach (Aspose.Words.Style s in styles)
{
styleCollection.Add(s);
}
And try to serialize my styleCollection I get the following error:
Aspose.Words.Style cannot be serialized because it does not have a parameterless constructor.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Aspose.Words.Style cannot be serialized because it does not have a parameterless constructor.

Hi Giancarlo,

Thanks for your inquiry.

Yes I'm afraid the styles class and most of the other Aspose.Words classes are not serializable. Instead if you want to store a style, most likely you will need to copy the style into a blank document. You can find a way to do this using the code provided by Alexey here. After copying the style you can then convert the document to a byte array as described here and store this.

Please let us know if such a technique is suitable for you.

Thanks,

So there isn’t a way I can say create a document template (.dotx) file, style it, and save it to the database, then when generating a document generate it from that template and add the text? This would essentially be “saving the style” without all the verbose code no? Maybe the library doesn’t allow for this or I’m not looking in the right place. Also, maybe I’m confused as to what a dotx file is. Can you offer some advice on this?
Thanks,
G

Hello,

Thank you for your inquiry.
We will not support serialization of styles. In any case you would need to keep the styles in some document. You can create a document that will be necessary for you to copy the styles and use it as storage. We have an appropriate issue in our defect database. I linked your request to it. As soon as a more convenient and flexible way to copy styles between documents will be implemented, we'll let you know.

Hi there,

Thanks for your inquiry. Yes, of course you can store the styles in the document and store this document within your database without needing the extra coding. You can retrieve the document and then load it like a normal document and add text.

A DOTX file is a template document that it used to provide the base styles and formatting for other documents. At the core it is just a normal DOCX document and can be loaded using Aspose.Words in the same way as a regular document.

If you have any further queries, please feel free to ask.

Thanks,

The issues you have found earlier (filed as WORDSNET-1268) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(46)