Remove old ProjectItem

341
3
12-05-2019 02:21 PM
MKa
by
Occasional Contributor III

I need to find a way to remove old Layouts from my project if they were added before a certain date.  I create layout templates and add them to my addin.  These templates are then used to print a map, however, after it is loaded I stays with the project.  I do want the layout to stay with the project (as load times are much faster), but when I update the Layout I want to remove the existing template if it is before a certain date that I maintain.  I need to be able to get the date the existing Layout was added to the Projects catalog, then I will remove it based on this date if it is old.

//Remove the old templates that might be out of date
                    foreach (LayoutProjectItem layoutTemplate in Project.Current.GetItems<LayoutProjectItem>())
                    {
//NEED LOGIC HERE TO SEE IF THE layoutTemplate IS BEFORE a DATE
                        Project.Current.RemoveItem(layoutTemplate as IProjectItem);
                    }
0 Kudos
3 Replies
UmaHarano
Esri Regular Contributor

Hi

Looks like Layout.SourceModifiedTime is not providing the correct info. The Layout development team is looking at this issue. I will update this post when there is a fix.

Thank you!

Uma

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

A possible work around (I didn't try this yet): Maybe until the problem is resolved you can add the 'layout added' date as part of the LayoutProjectItem's Summary property and then parse the Summary string for the 'layout added' date as part of your removal logic.

JeffBarrette
Esri Regular Contributor

Thank you for bringing this requirement to our attention.  The SourceModifiedTime property is only used for project items that were added from a portal.  The documentation will be updated to reflect its purpose more clearly.  The development team will strongly consider this requirement and possibly add a new property specific to this use case (e.g., LastModified).  The final solution goes beyond just Layout project items.  We do not have a time frame since there are details to be worked out. In the meantime, Wolfgang's suggestion is hopefully a viable solution.

Jeff

Layout Team

0 Kudos