本文整理汇总了C#中umbraco.cms.businesslogic.web.Document.CreateContent方法的典型用法代码示例。如果您正苦于以下问题:C# Document.CreateContent方法的具体用法?C# Document.CreateContent怎么用?C# Document.CreateContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类umbraco.cms.businesslogic.web.Document
的用法示例。
在下文中一共展示了Document.CreateContent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeNew
/// <summary>
/// Creates a new document
/// </summary>
/// <param name="Name">The name (.Text property) of the document</param>
/// <param name="dct">The documenttype</param>
/// <param name="u">The usercontext under which the action are performed</param>
/// <param name="ParentId">The id of the parent to the document</param>
/// <returns>The newly created document</returns>
public static Document MakeNew(string Name, DocumentType dct, User u, int ParentId)
{
//allows you to cancel a document before anything goes to the DB
var newingArgs = new DocumentNewingEventArgs()
{
Text = Name,
DocumentType = dct,
User = u,
ParentId = ParentId
};
Document.OnNewing(newingArgs);
if (newingArgs.Cancel)
{
return null;
}
Guid newId = Guid.NewGuid();
// Updated to match level from base node
CMSNode n = new CMSNode(ParentId);
int newLevel = n.Level;
newLevel++;
//create the cms node first
CMSNode newNode = MakeNew(ParentId, _objectType, u.Id, newLevel, Name, newId);
//we need to create an empty document and set the underlying text property
Document tmp = new Document(newId, true);
tmp.SetText(Name);
//create the content data for the new document
tmp.CreateContent(dct);
//now create the document data
SqlHelper.ExecuteNonQuery("insert into cmsDocument (newest, nodeId, published, documentUser, versionId, Text) values (1, " +
tmp.Id + ", 0, " +
u.Id + ", @versionId, @text)",
SqlHelper.CreateParameter("@versionId", tmp.Version),
SqlHelper.CreateParameter("@text", tmp.Text));
// Update the sortOrder if the parent was the root!
if (ParentId == -1)
{
newNode.sortOrder = CountLeafNodes(-1, Document._objectType) + 1;
}
//read the whole object from the db
Document d = new Document(newId);
//event
NewEventArgs e = new NewEventArgs();
d.OnNew(e);
// Log
Log.Add(LogTypes.New, u, d.Id, "");
// Run Handler
umbraco.BusinessLogic.Actions.Action.RunActionHandlers(d, ActionNew.Instance);
// Save doc
d.Save();
return d;
}