locked
Create a folder in Sharepoint Online from CRM Online by code RRS feed

  • Question


  • Hi, I would like create a folder in my Sharepoint Online from my CRM Online by code.

    My Sharepoint Online is integrated to my CRM Online and the standard document management run well.

    For a customer, I must create my custom document management in the CRM. I created the documents locations by plugin, it run well, but it don't create the folder in Sharepoint. I tried several to do that, but I still have the same rights error :

    "System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

    Apparently this comes from the credentials. I use this code in my plugin :

    public static void CreateFolder(string folderName, ITracingService trace)
            {
                ListService.Lists listProxy = new ListService.Lists();
                string xmlconst = "<Batch OnError='Continue' RootFolder='https://mySharepoint/sites/crmfolder'><Method ID='1' Cmd='New'><Field Name='ID'>New</Field><Field Name='FSObjType'>1</Field><Field Name='BaseName'>!@foldername</Field></Method></Batch>";
                listProxy.Url = "https://mySharepoint/_vti_bin/lists.asmx";
                listProxy.UseDefaultCredentials = true;
                XmlDocument doc = new XmlDocument();
                string xmlFolder = xmlconst.Replace("!@foldername", folderName);
                doc.LoadXml(xmlFolder);
                XmlNode batchNode = doc.SelectSingleNode("//Batch");
                XmlNode resultNode = listProxy.UpdateListItems("tester2", batchNode);
            }

    I also tried to put my credentials directly in the code. I'm admin in CRM and Sharepoint.

    As I'm on an online CRM I can't use Sharepoint library.

    Does someone could help me ?

    Friday, November 6, 2015 6:52 PM

Answers

  • I found the solution : https://code.msdn.microsoft.com/SharePoint-Integration-c5f21604/view/Discussions#content

    Thank you for your answers ! :)

    • Marked as answer by Peach79 Wednesday, November 25, 2015 2:02 PM
    Wednesday, November 25, 2015 2:01 PM

All replies

  • Check below.

    http://journeyintocrm.com/archives/182

    Friday, November 6, 2015 8:29 PM
  • Hello,

    You are getting this error because of security restrictions, please refer more details here: https://msdn.microsoft.com/en-us/library/gg334752.aspx?f=255&MSPPError=-2147217396 you can look for the solution suggested in earlier reference


    Mahender | Our Blog
    "Make sure to click on 'Vote as Helpful' and 'Mark As Answer', if you get answer of your question

    Saturday, November 7, 2015 11:20 AM
    Moderator
  • I found the solution : https://code.msdn.microsoft.com/SharePoint-Integration-c5f21604/view/Discussions#content

    Thank you for your answers ! :)

    • Marked as answer by Peach79 Wednesday, November 25, 2015 2:02 PM
    Wednesday, November 25, 2015 2:01 PM