MOSS 2007 and CRM 3.0 Integration Hands On Labs
Uploading Sales Literature documents to MOSS (Based on the MOSS \ CRM Image from the IW Team)
In this Hands On Lab you will see how to programmatically upload documents to MOSS 2007 in response to tasks created in the previous lab. You will create a MOSS custom list, a site column, a content type and a document library. A prewritten CRM callout and web service will be used to programmatically upload sales Literature documents to MOSS.
1. Install the file upload web service
a. Log on to VPC image MOSSCRM using the following credentials:
User name
administrator
Password
pass@word1
Domain
LITWAREINC
b. Download the UploadServiceCopier.exe from here:
http://www.walisystems.com/ws1_dlc.asp and unzip
double click UploadServiceCopier.exe.

c. In the first WSuploadService dialog box, click Next.

d. In the Select Installation Address dialog box, set the Site value to MOSS and the Virtual Directory value to be bin.
Click Next twice.

e. In the Installation Complete dialog box click Close.

2. Create a callout component
a. Build an assembly \ callout using the following:
using System;
using Microsoft.Crm.Callout;
using System.Xml;
using CRMCallout.CRM;
using System.IO;
using System.Text;
namespace CRMCallout
{
public class PostUpdateSalesLiterature : CrmCalloutBase
{
public override void PostUpdate(CalloutUserContext userContext, CalloutEntityContext entityContext, string preImageEntityXml, string postImageEntityXml)
{
string rootDirectory=@"C:\SharedDocumentSource";
//read in the XML from the new product and find the name of the item
XmlDocument doc = new XmlDocument();
doc.LoadXml(postImageEntityXml);
XmlNodeList lstProperties = doc.GetElementsByTagName("Value");
string salesLiteratureID = lstProperties[0].FirstChild.Value.ToString();
//connect to the CrmService
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
//find all the SalesLiteratureItems that belong to this Sales Literature
BusinessEntityCollection entities;
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.salesliteratureitem.ToString();
ColumnSet cols = new ColumnSet();
cols.Attributes = new string[] { "filename", "filesize", "title" };
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "salesliteratureid";
condition.Values = new string[1] { salesLiteratureID };
condition.Operator = ConditionOperator.Equal;
FilterExpression filter = new FilterExpression();
filter.Conditions = new ConditionExpression[] { condition };
query.ColumnSet = cols;
query.Criteria = filter;
entities = service.RetrieveMultiple(query);
if (entities.BusinessEntities.Length != 0) //there are SalesLiteratureItems with the updated Sales Literature
{
for(int i=0;i<entities.BusinessEntities.Length;i++)
{
salesliteratureitem entity = (salesliteratureitem)entities.BusinessEntities[i];
string documentTitle="Untitled document";
if(entity.title !=null)
{
documentTitle=entity.title.ToString();
}
try
{
// upload the file via the custom web service
CRMCallout.MOSS.Files oUploader = new CRMCallout.MOSS.Files();
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("administrator","pass@word1","litwareinc");
oUploader.Credentials=credentials;
string strPath = Path.Combine(rootDirectory, entity.filename.ToString());
string strFile = strPath.Substring(strPath.LastIndexOf("\\")+1);
string strDestination = "http://moss/Sales Literatures";
FileStream fStream = new FileStream(strPath,FileMode.Open);
byte[] binFile = new byte[(int)(fStream.Length)];
fStream.Read(binFile,0,(int)fStream.Length);
fStream.Close();
string str =oUploader.UploadDocument(strFile,binFile,strDestination);
}
catch (System.Exception ex)
{
}
}
}
}
}
}

b. Copy the callout.config.xml file to the assembly\bin folder on the server.
<callout.config version="3.0" xmlns=" http://schemas.microsoft.com/crm/2006/callout/">
<callout entity="product" event="PostCreate">
<subscription assembly="CRMCallout.dll" class="CRMCallout.PostCreateProduct">
<postvalue>name</postvalue>
</subscription>
</callout>
<callout entity="salesliterature" event="PostUpdate">
<subscription assembly="CRMCallout.dll" class="CRMCallout.PostUpdateSalesLiterature">
<postvalue>salesliteratureid</postvalue>
</subscription>
</callout>
</callout.config>
a. Right click the callout.config.xml file and choose Properties. In the callout.config.xml Properties dialog box, click the Security tab.
Click the Add button.

b. In the Select Users, Computers or Groups dialog box, enter the value everyone in the textbox and click Check Names.
Check that the entry resolves correctly and then click the OK button.

c. In the callout.config.xml Properties dialog box, ensure that the entry for Everyone is selected and assign Full Control access rights.
Click the OK button and close all open windows.

c. Choose Start, Run… and in the Run dialog enter iisreset. Click the OK button.

3. Creating a shared folder for document storage
a. Using Windows Explorer, navigate to the root of drive C:. Right click in the dialog box and choose New, Folder. Name the folder SharedDocumentSource.
Right click the new folder, choose Properties, and on the Sharing tab configure the folder to be shared giving Full Control to Everyone.
Click OK twice and close all open dialogs.

4. Creating a MOSS 2007 Custom List
a. Using Internet Explorer, navigate to http://moss.
On the Site Actions menu, choose Create.

b. In the Create web page, choose Custom List from within the Custom Lists section.

c. In the New web page, enter the name Customers for the new list and click Create.

d. In the Customers web page, select Settings and List Settings.

e. In the Customize Customers web page, click the Title link in the Columns section.

f. In the Change Columns: Customers web page, set the Column name attribute with a value of CustomerName. Leave the remaining options with their default values and click OK.

g. In the Customers web page, select New, and choose New Item.

h. In the Customers: New Item page enter the CustomerName value of Contoso. Click the OK button.

i. Repeat steps g and h, entering a CustomerName of Fabrikam.

j. Repeat steps g and h, entering a CustomerName of Northwind.

5. Creating a MOSS 2007 Site Column
a. On the Customers web page choose the Site Actions menu and select Site Settings.

b. In the Site Settings web page, choose Site Columns from the Galleries section.

c. In the Site Column Gallery web page, choose Create.

d. In the New Site Column: MOSS web page, in the Name and Type section, set the Column name attribute to be CustomerName.
Choose the Lookup (information already on this site) option and wait for the page to refresh.

e. In the New Site Column: MOSS web page, in the Group section, choose the New group option and call the group MOSS Columns.

f. In the New Site Column: MOSS web page, in the Additional Column Settings section, in the Get information from drop down list, choose Customers and in the In this column drop down list, select CustomerName.
Click the OK button.

6. Creating a MOSS 2007 Content Type
a. Navigate to the site home page and on the Site Actions menu, choose Site Settings.
On the Site Settings web page, choose Site Content Types from the Galleries section.

b. In the Site Content Type Gallery web page, choose Create.

c. In the New Site Content Type web page, enter a Name for the content type of MOSS Document.
In the Select parent content type from drop down list, choose Document Content Types and in the Parent Content Type drop down list, select Document.
Select the New group radio button and enter a new group name of MOSS Content Types.
Click the OK button.

d. In the Site Content Type: MOSS Document web page, select the Add from existing site columns link.

e. In the Add Columns to Site Content Type: MOSS Document web page, in the Select columns from drop down list, choose MOSS Columns.
In the Available columns list box, choose CustomerName and click the Add button.
Click the OK button.

7. Creating a MOSS 2007 Document Library
a. Navigate to the site home page and click the Site Actions menu. Choose Create.

b. In the Create web page, choose Document Library from the Libraries section.

c. In the New web page, set the Name of the new Document Library as Sales Literatures.
Choose the Microsoft Office Word document option from the Document Template drop down list and click Create.

d. In the Sales Literature web page, select Settings, Document Library Settings.

e. In the Customize Sales Literatures web page, select advanced settings from the General Settings section.

f. In the Document Library Advanced Settings: Sales Literatures web page, in the Content Types section, select the Yes radio button under Allow management of content types?

g. In the Customize Sales Literatures web page, choose Add from existing site content types in the Content types section.

h. In the Add Content Types: Sales Literatures web page, in the select content types from drop down list, choose MOSS Content Types.
From the Available Site Content Types list box, choose MOSS Document and click Add.
Click the OK button.

i. In the Customize Sales Literatures web page, select the Document link in the Content Types section.

j. In the List Content Type: Document web page, choose Delete this content type from the Settings section.
In the resulting Message Box, choose Yes to confirm deletion of the content type.

k. Return to the site home page and click the Sales Literatures link in the left hand Quick Launch bar.

8. Creating a document, adding it to CRM and uploading to MOSS 2007-01-26
a. In the Sales Literature web page, choose New, MOSS Document.
Microsoft Office Word 2007 will open.

b. In the properties for the new document, enter Northwind Fire Literature in the Title text box and choose Northwind from the CustomerName drop down list.
Enter some generic text in the body of the document.

c. Save the document as Northwind Fire.docx in C:\SharedDocumentSource and close Microsoft Office Word 2007.

d. Minimise the Internet Explorer window for the MOSS site and open a new instance if Internet Explorer. Navigate to the http://moss:5555 CRM web client home page.
Click the Sales link in the left navigation.

e. Click the Sales Literature link and click New.

f. In the Title section, enter Northwind Fire Literature and choose Insurance Services in the Subject section.
Click Save and Close.

g. Double click the new Sales Literature item to open it.

h. Click the Documents link, choose New Document and in the resulting web page, enter a Title for the document of Northwind Fire Proposal and attach the document saved at C:\SharedDocumentSource\NorthwindFire.docx.
Click Save and Close to save the new document.
DO NOT SAVE AND CLOSE THE SALES LITERATURE OBJECT.

i. Click the Information link to display the Northwind Fire Literature and in the Type drop down list, select Sales Literature. Add some general notes in the Description section.
Click Save and Close.

j. Return to the http://moss site and refresh the Sales Literatures document library to display the uploaded Northwind Fire document.

Enjoy!
Philip Rawlinson (UK CRM Technical Specialist)