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 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

share|improve this question
    
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 –  Per Jakobsen Apr 2 '12 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 –  Muhammad Raja Apr 2 '12 at 17:02
1  
Changing a list schema in the 12 hive is absolutely NOT a solution –  Per Jakobsen Apr 2 '12 at 17:18
add comment

1 Answer

up vote 0 down vote accepted

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;
share|improve this answer
add comment

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.