Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to give a SPLists a Expiry Date so they are later deleted through a timerjob. The value is set by the user when they create a list through my functioning visual webpart.

Is it possible to give a List this value or do I have to give each SPListItem?

share|improve this question
    
you want to delete the items in the list or the whole list? –  SPArchaeologist May 13 '13 at 10:46
    
The whole list. Right now I see only two solutions. Either add expirydate to lists description or have a column for each listitem with the same expirydate. It works but its ugly. –  Skaft May 13 '13 at 11:07
    
To add an expiry date to the item in a list is easy - you could do that with OOTB features. Deleting the list on the other hand seems somewhat more complex - no idea comes to mind. Could you live by using folders inside a main lib that won't be deleted? That way you should be able to use retention policies. –  SPArchaeologist May 13 '13 at 11:17
    
Deleting the list is easy. Im using a timerjob to iterate through lists on a specific webapp and compairing todays date with ExpireDate-value, then deleting all lists that is expired. –  Skaft May 13 '13 at 12:37
    
So your problem isn't deleting the list (you use a timer job). It is "how to mark the list for deletion / how to recognize which list to delete". Ok, forget my suggestion about retention polices... seems you don't need them anymore. –  SPArchaeologist May 13 '13 at 13:50

2 Answers 2

up vote 2 down vote accepted

Many SharePoint objects have a Property collection. Lists do not directly, but you can use list.RootFolder.Properties and there are methods for Add, Delete, Get, and SetProperty. There's an example here: http://www.novolocus.com/2012/07/23/getting-and-setting-properties-in-sharepoint/

share|improve this answer
    
This looks very promising. I will implement it and get back to you. –  Skaft May 13 '13 at 13:43
    
Works! Thank you very much. –  Skaft May 13 '13 at 14:11

a simple method would be to have a hidden date field associated with the default document type in the list and to set that at a specific date e.g. 25th December 1970 for example. It could then be easily used as the identifier when you want to remove the list.

If you want to have a hidden field like this added to the type, you'll need to set the 'Allow Management of Content Types' to 'Yes' and then you can either add a new column to that and set it as hidden by default or create a new column and again set it to hidden. Importantly it wouldn't be visible in any way to end users etc. but would be useful programmatically.

Hope this is a useful alternative. Alan C.

share|improve this answer
    
This was how i temporarily solved it at first. Thanks for your assistans. –  Skaft May 14 '13 at 9:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.