Hi,
I'd like to load the word DOCX file from the mssql db and I made as below.
I referenced https://blazor.syncfusion.com/documentation/document-editor/opening-a-document
but, I getting an error,,, please advise how can I fix it.
Syncfusion.Compression.Zip.ZipException: Zip exception.Can't locate end of central directory record. Possible wrong file format or archive is corrupt. at Syncfusion.Compression.Zip.ZipArchive.Open(Stream stream, Boolean closeStream) at Syncfusion.DocIO.DLS.Convertors.DocxParser.Read(Stream docStream, WordDocument document) at Syncfusion.DocIO.DLS.WordDocument.OpenDocx(Stream stream) at Syncfusion.DocIO.DLS.WordDocument.OpenInternal(Stream stream, FormatType formatType, String password) at Syncfusion.DocIO.DLS.WordDocument.Open(Stream stream, FormatType formatType)
CREATE TABLE [dbo].[BoardNotices](
[BoardId] [int] IDENTITY(1,1) NOT NULL,
[BoardType] [int] NULL,
[MessageType] [int] NULL,
[ParentId] [int] NULL,
[Title] [nvarchar](255) NULL,
[Description] [varbinary](max) NULL,
[IsPinned] [bit] NULL,
[CreatedBy] [nvarchar](255) NULL,
[Created] [datetime] NULL,
[ModifiedBy] [nvarchar](255) NULL,
[Modified] [datetime] NULL,
[CountRead] [int] NULL,
[BoardGuid] [uniqueidentifier] NULL,
[IsArchived] [bit] NULL
)
public void OnLoad(object args)
{
string documentID = "genboard.docx";
string connectionString = "Data Source=BRY-AERO;Initial Catalog=BoardCafe;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
SqlConnection connection = new SqlConnection(connectionString);
string query = "select Description from BoardNotices where BoardId = " + selectedBoardId;
SqlCommand command = new SqlCommand(query, connection);
connection.Open();
SqlDataReader read = command.ExecuteReader();
read.Read();
//Reads the Word document data as byte array from the database
byte[] byteArray = (byte[])read["Description"];
Stream stream = new MemoryStream(byteArray);
//To observe the memory go down, null out the reference of byteArray variable.
byteArray = null;
WordDocument document = WordDocument.Load(stream, ImportFormatType.Docx);
stream.Dispose();
//To observe the memory go down, null out the reference of stream variable.
stream = null;
string json = JsonConvert.SerializeObject(document);
document.Dispose();
//To observe the memory go down, null out the reference of document variable.
document = null;
SfDocumentEditor editor = container.DocumentEditor;
editor.OpenAsync(json);
//To observe the memory go down, null out the reference of json variable.
json = null;
}
Attachment: localhost1647556021974_5f03da66.zip
Hi Bryan,
Can you please confirm are you facing this issue for all the document or specific document? Can you please share the input document that will be helpful for us to proceed further and provide you the solution at the earliest?
Regards,
Suriya M.
Hi Suriya, Thanks
As I explained, I put it into the Mssql DB (column name is [Description] [varbinary](max) NULL,)
I added DocumentEditor and input the text/images/table and then save into DB directly.
and I bring it to read by MemoryStream of the OnLoad Method.
Hi Bryan,
Can you please share the input document” genboard.docx” which you have used in your sample?
Note: If you have any confidential data in your Word document, please replace with some dummy data and provide us the same. We just need your document to recreate the problem you face.
Regards,
Suriya M.