English 中文(简体)
如何从代码中将属性添加到 Umbraco 的文档类型?
原标题:How to add a property to a document type in Umbraco from code?

有人能给我举一个例子吗? 如何用程序将一个财产添加到 Umbraco CMS 的现有文件类型中? 这就是我尝试过的:

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

但它是一个例外:

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,因此必须用较新的版本替换模版。在旧版的Umbraco中,方法的返回类型是 公共无效的Add PropertyType ,而新的版本是 公共产权Type Add PropertyType 。在升级期间,显然没有复制新的cmms.dll,所以我从干净的Umbraco 4.7.1解决方案中复制了它,改变了代码以接收返回类型,它也有所帮助。

所需命名空间 :

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

所以最终代码(假设正确组装被引用):

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

这守则看起来不错,我应该能行的

确保您的第一行实际上是返回一个文档类型, 不是空的 。

还有,你是否有合适的用途 需要至少一些这些吗?

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




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签