如何从code添加属性到文档类型一把umbraco? [英] How to add a property to a document type in Umbraco from code?

查看:138
本文介绍了如何从code添加属性到文档类型一把umbraco?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能给我如何编程的属性添加到一把umbraco CMS现有的文档类型的例子吗?这是我尝试过:

Could anyone give me an example of how to programatically add a property to an existing document type in Umbraco CMS? This is what I tried:

var dt = DocumentType.GetByAlias("TestDocType");
dt.AddPropertyType(new DataTypeDefinition(-49),"testprop", "test prop");

但是,它抛出一个异常:

But it throws an exception:

Method not found: 'Void umbraco.cms.businesslogic.ContentType.AddPropertyType(umbraco.cms.businesslogic.datatype.DataTypeDefinition, System.String, System.String)'.

任何想法?

推荐答案

我设法解决它。该网站最近升级的一把umbraco 4.5到一把umbraco 4.7.1,这样的有DLL替换为更近的。在一把umbraco旧版本的方法的返回类型为公共无效AddPropertyType ,而新的公共属性类型AddPropertyType 。显然,在升级新cms.dll没有复制,所以我从一个干净的一把umbraco 4.7.1解决方案复制它,改变了code接收返回类型,并且它帮助。

I managed to fix it. The website was recently upgraded from Umbraco 4.5 to Umbraco 4.7.1, so the dll's had to be replaced with the more recent ones. In the older version of Umbraco the method's return type was public void AddPropertyType whereas the new one public PropertyType AddPropertyType. Apparently during the upgrade the new cms.dll wasn't copied over, so I copied it from a clean Umbraco 4.7.1 solution, changed the code to receive the return type and it helped.

必需的命名空间:

using umbraco.cms.businesslogic.datatype;
using umbraco.cms.businesslogic.web;

所以最后code(假设正确的组件引用):

So the final code(assuming correct assemblies are referenced):

var dt = DocumentType.GetByAlias("TestDocType");
var pType = dt.AddPropertyType(new DataTypeDefinition(-49),"testprop", "test prop");

这篇关于如何从code添加属性到文档类型一把umbraco?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆