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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Create folder in Sharepoint from plugin in CRM Online

(0) ShareShare
ReportReport
Posted on by 1,145

Hi,

I have to create a folder in sharepoint using a plugin in CRM Online, 

I did this method but I have an error : the remote server returned an error (403) forbidden

My credentials are correct and I have the rights to create a folder. I can do that from a browser.

Thanks for help.

private void CreateFolderInSharepoint(string folderUrl, ITracingService trace)
{
try
{
System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("username", "password");
WebRequest request = WebRequest.Create(folderUrl);
request.Credentials = myCredential;
request.Method = "MKCOL";
WebResponse response = request.GetResponse();
response.Close();


}
catch (Exception ex)
{
trace.Trace(ex.ToString());
}
}


*This post is locked for comments

I have the same question (0)
  • Royal King Profile Picture
    27,686 on at

    check this one it has full code to do this

    develop1.net/.../SharePoint-Integration-Reloaded-e28093-Part-3.aspx

  • ashishkhanna Profile Picture
    180 on at

    Are you able to create folder on the same site using these credentials manually? Sometimes, you have access to SharePoint site but need admin level access to create folders.

  • saadzag Profile Picture
    1,145 on at

    Yes I can do that manually

  • Rajkumar Rajaraman Profile Picture
    on at
  • saadzag Profile Picture
    1,145 on at

    it does'nt work for crm Online

  • Suggested answer
    Aram Adnan Profile Picture
    375 on at

    Hi,

    In order to do anything in SharePoint you have to first have need authentication (cookies) and use the following class in your plugin. (MsOnlineClaimsHelper).

    www.wictorwilen.se/.../How-to-do-active-authentication-to-Office-365-and-SharePoint-Online.aspx

    Its rather old way but it works well and once you are login then you have to do following:

    1. Create SharePoint List Web Service proxy calss.

    2. Use Caml Query (xml) (to get the Document library list and view ID)

    or use List service instead of caml query to dynamically create folder .

    Here are some links:

    social.msdn.microsoft.com/.../how-to-create-folder-and-subfolder-using-web-services

    stackoverflow.com/.../creating-folders-programmatically-in-sharepoint-2013

    I have done this all many times but if you still need help in code or something. Please let em know.

    Thanks

  • Aram Adnan Profile Picture
    375 on at

    Hi raj,

    In this blog wouldn't these 2 sharepoint DLL's:

    Microsoft.SharePoint.Client.dll

    Microsoft.SharePoint.Client.Runtime.dll

    need to be register on server's GAC.  Otherwise DLL merge in plugin (mess) :)

  • saadzag Profile Picture
    1,145 on at

    Hi Adnan,

    The MsOnlineClaimsHelper needs Microsoft.SharePoint DLL.

    So as I said in the issue above, I'm working on CRM online so Idon't have access to the server to put references.

  • Suggested answer
    Aram Adnan Profile Picture
    375 on at

    who said that  MsOnlineClaimsHelper needs any SharePoint DLL, no it doesn't need anything from plugin, that is why I give you the reference so that you just need to include this class in your plugin just compile and register it no references.

    Do you have this class??
     Just comment the clientContext_ExecutingWebRequest event and use the following code for authentication.

    MsOnlineClaimsHelper obj= MsOnlineClaimsHelper(SharePointUrl, SharePointUserId, SharePointPassword);

    CookieContainer cook=obj.getCookieContainer();

    // for online sharepoint only not other
    SharePointList.CookieContainer = authCookie;
    SharePointListView.CookieContainer = authCookie;

    // now you can use both list and view web service to create a folder

  • saadzag Profile Picture
    1,145 on at

    OK i'will test that

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans