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 use a FeatureEventReceiver to rename Home.aspx -> Old_Home.aspx. When i activate the feature rather than Home.aspx getting renamed it gets deleted/disappears (i.e. missing when i refresh sharepoint designer) from the library. Here is the FeatureActivated....what be i doing wrong?

public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb curWeb = (SPWeb)properties.Feature.Parent;
            SPSite curSite = curWeb.Site;
            SPWeb rootWeb = curSite.RootWeb;

            /* Rename Home.aspx to Old_Home.aspx */

            SPList list = rootWeb.Lists["Site Pages"];
            if (list != null)
            {
                foreach (SPListItem item in list.Items)
                {
                    if (item["Name"].Equals("Home.aspx"))
                    {
                        item.File.CheckOut();
                        item["Name"] = "Old_Home.aspx";
                        item.Update();
                        item.File.CheckIn("file name has been changed");
                        break;
                    }

                }
            }            
        }

TIA

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

this doesnt work when you have multiple language packs installed...

This Will help you :

http://blogs.msdn.com/b/sowmyancs/archive/2008/10/02/programmatically-rename-a-file-inside-a-sharepoint-document-library.aspx

share|improve this answer
add comment

Could you be missing

item.File.Publish();

Also, as you debug, is there any exception thrown? Any entry on the ULS or on the Event Viewer that could give you some clue of what's happening?

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.