Sorry for the possibly confusing subject name. Basically the problem is i want to create a child node to have the same name as the parent however i havent any idea how to do this as i have exhausted what little knowledge i already have.
my code is as follows:
DocumentType dt = DocumentType.GetByAlias("Gallery"); User author = User.GetUser(0); int id = sender.Id; string name = sender.getProperty("nodename").Value;
//create a document with a name, a type, an umbraco user, and the ID of the document's parent page. To create a document at the root of umbraco, use the id -1 Document doc = Document.MakeNew(name, dt, author, id);
//after creating the document, prepare it for publishing doc.Publish(author);
//Tell umbraco to publish the document umbraco.library.PublishSingleNode(doc.Id);
Im struggling to pull out the parents name, its throwing a wild error now so my last effort wasnt particularly any good. However thanks for the method, It looks to be doing the job.
Alec
p.s On the side note, another Plymouth member? must say I'm rather shocked!
//Create a variable Document currentPage = new Document(sender.Id);
//Check if the contenttype is not taxonomy otherwise an endless loop will occur if (sender.ContentType.Alias == "Taxonomy") { if (sender.HasChildren == false) {
//Get the document type you would like to use by its alias and the user who should be the creator of the document DocumentType dt = DocumentType.GetByAlias("Gallery"); User author = User.GetUser(0); int id = sender.Id; string nodename = currentPage.Text;
//create a document with a name, a type, an umbraco user, and the ID of the document's parent page. Document doc = Document.MakeNew(nodename + " Gallery", dt, author, id);
doc.Text = nodename;
//after creating the document, prepare it for publishing doc.Publish(author);
//Tell umbraco to publish the document umbraco.library.UpdateDocumentCache(doc.Id); } } }
The problem I had was pulling through the parents name. Turns out I hadnt included the .Alias. Hope it helps!
Changing a newly created Pages name.
Hi,
Sorry for the possibly confusing subject name. Basically the problem is i want to create a child node to have the same name as the parent however i havent any idea how to do this as i have exhausted what little knowledge i already have.
my code is as follows:
DocumentType dt = DocumentType.GetByAlias("Gallery");
User author = User.GetUser(0);
int id = sender.Id;
string name = sender.getProperty("nodename").Value;
//create a document with a name, a type, an umbraco user, and the ID of the document's parent page. To create a document at the root of umbraco, use the id -1
Document doc = Document.MakeNew(name, dt, author, id);
//after creating the document, prepare it for publishing
doc.Publish(author);
//Tell umbraco to publish the document
umbraco.library.PublishSingleNode(doc.Id);
Cheers,
Alec
The property you need to set is doc.Text to set the name I believe.
Im struggling to pull out the parents name, its throwing a wild error now so my last effort wasnt particularly any good. However thanks for the method, It looks to be doing the job.
Alec
p.s On the side note, another Plymouth member? must say I'm rather shocked!
Its solved.
I took what was given and stored it in a variable (after fetching the correct parent node).
Thanks for the help it was bugging me for ages!
Alec
Glad you sorted it, perhaps post up your solution in case it helps ayone else out.
I didn't know of any other local members either until the launch of this site and the new member locator, handy to know for future.
For future reference my code that cracked the problem is
void Document_AfterSave(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
{
//Create a variable
Document currentPage = new Document(sender.Id);
//Check if the contenttype is not taxonomy otherwise an endless loop will occur
if (sender.ContentType.Alias == "Taxonomy")
{
if (sender.HasChildren == false)
{
//Get the document type you would like to use by its alias and the user who should be the creator of the document
DocumentType dt = DocumentType.GetByAlias("Gallery");
User author = User.GetUser(0);
int id = sender.Id;
string nodename = currentPage.Text;
//create a document with a name, a type, an umbraco user, and the ID of the document's parent page.
Document doc = Document.MakeNew(nodename + " Gallery", dt, author, id);
doc.Text = nodename;
//after creating the document, prepare it for publishing
doc.Publish(author);
//Tell umbraco to publish the document
umbraco.library.UpdateDocumentCache(doc.Id);
}
}
}
The problem I had was pulling through the parents name. Turns out I hadnt included the .Alias. Hope it helps!
Alec
is working on a reply...