Summary:

A customer had a requirement to use the .NET API to write binary data to the outputstream. Their exact requirment was to use the .NET API to create a PDF file on the server, then embed the file in a CRM screen. the following shows a method for creating a PDF file in CRM's library, then embedding the document within the page.

More information:

You can write the binary data as a pdf to the server using the technique shown in the example below. This example creates a "Hello World" pdf, then embeds it in the CRM screen.

using System;
using System.Collections.Generic;
using System.Text;
using Sage.CRM.WebObject;
using Sage.CRM.Data;
using Sage.CRM.Utils;
using System.IO;

namespace PDFPage
{
    public class MyCustomPage : Web
    {
        public override void BuildContents()
        {
            //Get the Library directory from the custom_sysparams table
            string docStore = Metadata.GetParam(Sage.ParamNames.DocStore);
 
            string base64EncodedPDF = "JVBERi0xLjcNCg0KMSAwIG9iaiAgJSBlbnRyeSBwb2"
                + "ludA0KPDwNCiAgL1R5cGUgL0NhdGFsb2cNCiAgL1BhZ2VzIDIgMCBSDQo+Pg0K"
                + "ZW5kb2JqDQoNCjIgMCBvYmoNCjw8DQogIC9
UeXBlIC9QYWdlcw0KICAvTWVkaW"
                + "
FCb3ggWyAwIDAgMjAwIDIwMCBdDQogIC9Db3VudCAxDQogIC9LaWRzIFsgMyAw"
                + "IFIgX
Q0KPj4NCmVuZG9iag0KDQozIDAgb2JqDQo8PA0KICAvVHlwZSAvUGFnZQ"
                + "
0KICAvUGFyZW50IDIgMCBSDQogIC9SZXNvdXJjZXMgPDwNCiAgICAvRm9udCA8"
                + "PA
0KICAgICAgL0YxIDQgMCBSIA0KICAgID4+DQogID4+DQogIC9Db250ZW50cy"
                + "A1IDAgUg0
KPj4NCmVuZG9iag0KDQo0IDAgb2JqDQo8PA0KICAvVHlwZSAvRm9u"
                + "dA0K
ICAvU3VidHlwZSAvVHlwZTENCiAgL0Jhc2VGb250IC9UaW1lcy1Sb21hbg"
                + "0K
Pj4NCmVuZG9iag0KDQo1IDAgb2JqICAlIHBhZ2UgY29udGVudA0KPDwNCiAg"
                + "L0xlbmd0
aCA0NA0KPj4NCnN0cmVhbQ0KQlQNCjcwIDUwIFREDQovRjEgMTIgVG"
                + "YNCihIZWxsbywgd29ybGQhKSBUag0KRVQNCmV
uZHN0cmVhbQ0KZW5kb2JqDQoN"
                + "
CnhyZWYNCjAgNg0KMDAwMDAwMDAwMCA2NTUzNSBmIA0KMDAwMDAwMDAxMCAwMD"
                + "AwMCBuIA
0KMDAwMDAwMDA3OSAwMDAwMCBuIA0KMDAwMDAwMDE3MyAwMDAwMCBu"
                + "IA0K
MDAwMDAwMDMwMSAwMDAwMCBuIA0KMDAwMDAwMDM4MCAwMDAwMCBuIA0KdH"
                + "J
haWxlcg0KPDwNCiAgL1NpemUgNg0KICAvUm9vdCAxIDAgUg0KPj4NCnN0YXJ0"
                + "eHJlZg0KNDkyDQolJUVPRg==";


            // Create the new, empty pdf file in the library folder.
            string fileName = docStore + "sample.pdf";
 
            FileStream fs = new FileStream(fileName, FileMode.Create);

            // Create the writer for data.
            BinaryWriter w = new BinaryWriter(fs); 

            // Write data to sample.pdf.
            w.Write(Convert.FromBase64String(base64EncodedPDF));

            w.Close();
            fs.Close();

            string strResponse = "<html><head><title>PDFObject example</title>"
                + "<script type='text/javascript' src='/CRM72/js/custom/pdfobject.js'></script>"
                + "<script type='text/javascript'>window.onload = function (){"
                + "var myPDF = new PDFObject({ url: 'sample.pdf' }).embed();};</script></head><body>"
                + "<p>It appears you don't have Adobe Reader or PDF support in this webbrowser. "
                + "<a href='sample.pdf'>Click here to download the PDF</a></p></body></html>";

            AddContent(strResponse);
        }
    }
}

This is just an example; the correct location for the file within the Library can be retrieved by using the GetContextInfo method.