SBX - Search With Button

SBX - Forum Post Title

how to read :DocumentBody from AnnotationBase table

Microsoft Dynamics CRM Forum

Arif Imteyaz asked a question on 22 Dec 2015 6:19 AM
My Badges

Question Status

Suggested Answer

SELECT DocumentBody, MimeType

FROM AnnotationBase 

how to read DocumentBody from sql .

Reply
Suggested Answer

The DocumentBody is a base64 encoded string, so you'll need to convert back to binary and save to a file.

For an online converter see - www.motobit.com/.../base64-decoder-encoder.asp

For doing this in c# use File.WriteAllBytes(@"c:\yourfile", Convert.FromBase64String(yourBase64String));

To do this in SQL is a bit tricky - see blogs.msdn.com/.../converting-from-base64-to-varbinary-and-vice-versa.aspx

Hope this helps!

Reply

How did you get on? Did this answer your question?

Reply
Arif Imteyaz responded on 24 Dec 2015 2:08 AM
My Badges

Thanks Scott.....

i am trying to write small API in .Net ...

Reply
Suggested Answer

Then you will need to retrieve the base64 string from the document body and then convert to a binary array and save to a file - see  stackoverflow.com/.../converting-a-base-64-string-to-an-image-and-saving-it

I hope this answers your question?

Reply
Luis Marques2 responded on 25 Apr 2019 12:05 PM

Hi,

I am working with CRM 4.0 and I had a similar issue where the document body column where it seems to be limited by 43679 and with that it gives me an error about an invalid Base 64 string.

'The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.'

It seems the file would have more than that to write on that field as the note was a pdf on this CRM 4 database.

The reason why I am trying to do it via code is to recover a few documents that were deleted but still exist in a earlier day backup.

Any ideas how to recover it?

Thanks,

Luis

Reply
Suggested Answer

The DocumentBody is a base64 encoded string, so you'll need to convert back to binary and save to a file.

For an online converter see - www.motobit.com/.../base64-decoder-encoder.asp

For doing this in c# use File.WriteAllBytes(@"c:\yourfile", Convert.FromBase64String(yourBase64String));

To do this in SQL is a bit tricky - see blogs.msdn.com/.../converting-from-base64-to-varbinary-and-vice-versa.aspx

Hope this helps!

Reply
Suggested Answer

Then you will need to retrieve the base64 string from the document body and then convert to a binary array and save to a file - see  stackoverflow.com/.../converting-a-base-64-string-to-an-image-and-saving-it

I hope this answers your question?

Reply

SBX - Two Col Forum

SBX - Migrated JS