SharePoint REST service to add an exsiting site content type to a list/library

Trying to use SharePoint 2013 REST Service to add existing site content types to a list/library. Below MSDN article suggests that the POST method is available but does not say how to use it.
http://msdn.microsoft.com/en-us/library/office/jj246793%28v=office.15%29.aspx#postsyntax_htm
POST http://<sitecollection>/<site>/_api/web/lists(listid)/contenttypes/add(parameters)
How do we create the body for this rest call?

Hi You need to use the addAvailableContentType method to attach a Existing Content Type to a list/Library.
Consider the below Sample. Take the Id of the Content Type and pass it.
the REST API URL is 
 http://<sitecollection>/<site>/_api/web/lists(listid)/contenttypes/addAvailableContentType(contentTypeId)
var siteUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Employees')/ContentTypes/AddAvailableContentType";
    var call = jQuery.ajax({
        url: siteUrl,
        type: "POST",
        data: JSON.stringify({            
            "contentTypeId": "0x0100E5EC1FE6D284A74A972A1776FFFE2DA0"            
        headers:
               'accept': 'application/json;odata=verbose',
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
    call.done(function (data, textStatus, jqXHR) {
        var message = jQuery("#message");
        message.text("Added Content Type Successfully");
    call.fail(function (data, errorcode, errormessage) {
        alert("Could not enable content types: " + errormessage);
Here 0x0100E5EC1FE6D284A74A972A1776FFFE2DA0 is the Content Type Id of my existing Content type "Employees"
Ensure the AllowContentTypes is set to True for that List/Library
R.Mani | http://rmanimaran.wordpress.com

Similar Messages

  • Add existing site content type to doc lib -power shell

    Add-PSSnapIn Microsoft.SharePoint.PowerShell
    #Update : incomplete on  09-feb-2015 05 pm
    $siteCollecURL = "http://sirvr11:123/sites/Engineering/WIP"
    $basicContentType="Basic Content Type"
    #$siteColl = Get-SPSite -Identity $siteCollecURL
    $paramWeb = Get-SPWeb -Identity $siteCollecURL
    Write-Host $siteColl.Url
    $pdoclib ="CY"
    $docLib = $paramWeb.Lists[$pdoclib]
              $docLib.Title
             if ($docLib -ne $null)
                $docLib.ContentTypesEnabled = $true
                $docLib.Update()
                #Add site content types to the list
                $ctToAdd = $paramWeb.ContentTypes["Basic Content Type"]
                $ctToAdd.Name
                pause
                try
                $ct = $docLib.ContentTypes.Add($ctToAdd)
                catch
                write-host "error adding Content type" $ct.Name  "to" $docLib.Title
                write-host "Content type" $ct.Name "added to list" $docLib.Title
                $docLib.Update()
    am trying to add the "BasicContent Type"  to my doc lib called "CY" with the help of above  power shells cript.
    but it failed to add .
    getting the error message.can anyone pls help where  am missing any steps /line of code.
    help is appreciated!

    Hi,
    try the following
    #Get site object and specify name of the library to look for in each site
    $site = Get-SPSite http://portal
    $lookForList = "Shared Documents"
    #Walk through each site and change content types on the list specified
    $site | Get-SPWeb -Limit all | ForEach-Object {
    write-host "Checking site:"$_.Title
    #Make sure content types are allowed on the list specified
    $docLibrary = $_.Lists[$lookForList]
    if ($docLibrary -ne $null)
    $docLibrary.ContentTypesEnabled = $true
    $docLibrary.Update()
    #Add site content types to the list
    $ctToAdd = $site.RootWeb.ContentTypes["Sales Document"]
    $ct = $docLibrary.ContentTypes.Add($ctToAdd)
    write-host "Content type" $ct.Name "added to list" $docLibrary.Title
    $ctToAdd = $site.RootWeb.ContentTypes["IT Document"]
    $ct = $docLibrary.ContentTypes.Add($ctToAdd)
    write-host "Content type" $ct.Name "added to list" $docLibrary.Title
    $docLibrary.Update()
    else
    write-host "The list" $lookForList "does not exist in site" $_.Title
    #Dispose of the site object
    $site.Dispose()
    Kind Regards,
    John Naguib
    Technical Consultant/Architect
    MCITP, MCPD, MCTS, MCT, TOGAF 9 Foundation
    Please remember to mark your question as answered if this solves your problem

  • Role Assignment Discovery Issue for Files and Folders through Sharepoint REST services

    To preface, I am a decided Sharepoint newbie in every sense. I am trying to use the Sharepoint REST services (Sharepoint 2013) to walk the folder and file structure of my Sharepoint server and, determine as I go, the Role Assignments (and subsequently
    Permissions) on those folders and files. I'm using an Administrator credentials and I'm actually able to successfully do it but I've run into some caveats. All the caveats begin with this; when I'm examining a folder, for example:
    /_api/Web/GetFolderByServerRelativeUrl('/sites/cmisdev/Development')/ListItemAllFields
    I receive either an empty list or an error response doc when following the link supplied for ListItemAllFields.  When following that kind of link for folders, I either get:
    <d:ListItemAllFields
    m:null="true"
    />
    or an error response document that says "The object specified does not belong to a list." When I hit the /ListItemAllFields endpoint for files, I receive a response with a link for Role Assignments which subsequently also works and I get the
    info I need. So, is this a bug? Why does the link returned from Sharepoint work for files and not folders? So, google, google, google, and I discover that there is another possible way to get at the Role Assignments (and that the object does, indeed, belong
    to a list!).
    If I know the Title (or the guid) of the folder in question, I can use the following endpoint:
    /_api/Web/Lists/GetByTitle('Development')
    If I use that endpoint, I get the information I would have expected to get from following /ListItemAllFields and the subsequent Role Assignments links all work and I get what I need. If there's a bug and this is how I have to work around it, that's fine
    but I have yet to discover how to dynamically determine the Title of a given folder nor am I sure if all Titles are supposed to be unique within a given Sharepoint server. I'm assuming that the folder name as represented in the server relative URL and the
    Title may be different and this is where my newbishness may start to shine if I'm misunderstanding what a "List" is supposed to be in Sharepoint. Anyway, I did find that I could use the Properties endpoint to perhaps get the Title, for example:
    /_api/Web/GetFolderByServerRelativeUrl('/sites/cmisdev/Development')/Properties
    gives me:
    <d:vti_x005f_listtitle>Development</d:vti_x005f_listtitle>
    whose value I assume I could then supply to the /GetByTitle endpoint and be golden. However, "vti_x005f_listtitle" just sounds a little too deep to be something I should be relying on but maybe that's kosher. That's part of what I'm trying to
    find out. Also, if there is a way to use the Sharepoint REST API to discover the guid of a given object, then I could look it up in that way.
    So, in summary:
    1. Am I going about getting folder Role Assignment information in the wrong way? Based on the CSOM examples I've seen, I believe I'm doing it correctly and that the answer to #2 below is a resounding "Yes!" :)
    2. Is it a bug if I'm not able to use /ListItemAllFields on folders using the server relative url?
    3. If I'm supposed to use GetByTitle as a workaround, am I discovering that Title correctly through /Properties? Seems quite circuitous and awkward. Are Titles required to be unique throughout a given Sharepoint server?
    4. If I'm supposed to use the guid, how can I use the REST interface to discover an object's guid? Once we get down to the Role Assignments and other links, the guid appears in those links but I don't know how to discover it independently if that's the
    path I should use to get the data I described above.

    Upon further research, I'll answer my own question for the benefit of some other potential future newbie.  The answer to question number 1 above is "Not exactly.".  The server relative URLs I was using corresponded to lists (which are
    returned as a collection through /_api/web/lists).  I was treating them mentally like regular folders.  That, coupled with the fact that accessing their data as I showed above returns a ListItemAllFields link, made me think that was the way to get
    the Role Assignments just as I would for files and, as it turns out, "real" folders and sub-folders created under these lists.  That was the other problem with thinking of these lists as regular folders.  So, ListItemAllFields works on
    all files and folders in a list.  However, if you want Role Assignments for the lists themselves, you can keep track of the Titles and\or Guids from the /_api/web/lists that you're interested in (in my case, all non-hidden "document library"
    type lists) and then access those Role Assignments as I discussed in questions 3 and 4 above.  For example, from the /_api/web/lists collection from my test server, the "Development" document library Role Assignments are accessable via /_api/Web/Lists(guid'cd242eeb-aafa-4efa-aecc-9bbdf8e3d459')/RoleAssignments
    or /_api/Web/Lists/GetByTitle('Development')/RoleAssignments.

  • Creating the site content type failed when publish Infopath form to Sharepoint 2013

    I have an InfoPath 2013 form trying to publish it to SharePoint 2013.  When I click on publishing an error message appears stating "Creating the site content type failed".  I can't figure out why this
    is happening, any help on this one?
    Also it appears the form template is uploaded when I go to the library settings under advance.  When I see the .xsn file and click on it, it opens in InfoPath but not in sp.

    Rettajm, could you please find any errors in ULS?

  • Cannot add hub-managed content type with external list lookup columns to a list -- Error:Id field is not set on the external data field

    This is a variation on the issue mentioned in this
    post
    We are using SP 2010 Content Hub to manage our content types.  On the content hub we've created a couple of exteranl lists, and then created some site columns as lookups against these lists.  We then added the columns to one of our content types
    and set it to publish.
    After the publishing job executed, I tried adding the content type (which now appears on the subscriber sites) to one of the document libraries on one of the subscriber sites.  When I did that it threw the following error:
    Microsoft.SharePoint.WebControls.BusinessDataListConfigurationException: Id field is not set on the external data field    
    at Microsoft.SharePoint.SPBusinessDataField.CreateIdField(SPAddFieldOptions op)     
    at Microsoft.SharePoint.SPBusinessDataField.OnAdded(SPAddFieldOptions op)     
    at Microsoft.SharePoint.SPFieldCollection.AddFieldAsXmlInternal(String schemaXml, Boolean addToDefaultView, SPAddFieldOptions op, Boolean isMigration, Boolean fResetCTCol)     
    at Microsoft.SharePoint.SPContentType.ProvisionFieldOnList(SPField field, Boolean bRecurAllowed)     
    at Microsoft.SharePoint.SPContentType.ProvisionFieldsOnList()     
    at Microsoft.SharePoint.SPContentType.DeriveContentType(SPContentTypeCollection cts, SPContentType& ctNew)     
    at Microsoft.SharePoint.SPContentTypeCollection.AddContentTypeToList(SPContentType contentType)     
    at Microsoft.SharePoint.SPContentTypeCollection.AddContentType(SPContentType contentType, Boolean updateResourceFileProperty, Boolean checkName, Boolean setNextChildByte)     
    at Microsoft.SharePoint.SPContentTypeCollection.Add(SPContentType contentType)     
    at Microsoft.SharePoint.ApplicationPages.AddContentTypeToListPage.Update(Object o, EventArgs e)     
    at System.Web.UI.WebControls.Button.OnClick(EventArgs e)     
    at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)     
    at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)     
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)    b55297ed-717f-466d-8bdc-297b20344d3f
    I checked the external  content type configuration and it did specify an "id column".  Anyone know if what I am attempting to do is possible and if so, what special configurations are required?
    Thanks

    The issue is not External Content type or external list but the look up column.
    It's not possible to publish a look up column via the Content Type Hub.
    If you need to do this then an alternate way is to use a Managed Metadata column instead, otherwise you will have to implement this via a feature.
    Varun Malhotra
    =================
    If my post solves your problem could you mark the post as Answered or Vote As Helpful if my post has been helpful for you.

  • What are the drawbacks to adding a Site Content Type to the Document Site Column?

    I have a client who has enough SharePoint knowledge to be dangerous.
    They are requesting that a Column be added to all Document Libraries everywhere.  We built a solution that would require a bit of work when a Site Collection is created, and it would require that we run a script to identify if there are any Libraries
    that do not have this Column attached.
    This client wants to know why we didn't just add this Column to the default Document Site Content Type.  I don't know specifics as to why that's not a good idea, just that it's not a good idea.
    Can anyone point me to a resource that identifies the reasons why this is not recommended?
    Thank you

    I'd say there's a risk that patches or upgrades could be affected by this, or overwrite the change.
    In the past I've derived a Company specific Document Content Type from the Base Document CT, and added any new company wide columns to that new CT.
    w: http://www.the-north.com/sharepoint | t: @JMcAllisterCH | YouTube: http://www.youtube.com/user/JamieMcAllisterMVP

  • Site content types and site columns were absent

    hi,
    i have seved a  sub site as a template which includes 20+ doc libs with 20+ site content ctypes which includes  15+ site columns  and then i have used this savedsite template in one site collection and implemented my
    custom web parts and upload document fun. successfully.
    now i have created another new site collection and forgot to create site content types and site columns as  we have seen the  site columns in the saved site template already.
    now i realized that those  site content types and site columns were not there but the strange thing is that i am able to uplaod the documents  into those document libraries  which are not associated with site content types, without any error.
    Can I create  the same in my new site collection ? since i have already created  many many sub sites based on the  saved site templates tested the functionality ,i dont wanna delete the template recreate all the sites  again in order
    to save the time.
    Now pls advice:
    1) if site columns / site contents  were not existing at the site collection level, will this affect my func. in future?
    2)   is there any automated way fo creating site columns, site content types, associateing these site content types with doc libs programmatically like power shell/ sp object model API.
    3) would like to any programmatic way of creating hundreds of sub sites based on the saved site templates in myw eb application/ site collection.

    Hi,
    We can create site columns, site content types or sub-sites using SharePoint Server Object Model.
    The following articles for your reference:
    SharePoint 2010: Create Site Columns and Content Types using C#.Net
    http://social.technet.microsoft.com/wiki/contents/articles/20267.sharepoint-2010-create-site-columns-and-content-types-using-c-net.aspx
    How to: Add a Content Type to a SharePoint List
    http://msdn.microsoft.com/en-us/library/office/aa543576(v=office.14).aspx
    Create Sites Using Custom Site Templates in SharePoint 2010
    http://www.c-sharpcorner.com/UploadFile/63e78b/create-sites-using-custom-site-templates-in-sharepoint-2010/
    How to create sub site with custom site template through PowerShell
    http://fangdahai.blogspot.com/2012/08/how-to-create-sub-site-with-custom-site.html
    Best regards
    Dennis Guo
    TechNet Community Support

  • Create BCS External Content Type or a list based on a WCF Web Service using Visual Studio

    Hi ,
    How to create a BCS External Content Type or a list Based on a WCF Web Service using Visual Studio.
    The link provided here shows the requirement through Designer. http://msdn.microsoft.com/en-us/library/office/ee556431(v=office.14).aspx but I want this to be through VS code..
    Please help ..Appreciate your help..
    Thanks,
    Satheesh

    HI Sateeshlt,
    You can see the below link also;
    http://www.fabiangwilliams.com/2013/10/14/part-2-of-3-blog-update-on-sharepoint-bcs-with-full-crud/
    Best Regards,
    Brij K

  • Sharepoint 2013 and SSRS 2012 Integration - Report Server Content Types not displayed

    Hello, Everyone:
      I installed SSRS 2012 on our Sharepoint 2013 application server following the step-by-step instruction from the posting below:
      http://msdn.microsoft.com/en-us/library/jj219068.aspx
      Everything goes well after STEP 3 is completed.
      I did see the reporting services started and SSRS service application created.
      However, when I created a new site and tried to enable the predefined Reporting Services content types, I do not see the Shared data source (.rsds) files, report models (.smdl), and Report Builder report definition (.rdl) 3 types of files listed at
    all.
      Further more, when I go to the Provision Subscriptions and Alerts page, I keep getting a "SQL Server Agent state cannot be determined" error, even though the username and password provided is the admin user
    for the database.
      Any experience of what is wrong with the SSRS - Sharepoint integration? Please help!
    Tina

    Hello, Treavor:
      Now that the content types problem is resolved, I need to come back to the
    Provision Subscriptions and Alerts page.
      I guess I'm a little confused about what is being asked for the Provision Subscriptions and Alerts  page.
      The user I provided on the Provision Subscriptions and Alerts  page is my user-defined sysadmin role. And the page takes that.
      When I downloaded the SQL script, it was trying to give the automatically generated user "sa-SPDevContentAppPo" permission.
      Which user are we using to detect the SQL Server Agent?
      Thanks again!
    Tina

  • How to add [Thunderbird] Attachments content type action to list

    Thunderbird, Linux. Attachments. There is only one entry: Microsoft word documents. I want to add
    other attachment types, like .jpg (open with Gwenview) and so on, but I don't know how to add anything
    to the list.
    When I snapped on the "Post Question" box below this, it added a "troubleshooter" which was no help whatsoever.
    Please just tell me in English how to do this.
    Thanx.

    WPQ2FormCtx.ItemContentTypeId will give the content type ID of the item in each of the forms newform.aspx, ediform.aspx and displayform.aspx. You can also use WPQ2FormCtx.ItemContentTypeName, if you want to compare name instead of Id. Here is a JQuery
    code to hide fields in the forms:
    <script type="text/javascript">
    jQuery(document).ready(function($) {
        if(WPQ2FormCtx.ItemContentTypeId == '0x010400C36D463A4788AD4AAF5F85C02DA29F8E') {
        $("h3.ms-standardheader:contains('Body')").closest("tr").hide();
    </script>
    Note that this script assumes the JQuery is already referenced in the site. You can place above code in Script Editor web part in each of the forms. 
    Also, beware that this way you can hide the field from UI, but user can still open the page source and find the actual information in the hidden field. 
    If the requirement is to completely hide the field data then you will need to set the field properties like showInEditForm, showInDisplayForm and showInNewForm
    Nadeem Yousuf

  • Use SharePoint Rest Services in Apps Of Access (Content App)

    Hi,
    I want to get Office 365 SharePoint lists, Add new items into list, Update existing items etc by using app for access. When I am trying to send REST call to SharePoint online (Office 365) It given error:
    Fri Dec 05 2014 11:53:01 GMT+0530 (India Standard Time):RequestExecutor.OnMessage: Message.data={"command":"Query","postMessageId":"SP.RequestExecutor1","responseAvailable":false,"errorCode":-1005,"errorMessage":"There
    is no trusted URLs configured for the app deployment."}.
    Is there any way to achieve this. Is it actually possible to get or update SharePoint contents from an access app?
    Please help :(
    Thanks in Advance!
    Neetu Tanwar Software Developer

    Hi NeetuTanwar,
    Thanks for posting in MSDN forum.
    From the error message, it seem the issue is relative to SharePoint development.
    Here some links may be helpful:
    Solving cross-domain problems in apps for SharePoint
    Guidelines for registering apps for SharePoint 2013
    Can you reproduce the issue in a common web applicaiton? If yes, I also suggset that you reopen a new thread in
    SharePoint 2013 - Development and Programming forum to get more effective response.
    Regards & Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Can I View site content page in a list, rather than blocks?

    the viewlsts.aspx page in sp2013 shows each object in a block - is there a way to display it in the old, sp2010 style that shows # of items, last modified, etc in a table instead of the grid layout? it is much easier to look at as a list.

    No way out of the box. You could create a search driven web part, a custom App or a custom web part do display the list of the lists/libraries. But, this would not give you the full functionality of the current viewlsts.aspx page.
    The following is a "hack" is not supported by Microsoft (or anyone else!), and in general a bad idea. But if it is only for your personal use as an administrator and only as a way to browse the lists of lists, then go for it! (at your own risk
    of course)
    If you are on premises, not Office 365, and you are a server administrator, you could copy and rename the viewlsts.aspx from the 14\Templates\Layouts directory and put it in the 15\Templates\Layouts directory as ViewLstsOld.aspx. You can then access it as
    http://yourServer/sites/yourSite/_layouts/ViewLstsOld.aspx. This page will not display "Apps" nor let you add new "Apps". The Create link will take you to the old 2010 create page.
    Mike Smith TechTrainingNotes.blogspot.com
    Books:
    SharePoint 2007 2010 Customization for the Site Owner,
    SharePoint 2010 Security for the Site Owner

  • Powershell to add/delete content type to particular library alone in a site collection

    Hi,
    I am trying to add and delete content type from a particular picture library (site collection) using powershell.
    I have tried the below, but it is not working.
    Below scenarios are not working:
    1) If the content type to be added is there in library, then the loop is still moving to "No content type exists".
    2) Content type is not getting deleted from library
    3) Set the newly added content type as default content type.
    Below is the powershell, which I am trying:
    function ChangeContentType($url)
    $site = Get-SPSite($url);
    $web =$site.RootWeb
    $lookForList = "PicLibrary"
    $lookForCT = "Img1ContentType"
    $lookForRemoveCT = "Image2CT"
    write-host "Checking site:"$web.Title
    #Make sure content types are allowed on the list specified
    $docLibrary = $web.Lists[$lookForList]
    if ($docLibrary -ne $null)
    $docLibrary.ContentTypesEnabled = $true
    $docLibrary.Update()
    if (($web.ContentTypes | where { $web.Name -eq $lookForCT }) -eq $null)
    write-host "No content type exists with the name" $lookForCT "on list" $docLibrary.Title
    #Add site content types to the list
    write-host "Adding content type " $lookForCT "on list" $docLibrary.Title
    $ctToAdd = $web.ContentTypes[$lookForCT]
    $ct = $docLibrary.ContentTypes.Add($ctToAdd)
    write-host "Content type" $ct.Name "added to list" $docLibrary.Title
    $docLibrary.Update();
    else
    write-host "content type exists with the name" $lookForCT "on list" $docLibrary.Title
    #Remove Content type
    if (($web.ContentTypes | where { $web.Name -eq $lookForRemoveCT }) -eq $null)
    write-host "No content type exists with the name" $lookForRemoveCT "on list" $docLibrary.Title
    else
    $ctToRemove = $web.ContentTypes[$lookForRemoveCT]
    write-host "Removing content type" $ctToRemove.Name "from list" $docLibrary.Title
    $docLibrary.ContentTypes.Delete($ctToRemove.Id)
    $docLibrary.Update()
    else
    write-host "The list" $lookForList "does not exist in site" $web.Title
    #Dispose object
    $site.Dispose()
    $web.Dispose()
    How to fix this?
    Thanks

    Hi,
    Thanks for the reply.
    I checked it. If the script is run multiple times, the add and delete content type will throw error.
    How to delete content type? I have tried the below:
    $docLibrary = $web.Lists[$lookForList]
    if ($docLibrary -ne $null)
    $docLibrary.ContentTypesEnabled = $true
    $docLibrary.Update()
    #get the content Type
    Write-host "Getting content type $lookForCT in site $web"
    #Confirm that the content type exists.
    $contentType = $web.ContentTypes | where {$web.ContentTypes.Name -eq $lookForCT}
    ##Abort if not found.
    if ($contentType -eq $null)
    Write-host "$lookForCT not found in site collection."
    else
    if ($web.ContentTypes.Name -eq $lookForCT)
    Write-host $docLibrary.ContentTypes.Name
    if($docLibrary.ContentTypes.Name -eq $lookForCT)
    write-host "Content type $lookForCT is already added to list" $docLibrary.Title
    else
    write-host "No content type exists with the name" $lookForCT "on list" $docLibrary.Title
    write-host "Adding Content Type"
    $ctToAdd = $web.ContentTypes[$lookForCT]
    $ct = $docLibrary.ContentTypes.Add($ctToAdd)
    $docLibrary.Update()
    write-host "Content type" $ct.Name "added to list" $docLibrary.Title
    #get the content Type
    Write-host "Getting content type $lookForRemoveCT in site $web"
    #Confirm that the content type exists.
    $contentType = $web.ContentTypes | where {$web.ContentTypes.Name -eq $lookForRemoveCT}
    ##Abort if not found.
    if ($contentType -eq $null)
    Write-host "$lookForRemoveCT not found in site collection."
    else
    if ($web.ContentTypes.Name -eq $lookForRemoveCT)
    Write-host $docLibrary.ContentTypes.Name
    if($docLibrary.ContentTypes.Name -eq $lookForRemoveCT)
    write-host "Content type $lookForRemoveCT is added to list" $docLibrary.Title.
    write-host "Removing Content type $lookForRemoveCT"
    $ctToRemove = $web.ContentTypes[$lookForRemoveCT]
    $docLibrary.ContentTypes.Delete($ctToRemove.Id)
    $docLibrary.Update()
    else
    write-host "No content type exists with the name" $lookForRemoveCT "on list" $docLibrary.Title
    I am getting error in delete now. Error is "Exception calling "Delete" with "1" argument(s): "Specified argument was out of the range of valid values.
    Parameter name: id"
    Thanks

  • Scrip to update Sharepoint Online content type

    I have a content type "TestContentType" with three columns:
    Document Type
    Category
    Sub-category
    This content type is used on 18 document libraries, in 3 site collections.
    The Category column needs to have a "description" added which currently has no description. Is there a way to achieve this via a script so I don't have to make change manually via the UI.
    So far I have come up with the following script, but this so far only lists all list and document libraries. What I actually need is to be able to get the content type in this case "TestContentType" and then update the "Category" column
    to include a description:
    $loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
    $loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
    $webUrl = Read-Host -Prompt "HTTPS URL for the SP Online 2013 site"
    $username = Read-Host -Prompt "Email address login"
    $password = Read-Host -Prompt "Password for $username" -AsSecureString
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
    $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
    $web = $ctx.Web
    $lists = $web.Lists
    $ctx.Load($lists)
    $ctx.ExecuteQuery()
    $lists| select -Property Title
    Any suggestions would be appreciated.

    This isn't the best way to do it, which would be manipulating SharePoint through the CSOM, however you can automate IE so that it runs through a series of actions.
    The nice way would be to use something like the client-side code here:
    https://sharepointpowershell.codeplex.com/
     I don't have the time to dig into it at the moment but i'd try to merge that CSOM approach with something like this script:
    http://get-spscripts.com/2010/11/add-and-remove-site-content-types-from.html which uses the on-prem version.

  • Using SPmanagementshell to create library ,version enable & Add content type

    Hi Folks,
     How to create library document,enable version, add content type in every site using SPmanagementshell.
    Now i am doing user interface,it is  taking more time to do this task.
    Please give solution using SPmanagementshell to do this task.
    I would be great if someone help.

    Hi,
    Please try code given below:
    $spWeb = Get-SPWeb -Identity http://SPServer
    $listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
    $spWeb.Lists.Add("My Documents","My Doc Library",$listTemplate)
    $spDocumentLibrary = $spWeb.GetList("My Documents")
    $spDocumentLibrary.EnableVersioning = $true
    $spDocumentLibrary.ContentTypesEnabled = $true
    $spDocumentLibrary.Update()
    #Add site content types to the list
    $ctToAdd = $site.RootWeb.ContentTypes["<NAME OF ContentType>"]
    $ct = $spDocumentLibrary.ContentTypes.Add($ctToAdd)
    $spDocumentLibrary.Update()
    Hope it helps!
    Thanks,
    Avni Bhatt
    If this helped you resolve your issue, please mark it Answered

Maybe you are looking for