Answered How to deleted a list with lookup column programatically

  • Thursday, March 08, 2012 11:17 PM
     
     

    I have created a list with lookups and dependent lookup fields.

    Enforce the relationship to restrict to deleted.

    Now i have to delete he list programatically.

    How to delete the list.


    kukdai

All Replies

  • Thursday, March 08, 2012 11:23 PM
     
     

    Break the lookup dependence, programmatically.

    After that you will be able to delete list.


    Каждый админ должен: проложить сеть, посадить кактус, вырастить кота

  • Thursday, March 08, 2012 11:34 PM
     
     
    how to breakup the lookup dependency programatically i dont see any menthods there do you have any refrences or method names.

    kukdai

  • Friday, March 09, 2012 1:59 AM
     
     

    Primarily you will have to delete the field to delete the list. With regards to getting hold of the relationship check the code below which sets the relationship to cascade.

    SPFieldLookup teamLeaderField = (SPFieldLookup)projectsList.Fields.GetFieldByInternalName(teamLeaderFieldInternalName);
    teamLeaderField.LookupField = employeesList.Fields["Title"].InternalName;
    teamLeaderField.RelationshipDeleteBehavior = SPRelationshipDeleteBehavior.Cascade;
    teamleaderField.Indexed = true;
    teamLeaderField.Update();


    Varun Malhotra
    =================
    If my post solves your problem could you mark the post as Answered or Vote As Helpful if my post has been helpful for you.

  • Friday, March 09, 2012 5:02 AM
     
     

    Do you want to delete the list (child list) which has look fields or the parent list?


    Regards,
    Shantha Kumar .T | MCPD - SharePoint Developer 2010 | MCITP - SharePoint Administrator 2010
    (B) Shantha Kumar's Blog | (T)Follow me

  • Friday, March 09, 2012 7:19 AM
     
     
  • Friday, March 09, 2012 8:46 AM
     
     Proposed Has Code

    The way to break dependency:

    using (var site = new SPSite("http://server/"))

    {

        using (var web = site.OpenWeb())

        {

            var list = web.Lists.TryGetList("MyListTitle");

            if (list != null)

            {

                var lookupField = (SPFieldLookup) list.Fields["LookupFieldName"];

                lookupField.RelationshipDeleteBehavior = SPRelationshipDeleteBehavior.None;

    lookupField.Update();

            }

        }

    }



    Каждый админ должен: проложить сеть, посадить кактус, вырастить кота


  • Tuesday, March 13, 2012 3:42 PM
     
     Answered

    actually i have to delete the dependent column first setting the delete behavior to true.

    then i deleted the dependent columns first and the main lookup field.

    this way it worked for me thanks everyone.


    kukdai