0

I am trying to find a script that will replace Sharepoint Events List with one of Custom List i created + Copy all the data of Events list to my newly created list.

I know how to Delete a list and Create a new list, but dunno if there is any simplest way of replacing a Moss List.

Cheers

3
  • Why do you want to replace the list? If the existing list has information in it you have the risk of links to the existing list. In a lot of cases create a new Content Type add that content type to the list and change all the existing items will be a better solution Apr 2, 2012 at 16:59
  • I hidden Meeting Workspace checkbox from the list and created a new list based on that schema, but because its a big organization i am working for and my senior Developer asked me to do it this way, so i have to follow him :/, even tho i know some quick fixes like changing the scheme file in the 12 hive on live servers, But again am not allowed and suppose to follow the instructions, Cheers Apr 2, 2012 at 17:02
  • 1
    Changing a list schema in the 12 hive is absolutely NOT a solution Apr 2, 2012 at 17:18

1 Answer 1

0

Approach I used to Solve the Issue is,

  • Create a New List
  • Copy Items to New List
  • Delete old List

//Add a List

web.Lists.Add(listName, listDesc, t);

//Copying

SPList myDestinationList = web.Lists[destinationlistName];
                SPList mySourceList = web.Lists[Form1.OldListName];
                SPQuery mySourceListQuery = new SPQuery();
 SPQuery mySourceListQuery = new SPQuery();

            mySourceListQuery.Query = "<OrderBy><FieldRef Name='Title' /><FieldRef Name='Location' /></OrderBy>";" 
            SPListItemCollection mySourceItemColl = mySourceList.GetItems(mySourceListQuery);
            foreach (SPListItem mySourceListItem in mySourceItemColl)
            {
                SPListItem myDestinationListItem = myDestinationList.Items.Add();

                if (mySourceListItem["Title"] != null)
                    myDestinationListItem["Title"] = mySourceListItem["Title"];

                if (mySourceListItem["Location"] != null)
                    myDestinationListItem["Location"] = mySourceListItem["Location"];


                web.AllowUnsafeUpdates = true;
                myDestinationListItem.Update();
                web.AllowUnsafeUpdates = false;

//deleting a list

        web.AllowUnsafeUpdates = true;
        SPList myList = web.Lists[list];
        myList.Delete();
        web.AllowUnsafeUpdates = false;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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