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
Similar Messages
-
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 -
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 -
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 youI'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 -
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?
-
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?
ThanksThe 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. -
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 -
Migrating existing site content to UCM
We looking for any tools, APIs that help in migrating the existing content of web sites to UCM. The site content is structured and needs to mapped to WCM content in UCM. The site has static as well as dynamic content.
For dynamic content we are assuming a DB is used. But not sure if the entire functional information shown for a page is coming from the DB. Want to understand if any tools are available to make migration of content from a DB to UCM.
For static pages we have to extract the content and move it to UCM. Here also it is not clear as to how many static pages are there. Our concern is that if too many static pages (having a similar template) are there then manual migration may not work out. We may have to parse the html content and create structured WCM content out of them. Our doubt is do we have any API to create WCM content programatically?
Regards,
PratapHi Pratap,
we here at Fishbowl have developed just such a site migrator. It takes existing sites and will import and build them into a new WCM (10gR4) site.
Our site migrator focuses on the body content of the sites (i.e. what end users will be editing in context). You still need to build out your navigation structure etc. However, we do parse the contents of your existing sites into specific region definitions of the new WCM.
contact [email protected] for more info.
Warmly,
Billy Cripe
Fishbowl Solutions -
Unable to add sitecolumn to content type.
I have added a sitecolumn to content type through visual studio and deployed it and it got added.When i try to add one more column to content type and deploy it its not getting added..Please can i know if there is any solution for upgrading this content
type without using feature activation code.try these links:
http://sharepoint.stackexchange.com/questions/11114/how-to-delete-a-content-type-part-of-an-application-feature
http://stackoverflow.com/questions/6427315/unable-to-delete-sharepoint-2010-contenttype-contenty-type-in-use
https://social.technet.microsoft.com/forums/sharepoint/en-US/b859be4f-afb1-46b2-b5da-bb88cff9a1d1/unable-to-delete-the-content-type
https://msdn.microsoft.com/en-us/library/office/ms453791%28v=office.14%29.aspx
http://stackoverflow.com/questions/4963309/content-type-cant-be-deletedtry deleting content type and recreating it again.
Please mark it as answer if you find it useful happy sharepointing -
Special stock indicator O to add existing custom movement types
Hi Gurus,
Business having the two custom movement types for which they want to add special stock indicator O.
please let me know is it possible to add special stock indicator O to existing movement types.
or
Is it possible to achieve this with creation of new movement types along with current special stock indicators.
Thanks in advance.have you ever created a new movement type?
try it.
it can only be done by copy of a SAP given movement type, hence it has basically the same functionality as the original movement.
the main purpose for new movement types are to post to other accounts and to segregate authorization.
In other words you cannot add O to an existing movement, you need to create a new movement by copy from a movement that allows this O -
How add existing ipod content to newly installed notebook?
Hi,
I bought my ipod video 30 Gb last week, and I am very happy with it.
I installed all content I wanted onto my ipod, but I was forced to reinstall my notebook, due to a virus.
All the content on my ipod is good, and I would like to restore this content into the local library of (my newly installed) iTunes.
How should I do this?
It seems that on intial connection, I only have the option to change the ipod content to what my (newly installed iTunes, thus empty) library contains.
Please help!I have a similar but more embarrassing problem. I "moved to trash" yes I said moved to trash, my entire MUSIC folder from finder. While CAREFULLY opening Trash, somehow empty trash was selected and I've spent the last 6 hours trying to figure out how to get my "ipod selection", which amounts to approx. 70% of the lost itunes library, back into that library.
PLEASE HELP ME! Thank you.
Hi,
I bought my ipod video 30 Gb last week, and I am very
happy with it.
I installed all content I wanted onto my ipod, but I
was forced to reinstall my notebook, due to a virus.
All the content on my ipod is good, and I would like
to restore this content into the local library of (my
newly installed) iTunes.
How should I do this?
It seems that on intial connection, I only have the
option to change the ipod content to what my (newly
installed iTunes, thus empty) library contains.
Please help! -
Hi Experts,
I am a novice in Powershell and trying to learn PowerShell.
Currently, i need to reboot some 50-60 desktops remotely.
i am using the below powershell command
gc c:\Temp\machineList.txt |%{Restart-computer -computername $_ -force}
It is working perfect for me but what i want is before machine gets rebooted User should get a prompt like "Your machine will be rebooted in 60 seconds, Please save your work".
How i can achieve this in a powershell script.
Thanks in advance.
Dayaan other option is to start taskmanager on Domain Controller
go to users right click user Object send message
regards Thomas Paetzold visit my blog on: http://sus42.wordpress.com
"taskmanager"?
That only works for users logged into the dc. Users should not be allowed to log into the DC directly.
I suspect you mean to use the MSG facility if it is not disabled. MSG /?. This can send messages to uses on various systems.
¯\_(ツ)_/¯ -
Hi,
I am trying to create "View" in a Document Library and need to enable following:
1. Mark as default View
2. Folders -> Show this view : in Folders of Content Type : {Custom Content Type name}
I am using following code which sets "in Folders of Content Type : " to "Folder" rather than selecting custom content type despite passing Content Type ID of custom content type.
code:
var itemContentTypes = clientContext.LoadQuery(web.AvailableContentTypes.Where(ct => ct.Name == viewContentType));
clientContext.ExecuteQuery();
var itemContentType = itemContentTypes.FirstOrDefault();
view.ContentTypeId = itemContentType.Id;
view.DefaultViewForContentType = true;
view.Update();
clientContext.ExecuteQuery();
Please highlight what seems to be missing?
Thanks
SonalHi,
Before you set the content type ID for the view, you need to add the custom content type to the library firstly.
You can add the content type to library using OOTB feature “Add from existing site content types” in library settings or using Client Object Model.
Here is a code snippet for your reference:
var list = context.Web.Lists.GetByTitle(listTitle);
list.ContentTypesEnabled = true;
var contentType = context.Site.RootWeb.ContentTypes.GetById("0x0120");
list.ContentTypes.AddExistingContentType(contentType);
context.ExecuteQuery();
More information about add exist content type using Client Object Model:<o:p></o:p>
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.contenttypecollection.addexistingcontenttype%28v=office.15%29.aspx
Best regards,
ZhengyuGuo
Zhengyu Guo
TechNet Community Support -
Choose which content type to use in sharepoint 2013 list using InfoPath 2013
So, in my head it seems pretty simple and a feature that might be standard to InfoPath so much in fact I can't find anything on it... My goal is to a have one list where you can do a drop down or buttons to choose which content type to use.
I will be royally disappointed if this is not possible. =(
So, c'mon you giants of MS Support. Give me a happy answer.Hi Lincoln,
According to your description, my understanding is that you want to use multiple content types in a list.
For achieving it, you can do as the followings:
Open the list.
Go to List Settings->Advanced Settings.
Under ‘Allow management of content type’, select ‘Yes’, click OK.
In the Content Types section, click ‘Add from existing site content types’
Then add the content types that you want to add, click OK
Go back to the list, click ITEMS->New Item, then all content types are displayed in the drop-down list
When you click an item, you can select the new item is created based on one of these content types
I hope this helps.
Thanks,
Wendy
Wendy Li
TechNet Community Support -
Manually Running Timer Job "Content Type Subscriber" on SP Online
I need to run the "Content Type Subscriber" timer job on my SP Online instance because the default setting is hourly. This makes it difficult to build out and deploy content types quickly because depending on when you make the content type
change you have to wait upwards of an hour to see it published.
When will we be able to run timer jobs using the PowerShell cmdlets or some other way? Is there a recommended approach by MS to handle this scenario?What you describe is by design, I don't have to use a content type hub to reproduce. Only add a site content type into a list can show this.
According to
http://msdn.microsoft.com/en-us/library/ms463016.aspx
When you add a site content type to a list or library, SharePoint Foundation makes local copies of any columns that are referenced by the content type and adds them to the
list's fields. For more information, see Fields and Field References.
In addition, SharePoint Foundation makes a local copy of the site content type and adds the copy to the content type collection on the list.
The new list content type is a child of the site content type. The value of the
Id property for
the list content type is different from the value of the Id property for its parent site content type, but otherwise the two content types are initially the same.
Maybe you are looking for
-
New HDD not working. Please advise.
Hello. Today i purchased a new internal hdd for my 5.53 ghz macbook pro. I purchased the seagate momentus 500 gb 7200 rpm drive as suggested by users. The installation was fine, however i am having several issues with the drive. I boot into the 10.6
-
Trying to Install Windows 7 Recovery Cds on a new HD
HP Pavilion dv4-2165dx "No bootable device found -- insert cd and press any key" So my hard drive crashed on me, and I bought a new one from a 3rd party vender online and ordered recovery CDs for Windows 7 from HP. I got three CDs total; 2 Windows 7
-
WDA: Hide filter - function on ALV
Hi @ all, does anybody know how to hide filter in ALV - Grid in WebDynpro for Abap? The Class where you can set alv-settings doesn`t have Method to hide filter on ALV. Have anybody an idea? [ Class: IF_SALV_WD_TABLE_SETTINGS ] Best regards, Dennis
-
Sh ip cache flow command in Nexus
is there a similar command to the sh ip cache flow in Nexus? Thanks.. _Greg...
-
Hi, how to use formula colum tool.i have placed a formula column with my quey colums.and written plsql codefor it.in layout editor i placed field and source colum property to the formula colmn name.but when i run report it is not showing any value. P