Logo
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
EPL Standings
 
 
Windows Server

Microsoft Dynamics CRM 4.0 : SharePoint Integration - Store Attachments in SharePoint Using a Custom Solution

2/18/2013 6:42:24 PM

SharePoint is one of the market leaders for a document management and collaboration solution. This feature can be used with Microsoft Dynamics CRM to increase team productivity in organizations. For example, although you can attach documents as notes in Microsoft Dynamics CRM, that capability has inherent limitations. You cannot, for instance, search the contents of the attachments using the built-in features. Therefore, there is a strong need to leverage the document management and search capabilities of SharePoint inside Microsoft Dynamics CRM because we are offloading the storage of document attachments to SharePoint.

In this example, we show you how to manage and access the documents stored in SharePoint. We create a separate entity in Microsoft Dynamics CRM that will allow us to have the same document linked to multiple entities in the CRM. For this example, you need to do the following:

  • Create a custom button at the top of the entity in which you want to store the document integration.

    • Create a site to hold the document libraries.[*]

      [*] This can be automatic, to manage growth of the number of documents that will be stored.

    • Create a document library to hold the documents.[*]

  • Create a new entity in Microsoft Dynamics CRM to store the ID for the document.

    • Attribute for the OrganizationID

    • Attribute for the entity linked to the document in CRM

    • Attribute for the EntityID

    • Attribute for the SharePoint site URL storing the document library

    • Attribute for the SharePoint document library storing the document

    • Attribute for the SharePoint DocumentID

  • Create a custom ASPX application to upload documents into SharePoint.

  • Customize the isv.config inside the Microsoft Dynamics CRM to show a new attachments link.

  • Add a new tab in the entity to show the documents for that entity using URL filtering inside SharePoint.

To create a SharePoint site, follow these steps:

1.
Open the SharePoint website in a web browser.

2.
On the top navigation bar, select Sites to open the site directory.

3.
On the Site Actions menu, click Create Site.

4.
Enter the following information to create the site:

Title: CRM Document Store

Description: To store documents for CRM attachments

URL: http://<SharePoint Server>/SiteDirectory/CRMDocuments

Permissions: Use the same permissions as the parent site

5.
Click the Show link on the top navigation bar.

6.
Select the site categories in which to display the site directory.

7.
Select a blank template to use as a basis for the site.

To create a document library, follow these steps:

1.
Navigate to the new site.

2.
On the top link bar, click Site Actions.

3.
Select Create.

4.
On the Create page, select Document Library, and enter the following information:

Name: CrmDocLib1

Description: Document library to store attachments

5.
In the Navigation section, click Yes to put a link to this document library on the Quick Launch bar.

To create a column in a SharePoint document library, follow these steps:

1.
Select the Settings drop-down.

2.
Select Create Column.

3.
Enter the following properties:

Column name: CRMRecordID

Type: Single or multiple lines of text

To create a new entity in Microsoft Dynamics CRM, follow these steps:

1.
Open the Microsoft Dynamics CRM application.

2.
In the navigation pane, click Settings.

3.
Select Customization.

4.
Select Customize Entities.

5.
Click New and enter the following for the values:

Display name: CRMAttachment

Plural name: CRMAttachments

Ownership: Select organization

Duplicate detection: Ensure this is not selected

Relationships: Ensure that notes and activities are not selected

Areas: Select details

6.
Select the Primary Attribute tab, and enter the following values:

Display name: AttachmentID

Requirement level: Set to No Constraint

7.
Click Save.

To create the custom attributes, follow these steps:

1.
Open the Microsoft Dynamics CRM application.

2.
In the navigation pane, click Settings.

3.
Select Customization.

4.
Select Customize Entities.

5.
Open the newly created entity.

6.
Under Details, click Attributes.

7.
Select New and enter the following values:

Display name: CRMRecordID

Name: CRMRecordID

Requirement level: Select No Constraint

Searchable: Select No

Type: Nvarchar

IME mode: Auto

8.
Select Save and Close to close the attribute form.

9.
Repeat the steps 7 and 8 for the following attributes:

  • Attribute storing the CRM organization name (useful when there are multiple organizations)

    Display name: OrganizationID

    Name: OrganizationID

    Requirement level: Select No Constraint

    Searchable: Select No

    Type: Nvarchar

    IME mode: Auto

  • Attribute storing the name of the entity to which this attachment belongs

    Display name: EntityName

    Name: EntityName

    Requirement level: Select No Constraint

    Searchable: Select No

    Type: Nvarchar

    IME mode: Auto

  • SharePoint URL hosting as the SharePoint repository (In this example, the value should be http://<SharePoint Server>/SiteDirectory/CRMDocuments.)

    Display name: SharePointURL

    Name: SharePointURL

    Requirement level: Select No Constraint

    Searchable: Select No

    Type: Nvarchar

    IME mode: Auto

  • Document library for the document (In this example, the value should be CrmDocLib1.)

    Display name: DocumentLibraryName

    Name: DocumentLibraryName

    Requirement level: Select No Constraint

    Searchable: Select No

    Type: Nvarchar

    IME mode: Auto

  • Attribute storing the SharePoint document ID (in case a reverse lookup is required)

    Display name: SharePointDocumentID

    Name: SharePointDocumentID

    Requirement level: Select No Constraint

    Searchable: Select No

    Type: Nvarchar

    IME mode: Auto

To create the ASPX file for uploading the documents, follow these steps:

1.
Open Visual Studio (either 2005 or 2008).

2.
Select File.

3.
Select New.

4.
Select Projects.

5.
Select Visual C#.

6.
Select ASP.NET Web Application, and enter the following values:

Name: SharePointCRMUploader

Solution name: SharePointCRMUploader

7.
Click OK.

8.
On the Solution Explorer, right-click the project and select Add Web Reference, with the following properties:

URL dialog: http://<SharePointServer>/siteDirectory/CRMDocuments/_vti_bin/lists.asmx

Web service name: SharePointListsService

9.
Select Add Reference, to close the dialog box.

10.
Open the Default.aspx.cs file and enter the following lines of code for the Upload button click:

protected void UploadButton_Click(object sender, EventArgs e)
        {
            SharePointListsService.Lists listService
= new SharePointListsService.Lists();


            listService.Credentials
= System.Net.CredentialCache.DefaultCredentials;
            listService.URL
= Request.QueryString["SharePointURL"];


            string fileName = Path.GetFileName(
fileAttachment.PostedFile.FileName);
            byte[] content;
            using (
Stream fileReader
= fileAttachment.PostedFile.InputStream)
            {
                content = new byte[fileReader.Length];
                fileReader.Read(
content,
0,
fileAttachment.PostedFile.ContentLength
);
            }
            listService.AddAttachment(
                Request.QueryString["DocumentLibraryName"],
                Request.QueryString["SharePointDocumentID"],
                fileName,
                content
                );
}

					  

11.
Follow the necessary steps to sign, build, and deploy the project according to Microsoft standards.

Note

This can be made into a web part rather than a standalone ASPX application. A web part is simpy an ascx control surrounded by a SharePoint framework. That SharePoint framework lets users interact with the web part to perform basic functions (such as Close web part, Audience targeting, and inheriting cascading style sheets). A web part framework will also allow developers to be able to create connectible web parts, with other objects on the site.


To customize the isv.config to add the custom attachment link example shown previously, follow these steps:

1.
Open the Microsoft Dynamics CRM application.

2.
In the navigation pane, click Settings.

3.
Select Customization.

4.
Select Export Customizations.

5.
Select ISV Config.

6.
Select Export Selected Customizations, and save the zip in an accessible location.

7.
Extract the XML file, and open in an XML editor of your choice.

8.
Add the following lines of code in the entities where you want the Add Attachment button to show:

<Button
Icon="/_imgs/AttachmentIcon.gif"
  Url="http://<serverURL>/<UploadApplication>"
WinParams=""
WinMode="2"
>  <Titles>
    <Title LCID="1033" Text="Test" />
  </Titles>
  <ToolTips>
    <ToolTip LCID="1033" Text="Info on Test" />
  </ToolTips>
</Button>

9.
Select Customization.

10.
Select Import Customization.

To configure SharePoint to accept a URL for filtering data, follow these steps. (Before you can configure the CRM, ensure that the QueryString web part is connected to the document library.)

1.
Navigate to the new site.

2.
On the top link bar, click Site Actions.

3.
Select Edit Page.

4.
Drag and drop the QueryString web part.

5.
Configure the web part with the name of the URL parameter defined as CRMRecordID.

6.
Click OK.

7.
Select the drop-down arrow on the top right of the web part, and select Connections.

8.
Select Get Filter Values From to connect the document library.

9.
Select Exit Edit Mode.

In the following steps, we create an IFrame for each entity with the URL filter, This will show the SharePoint portal application inside Microsoft Dynamics CRM. Follow these steps to achieve this integration:

1.
Open the Microsoft Dynamics CRM application.

2.
Select Customizations from the left navigation pane.

3.
Select Customize Entities.

4.
Open the Accounts entity.

5.
Select Forms and Views.

6.
Open the form.

7.
Select Add a Tab from the Common Tasks list located on the right side.

8.
Give it a name (for example, Attachments), and then click OK.

9.
Navigate to the new tab created.

10.
Select Add a Section, and give it a friendly name (for example, SharePointAttachments). Then click OK.

11.
Select the new IFrame created.

12.
Select Add an IFrame with the following properties:

Name: SharePointAttachmentIFrame

URL: about:blank

13.
Select Form Properties from the Common Tasks list located on the right side.

14.
Select OnLoad.

15.
Click Edit.

16.
Enter the following code:

crmForm.all.tab4Tab.onclick = function()
{
if(crmForm.all.IFRAME_ SharePointIFrame.url.length < 15)
{
crmForm.all.IFRAME_iBASE.url = "http://<SharePointServer>/SiteCirectory/CRMDocuments? CRMRecordID=" + crmForm.all.accountnumber.value;
  }

					  

17.
Click OK.

18.
Select Save and Close to save the form modifications.

19.
Select Save and Close to save the entity modifications.

20.
Select the Accounts entity, and then select Publish to deploy the changes.
Top Search -----------------
- Windows Server 2008 R2 : Work with RAID Volumes - Understand RAID Levels & Implement RAID
- Windows Server 2008 R2 Administration : Managing Printers with the Print Management Console
- Configuring Email Settings in Windows Small Business Server 2011
- Windows Server 2008 R2 : Configuring Folder Security, Access, and Replication - Implement Permissions
- Monitoring Exchange Server 2010 : Monitoring Mail Flow
- Windows Server 2008 R2 :Task Scheduler
- Windows Server 2008 R2 : File Server Resource Manager
- Windows Server 2008 R2 : Installing DFS
- Exchange Server 2010 : Managing Anti-Spam and Antivirus Countermeasures
- Windows Server 2008 R2 : Configuring Folder Security, Access, and Replication - Share Folders
Other -----------------
- Microsoft Dynamics CRM 4.0 : SharePoint Integration - Custom SharePoint Development
- Windows Server 2008 R2 file and print services : Administering Distributed File System Services (part 2) - Configuring and administering DFS Replication
- Windows Server 2008 R2 file and print services : Administering Distributed File System Services (part 1) - Configuring and administering DFS Namespaces
- Customizing Dynamics AX 2009 : Number Sequence Customization
- Microsoft Systems Management Server 2003 : Queries (part 3) - Executing Queries
- Microsoft Systems Management Server 2003 : Queries (part 2) - Creating a Query
- Microsoft Systems Management Server 2003 : Queries (part 1) - Query Elements
- Microsoft Systems Management Server 2003 : Custom SMS Administrator Consoles
- System Center Configuration Manager 2007 : Operating System Install Packages and Image Packages (part 2) - Manual Image Creation, Image Deployment
- System Center Configuration Manager 2007 : Operating System Install Packages and Image Packages (part 1) - Automated Image Creation and Capture
 
 
Most view of day
- Windows Server 2008 Server Core : Compressing Data with the Compact Utility
- Manage the Active Directory Domain Services Schema : Remove Attributes from the Index
- Add an InfoPath Form Web Part to a SharePoint Web Part Page
- Microsoft Systems Management Server 2003 : Defining Parent-Child Relationships (part 2) - Installing the Secondary Site Locally from the SMS CD
- Windows Server 2003 : Analyzing Traffic Using Network Monitor (part 1)
- BizTalk 2009 : Host Integration Server 2009 - Planning Your Host Integration Server Topology
- Using Windows Live Programs (part 2) - Using Windows Live Mail
Top 10
- Automating Windows 7 Installation : Customizing Images Using Deployment Image Servicing and Management (part 3) - Servicing the Operating System in an Image , Committing an Image
- Automating Windows 7 Installation : Customizing Images Using Deployment Image Servicing and Management (part 2) - Mounting an Image , Servicing Drivers in an Image
- Automating Windows 7 Installation : Customizing Images Using Deployment Image Servicing and Management (part 1) - Viewing Information about an Image with DISM
- Automating Windows 7 Installation : Applying an Image Using ImageX
- Automating Windows 7 Installation : Capturing an Image Using ImageX
- Microsoft Visio 2010 : Creating Web Pages from Visio Drawings (part 4) - Fine-tuning Web Pages and Battling Bugs - Saving a Visio Drawing as a Web Page
- Microsoft Visio 2010 : Creating Web Pages from Visio Drawings (part 3) - Fine-tuning Web Pages and Battling Bugs - Customizing Web Page Output
- Microsoft Visio 2010 : Creating Web Pages from Visio Drawings (part 2) - Exploring Visio-Generated Web Pages
- Microsoft Visio 2010 : Creating Web Pages from Visio Drawings (part 1) - Saving as Web Page
- Microsoft Visio 2010 : Sending Visio Files in Email, Saving as PDF or XPS Files
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro