We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Save and Retrieve documents from a database table

Thread ID:

Created:

Updated:

Platform:

Replies:

51269 Nov 1,2006 12:31 PM May 7,2007 07:55 AM ASP.NET Web Forms (Classic) 7
loading
Tags: DocIO
Scott Glover
Asked On November 1, 2006 12:31 PM

We are currently evaluating DocIO for use in an ASP.NET application. We need the following capabilities and would like to know if and how the product can provide them.

1. Save a Doc file into a SQL Table column. We currently do this with custom code and a VarBinary column data type. The file will be uploaded via the browser.

2. Retrieve a document from a SQL table column into a DocIO document object.

3. Ability to update predefined Book Marks within the document with data supplied via program variables.

4. Send the document to the user’s browser and have it open directly in MS Word application.

NOTE: All of the above needs to be done without the need to access the file system of our web application server.

Dhivya K [Syncfusion]
Replied On November 2, 2006 09:43 AM

Hi Scott,

Thank you for your interest in Essential DocIO.

We do have support for saving and retrieving the word document from a database without accessing fileserver using memory stream.
I will provide you with a sample by tomorrow.

Regards,
Dhivya.

Dhivya K [Syncfusion]
Replied On November 6, 2006 08:20 AM

Hi Scott,

Sorry for the delay in getting back to you.

Here are some code snippet for doing the following:
1. Save a Doc file into a SQL Table column.

//Open the file as stream
Stream Sample = new MemoryStream();
Sample = new FileStream(Server.MapPath("sample.doc"), FileMode.Open, FileAccess.ReadWrite);

//store the bytes in a array
byte[] aDocByteArray = new Byte[Sample.Length];
Sample.Read(aDocByteArray, 0, System.Convert.ToInt32(Sample.Length));
Sample.Seek(0, SeekOrigin.Begin);

//Save it to database as binary
SqlParameter myParameter = new SqlParameter("@doc", SqlDbType.VarBinary, aDocByteArray.Length);
myParameter.Value = aPdfDocByteArray;
mCommand.Parameters.Add(myParameter);
mCommand.ExecuteNonQuery();

2. Retrieve a document from a SQL table column into a DocIO document object.
//get the doc from the database
byte[] DocByteArray = (byte[])myCommand.ExecuteScalar();

//Create a FileStream
FileStream fs = new FileStream("Sample.doc", FileMode.Create);
fs.Write(DocByteArray, 0, System.Convert.ToInt32(DocByteArray.Length));
fs.Seek(0, SeekOrigin.Begin);


3. Ability to update predefined Book Marks within the document with data supplied via program variables.
//open the document from database
WordDocument ldoc = new WordDocument(OpenDatabase(Conn));

//Add some bookmarks
AddBookmarks(ldoc);

4. Send the document to the user’s browser and have it open directly in MS Word application.
// Creating a memory Stream.
MemoryStream ms = new MemoryStream();

// Save the pdf document to the Stream.
ldoc.Save(ms,FormatType.Doc);
Response.OutputStream.Write(formSample.GetBuffer(), 0, formSample.GetBuffer().Length);

Currently we do not have support for opening a word document as stream.Hence you have to save the document as file when you retrieve the document from database[in step 2].I will consult with development team regarding this feature and send you an update as soon as I hear back.

Here is a sample for your reference:
SaveToDatabase.zip

Please let me know if you have any other queries.

Regards,
Dhivya.

Dhivya K [Syncfusion]
Replied On November 6, 2006 09:36 AM

Hi Scott,

Regarding the 2nd step[save to file],you can save to memory while retrieving and open it as stream using DocIO which allows to do all the operarions without accessing file server.[Sorry for the confusion!]

Here is the code snippet.
MemoryStream ms = new MemoryStream();
ms.Write(DocByteArray, 0, System.Convert.ToInt32(DocByteArray.Length));
ms.Seek(0, SeekOrigin.Begin);

//open the document from database
WordDocument ldoc = new WordDocument();
ldoc.Open(ms);

Here is the modified sample for your reference
SaveToDatabase.zip

Please let me know if you have any queries.

Regards,
Dhivya.

Raja
Replied On November 24, 2006 06:19 AM

Very Excellent and useful information.

Thanks to all.

Dhivya K [Syncfusion]
Replied On November 24, 2006 09:39 AM

Hi Raja,

Thank you for your interest in Essential DocIO. Glad to know that it helps you. Please let me know if you have any queries.

Regards,
Dhivya.

Gabi Münster
Replied On May 4, 2007 04:44 AM

Hi Dhivya,

sorry, but I can't get the changed file from your second posting. Is it still available?

Regards,
Gabi

Bhuvaneswari P [Syncfusion]
Replied On May 7, 2007 07:55 AM

Hi Gabi,

Sorry for the delay in getting back to you.

Thank you for your interest in Syncfusion products.

Herewith I have attached the sample for both loads the document from Database and save the document into the database.

http://websamples.syncfusion.com//samples/DocIO.Windows/F54716_1/main.htm

Please take a look into this and let me know if you have any other queries.

Best Regards,
Bhuvaneswari.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;