Reading Document from SQL Database

May 14, 2014 at 3:40 AM
Edited May 14, 2014 at 4:08 AM
Hey Guys,
I used the solutions to create a document with C# and replace the Placeholders successfully.
I will try now if I can do this too on the web server.

Here is my question: Instead of creating the document with C# can I read the file from the database (bytes) and convert it to a doc where I save it on the server.

I might have to say I can read the documents and its then like this in a bytes array.
now I have to move it into a DocX letter variable? I am still trying to achieve this but maybe I go to about this the wrong way.

I tried a few things which failed. I have a look further into it as I need to do this job :)

Any tips are welcome.

May 14, 2014 at 4:06 PM

Check this:

Accepted answer is what I was using. Taking template from db, using Memory Stream and using DocX on it. But i was using all that in desktop app. Not anywhere else.

With regards,
Marked as answer by MadBoy on 6/3/2014 at 3:22 AM
May 14, 2014 at 11:32 PM
Thank you Madboy

That might be what I was looking for. I will investigate it and try it out. Will post here if I succeed.

There is on variable I saw I cannot figure out. May I ask if you kindly can help with the definition of "Locale" ?

With Regards,
May 23, 2014 at 2:03 AM
Edited May 23, 2014 at 2:03 AM
no need to reply anymore... I found a working solution...

if anyone is interested please let me know
Jul 29, 2014 at 4:37 PM
i was able to get it to work using linq

dbEntities cDB = new dbEntities ();
        var first = cDB.Contracts.FirstOrDefault(p => p.IdkEY == 3);
        var ms = new MemoryStream(first.Content);

            using (DocX doc = DocX.Load(ms))
Aug 7, 2014 at 11:42 PM
Great Sam_Reg...

Sorry I am to busy solving a coms error when changing .docx to .Pdf. looks like I am not the only when look through all the google links :)