views:

265

answers:

3

CRM saves attachements in AnnotationBase base table.

How can I convert the text in the DocumentBody entity back to file and save it the file system.

I’m comfortable with plugins and workflow activities. But can't figure how to convert a string in the database to a file on the system.

+2  A: 
using(FileStream fs = new FileStream("fileName", FileMode.Create, 
                                            FileAccess.Write))
{
    StreamWriter writer = new StreamWriter(fs);
    writer.Write(yourString);
    fs.Flush();
}

[EDIT] If we're talking about BASE64 strings then try this:

using (FileStream fs = new FileStream("fileName", FileMode.Create,
                                            FileAccess.Write))
 {
     byte[] bytes = Convert.FromBase64String(yourString);
     fs.Write(bytes, 0, bytes.Length);
     fs.Flush();
 }
AZ
No, thats not going to work with a 64BIT string.
Chris Jones
are you talking about BASE64 encoding? If so you should have specified in the question.
AZ
Hmmm, I give you the answer, but i did answer my own question. :)
Chris Jones
A: 

Grrr.

Look all day, then find the answer 5mins after posting the question.

     File.WriteAllBytes("c:\\word1.docx", System.Convert.FromBase64String(str));
Chris Jones
A: 

What about the other way. e.g. I've got a Image.jpg and wants to Upload into DocumentBody.

Jaques