惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 【当耐特】
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Y
Y Combinator Blog
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
I
InfoQ
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
J
Java Code Geeks
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
C
Cybersecurity and Infrastructure Security Agency CISA
Know Your Adversary
Know Your Adversary
MongoDB | Blog
MongoDB | Blog
T
Tor Project blog
The Register - Security
The Register - Security
H
Help Net Security
Cisco Talos Blog
Cisco Talos Blog
P
Privacy & Cybersecurity Law Blog
NISL@THU
NISL@THU
P
Palo Alto Networks Blog
B
Blog RSS Feed
Latest news
Latest news
T
Threat Research - Cisco Blogs
The Hacker News
The Hacker News
C
Cisco Blogs
P
Privacy International News Feed
T
The Exploit Database - CXSecurity.com
V
Vulnerabilities – Threatpost
S
Schneier on Security
P
Proofpoint News Feed
Schneier on Security
Schneier on Security
www.infosecurity-magazine.com
www.infosecurity-magazine.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
AI
AI
Google Online Security Blog
Google Online Security Blog
H
Hacker News: Front Page
N
News and Events Feed by Topic
W
WeLiveSecurity

博客园 - 名可真难起

SharePoint还原大体积内容数据库报空间错误的解决办法 SharePoint 2013: Knockout JS + Rest Service展示List数据 SharePoint 2013—创建Master Page 通过SPWeb.EnsureUser将SPUser添加到网站 如何在页面中使用sharepoint中的富文本编辑器控件 通过编程的方式给列表项添加附件 SharePoint 2010 Visual Web Part发布后找不到文件的错误 SharePoint 2010通过Web Service读取和修改Excel文件 SharePoint 2010中Metadata Service 解决SharePoint2010中Excel刷新出错的问题 SharePoint 2007搜索网站开启匿名访问 SharePoint 2010: 取得浏览最多的网站 在Windows 7中如何用另一个用户运行程序 不仅仅是土豆 SharePoint 2010运行环境 最近比较懒 如何在ActionResult中返回XML类型 - 名可真难起 - 博客园 SharePoint 2010 Development Stack SharePoint 2010 Visual Web Part Demo--展示网站中的List.
CSOM创建Content Type并指定GUID
名可真难起 · 2014-07-02 · via 博客园 - 名可真难起

SharePoint 2013 Client Object Mode在创建Content Type时有一个限制,不能给Content Type指定一个GUID,只能由系统随机生成。而在用farm solution部署时,则可以在xml中指定好Content Type的GUID,或者用服务器端对象模型来指定GUID。

SharePoint 2013 SP1发布之后,这个问题就迎刃而解了。在新的CSOM对象模型中,可以在创建Content Type时指定GUID。在o365上申请一个免费的开发网站,然后编写APP就可以进行测试了。

SP2013 SP1 CSOM SDK的下载地址:

http://www.microsoft.com/en-us/download/details.aspx?id=35585

当SP的版本升级到SP1之后,或者在o365网站上,我们就可以为Content Type指定唯一的GUID了。代码如下:

private string CreateContentType(ClientContext clientContext, Web web)

        {

string ContentTypeID = "0x010048017A06020440BE8498BB193B944C84";            ContentTypeCollection contentTypeColl = clientContext.Web.ContentTypes;

            ContentTypeCreationInformation contentTypeCreation = new ContentTypeCreationInformation();

            contentTypeCreation.Name = "ContentType Name";

            contentTypeCreation.Description = "Custom Content Type created by CSOM.";

            contentTypeCreation.Group = "Custom";

            contentTypeCreation.Id = ContentTypeID;

            //Add the new content type to the collection

            ContentType ct = contentTypeColl.Add(contentTypeCreation);

            clientContext.Load(ct);

            clientContext.ExecuteQuery();

            return ContentTypeID;

        }

注意:在创建Content Type时,不能在代码中指定它的父Content Type类型。例如下面的代码是不能正常执行的。

contentTypeCreation. ParentContentType =contentTypes.GetById(“0x0100”);

正确的做法是在指定的GUID中直接包含其父类型的ID,如下面所示:

string ContentTypeID = "0x010048017A06020440BE8498BB193B944C84";    

致力于SharePoint开发. QQ:28748451.