This is a migrated thread and some comments may be shown as answers.

[Solved] importing Byte array using DocxFormatProvider

1 Answer 702 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
jaimin
Top achievements
Rank 1
jaimin asked on 04 Nov 2010, 12:27 AM
hi,
i am using latest version of RadControls in which you provided extended API for importing/exporting from/to byte array for binary formats.

 I am using DocxFormatProvider.
 use export API to save Byte Array in database.
 and import API to load the Byte Array.

Following is the property i am using in View Model

 

 

public RadDocument ParDocument

 

{

 

 

 

get

 

 

{

 

 

RadDocument doc = new RadDocument();

 

 

 

 

if(Particular != null && Particular.wp_perticulars != null)

 

{

doc = provider.Import(Particular.wp_perticulars);

}

 

 

 

return doc;

 

}

 

 

 

set

 

 

{

 

 

MemoryStream output = new MemoryStream();

 

provider.Export(

 

 

value,output);

 

Particular.wp_perticulars = output.GetBuffer();

}

}

 



in which wp_perticulars is image DataType in database.
The problem is it exporting fine and saving byte array in database.
when i am importing the byte array. its give me error "Invalid data".

Error During import:
{System.InvalidOperationException: Invalid data.
   at Telerik.Windows.Documents.Packaging.ZipPackage.Open(Stream stream, FileAccess access)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.Import.DocxImporter..ctor(Stream input)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.DocxFormatProvider.Import(Stream input)
   at Telerik.Windows.Documents.FormatProviders.DocumentFormatProviderBase.Import(Byte[] input)
   at PolicyEditor.ViewModels.ParticularSectionViewModel.get_ParDocument()
   at PolicyEditor.Views.ParticularsSection.Loadparticular(String param)}



can you please advice me what i have to do.??

Thanks
Jaimin


1 Answer, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 08 Nov 2010, 05:20 PM
Hi jaimin,

In fact your implementation of the Import function works fine. It is the Export function that does not work correctly and the documents that it produces are not valid DOCX files. Thus the exception you get on Import.
The straight-forward way to accomplish what you want is:

Particular.wp_perticulars = provider.Export(value);
Another option would be:
provider.Export(value, output);
Particular.wp_perticulars = output.ToArray();

The GetBuffer() method, however, returns an array which can have allocated unused bytes as described in this MSDN article and it will no longer represent a valid DOCX document.

Try this out and let us know if it helped.


Regards,
Iva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
RichTextBox
Asked by
jaimin
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Share this question
or