.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Cannot set list retention policy

Posted By:      Posted Date: October 07, 2010    Points: 0   Category :SharePoint

I'm trying to set a list policy for a doc lib. The code runs OK but does not set the policy correctly.

To create the retention XML, I created a doc lib Policy Lib, set it manually to a list policy, and set several stages.
Then I found that SP wrote the settings in an internal file called RetentionPolicy.Xml,
so I copied it to a local file E:\Temp\Retention.xml.
Then I deleted the doc lib and created it again from scratch, leaving all its default settings.

Then I set it to the saved XML file as follows:

XmlDocument doc = new XmlDocument();

SPList list = web.Lists["Policy Lib"];
ListPolicySettings lps = new ListPolicySettings(list);
lps.SetRetentionSchedule(doc.OuterXml, "Test");
lps.Uselpsicy = true;

lps = new ListPolicySettings(list);
Console.WriteLine("Has policy = " + lps.ListHasPolicy + ", UseListPolicy = " + lps.UseListPolicy);
Console.WriteLine("Retention Schedule= '{0}'", lps.GetRetentionSchedule(""););

The output looks OK, i.e.:

Has policy = True, UseListPolicy = True
Retention Schedule= '<RetentionItems><a href="/sites/Team/Policy Lib" Dirty="true" Desc="Test" ...</RetentionIt

View Complete Post

More Related Resource Links

Retention policy for content type not working


I have created a retention policy for the document content type and set it to delete a file permanently 3 days after the created date. It does not seem to be working, I have multiple documents in the library that have a created date over the 3 days. How often is the retention policy run? daily? weekly? Can it be changed?


Also, is it possible to take into account weekend days to exclude them from the counter?


Thank you,



Information Management Policy to clean up the Workflow History List?


I have several InfoPath 2007 forms (with workflows) that are heavily used in my MOSS 2007 environment, and the some of the Workflow History lists are very large need to be cleaned up.  I'm trying to use an (Expiration) Information Management Policy to delete items in the Workflow History list that are Last Modified + X days , but haven't had much success.  Has anyone else had success doing this?


SharePoint Designer 2010 workflow specified in Content Type retention policy not starting



I have a SharePoint Designer 2010 resuable workflow that uses the "Start Approval Process" Task Action. This workflow needs to run after a document has been declared a record. So I have a Content Type that has an Information Management Policy (IMP) attached to it. And I have 2 retention stages specified in the IMP. The first retention stage action is to run the workflow. And this Content Type is associated with the Document Library containing the records. But for some reason, the SPD workflow never gets triggered. The document has been successfully declared as a record. I also see in the document's "Compliance Details" screen, the "Scheduled Occurrence Date" is set to the proper date, but the workflow never got started on that date. I tried it with different dates that I set in the document, to ensure that the workflow runs on "Scheduled Occurence" dates such as 11/19/2010, 11/20/2010 to no avail.

What am I missing? Any help/suggestions would be greatly appreciated as always.

Best regards,
Kiran K

Custom Retention Policy deletion


I created a Feature solution in VS 2010 as per documentation found on the web. I delpoyed the solution twice (becuase I realized I had a bug in it).  The custom retention policy now shows up twice under the same name when I go to set retention for a content type. This is what I would expect.

Now, the issue is, that the Solution In VS 2010 has some properties: [Always Force Install] and [Auto Activate in Central Administration]

These can be viewd by using the Packagin Explorer and clicking on the feature.  Initially, when I deployed the first 2 times, these were both set to false.  The problem is that when these are set to false, the solution DOES NOT show up in central admin, and I can't find a way to delete it.

Interesting  note: I did set these properties to TRUE, and redeployed the solution.  It showed a THRID time in the Retention dialog, but ALSO showed in Central Admin.  I was able to deactivate and remove this version of the solution without issue. 

Is there a way to remove these policies from the server. I have looked for days to find a way or location where they are so I can brtue force it, but NO LUCK.

Thanks in advance.



Ready made List Types provided by SharePoint

SharePoint provides some out of the box List Types. Some of the most used ready made list types that SharePoint provides currently are listed below:

Export SharePoint List to Excel Spreadsheet Programmatically using C#

In SharePoint applications, Custom Lists are used to store business data and Document Libraries to store the documents. But for data manupulation and analysis, Microsoft Excel provides very rich features as compared to SharePoint Lists. That's why people still loves to work on Microsoft Excel Sheets.

Dropdown list in ASP.NET - How to get value selected

am sure this must be very simple, but unforunately I can't figure it out.
I have the following code which populates the dropdown lists from the database. This works fine. Now, when the user selects a particular employee name from the list, I want to get the Employee Id of the selected employee. i.e. I need to get the "Eid" value. I can do this if the EId is loaded in the dropdown list, but in this case only the employee name is displayed. Please let me know howI can get the Eid value even though it is not loaded in the dropdown list.
I would really appreciate your help

Creating Sites/Lists/List Items under Current User Context in SharePoint By Using SPUserToken

Usually we do this by performing the action under RunWithElevatedPrivileges method and updating the listitem using SPListItem.SystemUpdate() method (see here). but this approach has its own flaws like (RunWithElevatedPrivileges will run under system account, we cannot use SystemUpdate for SPSite,SPWeb,SPList, since it runs under system we will "CreatedBy" by as SystemAccount).

Editable Gridview with Textbox, CheckBox, Radio Button and DropDown List

This is an example of an editable gridview containing different ASP.NET controls. When user wants to edit values in gridview, she/he can use these controls to edit existing values in Gridview Edit Mode.

Using the Code

Get pixel format, raw format, property id list and property items image in VB.net - C#.net.

n this simple article you will learn that how we can get pixel format, raw format, property id list and property items image in VB and C#.net.

Get Pixel Format:

Image consists of pixels to get the format of the pixel we have a property named pixel format. This property returns an enumeration of pixel format. This enumeration tells the pixel format.

To demonstrate make a window application. Drag one button and a picture box on form.

Now write the following code on Button click event:

Binding an array to dropdown list


I have the following string which is a list of urls. How do I get this to work so the url shows for the selection and also is the value?      


allLinks = newAllLinks
        Me.DropDownList1.DataTextField = "Link"
        Me.DropDownList1.DataValueField = "LinkURL"
        Me.DropDownList1.Items.Insert(0, New ListItem(" - Select - ", 0))
        Me.DropDownList1.DataSource = allLinks


 ArgumentNullException: Value cannot be null.
Parameter name: container]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +121
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) +8

Compare List


i have got two list<string> containing datas

i would like to compare the both list and the result to new list whch does not contains the same data.(basically unique data)

eg shown below..

list A       list b          list c

a             a                 d

b           d                    c

c            f                   e

f            e

plz let me knw..

Gridview with a dropdown list for editing


Hello. I am working through Scott Mitchell's ASP.Net in 24 hours book. I am finishing the photo album project.

I have a GridView that retrieves a list of uploaded photo rows for the logged-in user.
The GridView is for editing and deleting rows.

The photo Category field in the Gridview is a dropdown list. The text entry field was deleted after converting this field to a Template.

Like the uploaded photos, these Categories are user-specific. They are created in another web page.

Users also have the option to select "none" for the category when they upload an image.

For the GridView:  The Category ID field's ItemTemplate and EditItemTemplate both have a " - None - " choice added to them.

I am getting this error:

'pictureReadOnlyCategories' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value


Note: The ID for the ItemTemplate for that dropdown list is the ID listed above in the error: "pictureReadOnlyCategories".


Am I missing some step in this process of changing a GridViews text field to a dropdown that can be used for editing? I went through the book's instructions three times.

Here is my code for the dropdown list and a screenshot of the Design

Format Generic List Bound to Gridview


I have a generic list of a custom type. The custom type has a string and double.

I'm binding the list to a gridview and it outputs everything fine.

I'm trying to format the double column into a currency format. It is in a template field as I'm calculating a running total. I pass the value to a function that returns a double and adds the current value to a running total which I will show in the footer.

The format is not changing to currency as expected when using String.Format("{0:c}", GetTotal(Convert.ToDouble(Eval("Amount"))))

Any ideas on what might be going on and how to fix this?


Populating Dropdown List using FK


Hi Folks,

2 Questions. I am trying out Data Entities in VWD 2010 Express. I have a parent (Customers) and child (Orders) table. Customers table has FirstName, LastName and Email columns.

Q1. When I view/edit/insert an Order, it shows the customer's first name in dropdown list whereas I want the full name. How can this be done?

Q2. How can I change the default behavior of PK/FK relationship so that customer's Email is displayed instead of Name?

Any help will be much appreciated.


C#, LINQ: (List<>) Question???


Hi Everyone,

I have a strange problem:


There is an entity (Table) called "Filters" in my .edmx which has all my tables and stuff in it (to use it for LINQ queries)

I have created a class called "CustomFilters" which inherits "Filters". So now my cutom class has all the properties of the original "Filters" class (table) and 1 more additional property that i wanted which is a List of "CustomFilters":

List<CustomFilters> children = new List<CustomFilters>();

Now i get all my records into:

List<CustomFilters> theOriginalList = new List<CustomFilters>();

NOTE: first all records are tken into a List<Filters> and then these are added into List<CustomFilters> where List<CustomFilters> for children of that record is added, and then children of the child records, and so on......

so now, every record is an instance of CustomFilters which has a property named "children" which is a list again; and each child again has instanaces of "CustomFilters", and each instance again has children...and on and on and on.....

(basiacally its a data source for a treeview in my silverlight control)

every thing is good and working as expected.


Getting users list reporting to manager from LDAP


Dear All,

I need to get list of users reporting to a particular manager from the Active directory.

In the active directory there is manager property with contains the data in the following way.


Please help me in building the filter condition.

I am using the following

pUserName="Gegore Lid";

strSearch = "(&(objectClass=user)(objectCategory=user)((Manager cn=" + pUserName + "))";

DirectorySearcher dSearcher = new DirectorySearcher(dEntry, strSearch);

            //Account properites to load
            string[] arrPropertiesToLoad = { "displayName", "department", "manager", "sAMAccountName", "EmployeeNumber", "Title" };

          SearchResultCollection sResultColl = dSearcher.FindAll();

 the above code is not returning any result.

Please help me in this.



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend