This project has moved and is read-only. For the latest updates, please go here.

Reading Document from SQL Database

May 14, 2014 at 4:40 AM
Edited May 14, 2014 at 5: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.

Cheers
Rene
May 14, 2014 at 5:06 PM
Hello,

Check this: http://stackoverflow.com/questions/2579373/saving-any-file-to-in-the-database-just-convert-it-to-a-byte-array/2579467#2579467

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,
MadBoy
Marked as answer by MadBoy on 6/3/2014 at 3:22 AM
May 15, 2014 at 12:32 AM
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,
Rene
May 23, 2014 at 3:03 AM
Edited May 23, 2014 at 3:03 AM
no need to reply anymore... I found a working solution...

if anyone is interested please let me know
Jul 29, 2014 at 5: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 8, 2014 at 12:42 AM
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 :)