Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

ContentTypes.GetById returns null when passing in Custom Content Type Id

$
0
0

I have done quite a bit of reading since originally posting this thread and the code I am now working with is more complete, but I am still unable to create a new Document Set based upon a custom Document Set Content type. I am posting the new code below as well a listing of Content Types and their associated Ids. 

Questions:

1. Shouldn't the contentType.Id.TypeId be unique to the ContentType?

2. What should the last Parameter of the DocumentSet.Create be?

3. Why do you think I am getting different hex Id (it has many more digits) from the code then from the SharePoint Designer or URL?

value from code: 0x0120D52000DB0A4FB1FCB5A944B61FC213050776C200F9571BAD051E174691C54DA59C3278E6

value from SharePoint designer and URL: 0x0120D52000DB0A4FB1FCB5A944B61FC213050776C2

System default Document Set value: 0x0120D520

Thank you,

Ralph

This is the pertinent section of my code:

using System;
using System.IO;
using System.Linq;
using System.Security;
using System.Text;
using System.Web;
using Microsoft.SharePoint.Client;

                                    

            using (var context = new ClientContext(webUrl))
            {
                context.Credentials = new SharePointOnlineCredentials(userName, password);
                context.Load(context.Web, w => w.Title);
                context.ExecuteQuery();
                Console.WriteLine("Your site title is: " + context.Web.Title);

                List spoDocumentLibrary = context.Web.Lists.GetByTitle("Properties Documents");
                context.Load(spoDocumentLibrary, dl => dl.ContentTypes);
                context.ExecuteQuery();

                ContentTypeCollection ctcMyContentTypes = spoDocumentLibrary.ContentTypes;
                Stream fsOutput = System.IO.File.Create("c:\\hold\\AvailableContentTypes.txt");
                string strOutput = "";

                foreach (ContentType ct in ctcMyContentTypes)
                {

                    Console.WriteLine("ContentTypeName: " + ct.Name + ", Content.Id: " + ct.Id + " ContentId.TypeId: " + ct.Id.TypeId + System.Environment.NewLine);

                    strOutput = ("ContentType.Name: " + ct.Name + ", ContentType.Id: " + ct.Id + ", ContentType.Id.TypeId: " + ct.Id.TypeId + System.Environment.NewLine);
                    byte[] outputData = new UTF8Encoding(true).GetBytes(strOutput);
                    fsOutput.Write(outputData, 0, outputData.Length);
                }
                fsOutput.Close();
                fsOutput.Dispose();

                //  *****  The following code is failing 
ContentType spoDocSetContentType = context.Web.ContentTypes.GetById("0x0120D52000DB0A4FB1FCB5A944B61FC213050776C200F9571BAD051E174691C54DA59C3278E6");
                context.Load(spoDocSetContentType, dsct => dsct.Id);
                context.ExecuteQuery();

                Microsoft.SharePoint.Client.DocumentSet.DocumentSet.Create(context, context.Web.RootFolder, "test DocSet from C#", spoDocSetContentType.Id);
                context.ExecuteQuery();

            }

Here is the output:

ContentTypeName: Tax Document - Property Set, Content.Id: 0x010100009DBADFDFC60A4389A19AF9ABBFB496005A6D226B17787943927A02CAE8D77708, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}
ContentTypeName: Accounting Document - Portfolio, Content.Id: 0x0101003CB9DF7C67A0104093375493084C35BF000ED0B9E8DC9A7D4F83B50B6447DA87CB, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}
ContentTypeName: Acquisition Document - Portfolio, Content.Id: 0x010100BBA4DFE3B730EA4A98658EC426EAAD9D007DF438423292CD4BBF85C320CCCB2EB6, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}
ContentTypeName: Disposition Document - Portfolio, Content.Id: 0x0101008E2FE15F00FEA9448531A26E0D8C2EAA00A799F35CE5364046BA12A1FB377533C5, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}
ContentTypeName: Entity Document - Portfolio, Content.Id: 0x0101004B8D605277B5944DB4A37069C526A36900AE1282281762824DB9C9386E171CB20F, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}
ContentTypeName: Financing Document - Portfolio, Content.Id: 0x010100F35A9D83EF03044FA1A671D940DA2EA4008EFE4D7E348559498E1CD111F5C89321, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}
ContentTypeName: Property Document - Portfolio, Content.Id: 0x010100D2106C57A6B6304A8F0B5A584364D4E900561EAE36B24A914BBF4246C9E2AD6804, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}
ContentTypeName: Tax Document - Portfolio, Content.Id: 0x010100443210C76BD90D40B0EC64AA84A9ACFF000D6844D9A75EC84F9EE1297C30BEC72B, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}
ContentTypeName: Document, Content.Id: 0x01010043A5502E274C434D9C2DB01FF8FD049D, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}
ContentTypeName: Acquisition - Property Set, Content.Id: 0x010100A9A98C359AAD104FA38FD8C5D169106B00DC17FA3615D87D46A499FC1E94E21CB1, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}
ContentTypeName: Folder, Content.Id: 0x012000E5CC86F711A017428ECD8516788407E8, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}
ContentTypeName: Portfolio Document Set, Content.Id: 0x0120D520002A5181429FE22747BC49F30DCA9091B1006F17AEA2A984374088EFD2A960A50B1D, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}
ContentTypeName: Portfolio Folder, Content.Id: 0x012000999213D17E061A46A0B3D8266B232F6400D1896424781BE64F88F2FCBF23E44D2C, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}
ContentTypeName: Property Document Set, Content.Id: 0x0120D52000DB0A4FB1FCB5A944B61FC213050776C200F9571BAD051E174691C54DA59C3278E6, ContentId.TypeId: {da0f1e90-296f-480e-bc27-cefe51eff241}



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>