Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
this should be simple, but I very rarely code things in Umbraco, so I'd like to know what's the best solution.
Customer has Umbraco 4.7.2 - not going to upgrade for a while yet.
I'd like to create an event handler on the beforePublish event and I've found code that works: http://www.richardsoeteman.net/PermaLink,guid,f470b6cf-40da-4aa9-a0d9-7b984fe9bf59.aspx
My problem is I need to sort all documents in folder by a custom property "dato" and keep the 10 newest in the folder, the rest go to archive folder. Unpublished documents I think will not be touched.
A code sample to do this would be much appreciated :)
I'm testing. Does anyone know why this moves only 1 item?
int nyhetsid = 3156; //1070;
int arkivid = 3281; //2058;
// Logg alltid eventer!
Log.Add(LogTypes.Custom, sender.Id, "Document Before publish Raised");
// Sjekk om har dokumenttype nyhet og at den skal arkiveres
if (sender.ContentType.Alias == "Sak")
// Sjekk at er i nyhetsmappen
if (sender.ParentId == nyhetsid)
Document nyhetsmappe = new Document(nyhetsid);
// Lag en liste med alle publiserte elementer i mappen
int i = 0;
Node mappe = new Node(nyhetsmappe.Id);
DataView dataView = new DataView(mappe.ChildrenAsTable());
dataView.Sort = " dato DESC";
foreach (DataRowView view in dataView)
int id = Convert.ToInt32(view.Row["Id"].ToString());
Document d = new Document(id);
if (i == 1)
// Avpubliser fra gjeldende node
// Publish blir kalt hvis brukeren velger Save and publish
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted