web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Creating Sharepoint document libairies & folder through CRM 4.0

(0) ShareShare
ReportReport
Posted on by 50

HI

Not sure if this is the right place but here goes.

I am trying to create a document library using a custom entity but get all kinds of errors. I can't seem to do anything with the custom entity.

I am trying to modify code for system entity, I found on the web, to do this. I am new to C#

Any help would be appreciated.

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.Crm.Sdk;

using Microsoft.Crm.SdkTypeProxy;

using SharepointFolderCreate.SharePoint ; //points to /_vti_bin/lists.asmx

using SharepointFolderCreate.CrmServiceRef; //points to myCRNServer/mscrmservices/2007/CrmServiceWsdl.aspx

 

 

// Custom Entity Name --> new_sharepointtesting

namespace MSCRMSharePoint

{

public class UpdateAccountOnCreate : IPlugin

{

#region IPlugin Memberspublic void Execute(IPluginExecutionContext context)

{

//First we'll grab the name of our account and its GUID

SharepointFolderCreate.CrmServiceRef.DynamicEntity entity = (SharepointFolderCreate.CrmServiceRef.DynamicEntity)context.InputParameters.Properties[ParameterName.Target];

string accountName = entity["name"].ToString();

string accountId = context.OutputParameters.Properties["id"].ToString();

 

//SharePoint Document Libraries have a type code of 101 Int32 spDocLibraryListType = 101;

 

//Call the SharePoint Web Service to create a document library

Lists listService = new Lists();

listService.Credentials = new System.Net.NetworkCredential("myUID", "myPW", "mydomain");

//System.Xml.XmlNode SPresult = listService.AddList(accountName, accountName + " Document Library", spDocLibraryListType);

System.Xml.XmlNode SPresult = listService.AddList(sharepointtestName, sharepointtestName + " Document Library", spDocLibraryListType);

//grab the return xml

string returnXml = SPresult.InnerXml.ToString();

 

//Now we'll update our account record with the URL of the contextual SP library

//DynamicEntity account = new DynamicEntity();

//account.Name = EntityName.account.ToString();

//account["accountid"] = new Key(new Guid(accountId));

//account["new_sharepointdocumentlibraryurl"] = "Sharepoint server" + accountName + "/Forms/AllItems.aspx";

SharepointFolderCreate.CrmServiceRef.DynamicEntity new_sharepointtesting = new SharepointFolderCreate.CrmServiceRef.DynamicEntity();

new_sharepointtesting.Name = SharepointFolderCreate.CrmServiceRef.EntityName.account.ToString();

new_sharepointtesting["new_sharepointtestingid"] = new SharepointFolderCreate.CrmServiceRef.Key(new Guid(New_sharepointtestingid));new_sharepointtesting["new_sharepointdocumentlibraryurl"] = "Sharepoint server/" + sharepointtestName + "/Forms/AllItems.aspx";

 

//Using the iPlugIn interface we create a reference to the CrmService web service

ICrmService service = SharepointFolderCreate.CrmServiceRef.context.CreateCrmService(true);

SharepointFolderCreate.CrmServiceRef.service.Update(new_sharepointtesting);

//service.Update(account);

}

#endregion

}

}

*This post is locked for comments

I have the same question (0)
  • elizas Profile Picture
    55 on at
    Re: Creating Sharepoint document libairies & folder through CRM 4.0
    It is quite easy to create an account in MS CRM using its interface but, if there is a need, it can also be achieved programmatically using its web services. This is helpful in situations where one doesn't have the access to the MS CRM Server. But one needs to add the following web service URL to the application. http:///MSCRMServices/2007/CrmServiceWsdl.aspx And enter CrmSdk as the Web Reference Name. Hope this would be helpful. http://bit.ly/cl7H0j
  • BenG Profile Picture
    155 on at
    Re: Re: Creating Sharepoint document libairies & folder through CRM 4.0

     This is where your problem is: why are you referring to account?

    new_sharepointtesting.Name = SharepointFolderCreate.CrmServiceRef.EntityName.account.ToString();

  • Adam Hubble Profile Picture
    135 on at
    Re: Creating Sharepoint document libairies & folder through CRM 4.0
    Ian, this may help you, if you still need the help. http://caughtinadotnet.blogspot.com/2010/03/creating-sharepoint-document-library-in.html
  • elizas Profile Picture
    55 on at
    Re: Creating Sharepoint document libairies & folder through CRM 4.0
    In some cases we need to add documents to the doument library programatically, the code snippet below demonstrates how to add a document to the document library . using (SPSite objSite = new SPSite("urlAddress")) { objSite.AllowUnsafeUpdates = true; using (SPWeb oSPWeb = objSite.OpenWeb()) { oSPWeb.AllowUnsafeUpdates = true; //Test1 is the document library SPList docLibrary = oSPWeb.Lists["Test1"]; using (FileStream fs = File.OpenRead(FullPath)) { Thanks, Eliza http://www.mindfiresolutions.com/Sharepoint-Support.htm
  • elizas Profile Picture
    55 on at
    Re: Re: Creating Sharepoint document libairies & folder through CRM 4.0
    For Microsoft Dynamics CRM 3.0 we can create a post-create callout component that will create a contextual document library within SharePoint whenever a new Account record is created. SharePoint provides us web services that allow us to programmatically create document libraries. The code sample also then writes the URL of the document library to custom attributes in the Account entity. The contextual document library is displayed in an iFrame by some custom JavaScript in the onLoad event for the Account form in Microsoft Dynamics CRM. You can go through the below link for more detailed information on "Contextual SharePoint Document Libraries and Folders with Microsoft Dynamics CRM" blogs.msdn.com/.../contextual-sharepoint-document-libraries-and-folders-with-microsoft-dynamics-crm.aspx Hope the above finding will help you to solve you query.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans