none
CopyTo Method RRS feed

  • Question

  • Hi All,

    we are writing eventreceiver for copying the pages to different site Page library when page is added to site Page library. CopyTo method is not working in this even its not throwing any error.

    Public override void ItemAdded(SPItemEventProperties properties)

            {

                try

                {

                    if(properties.ListTitle.Equals("Pages"))

                    {

                        SPFile fileName = properties.ListItem.File;

                        string strOtherPageLib = "http://MOSS/English/Uutiset_ja_tapahtumat/Turku/Pages/";

                       

     

                        fileName.CopyTo(strOtherPageLib, true);

                      

                       

     

                        base.ItemAdded(properties);

                    }

                }

                catch (Exception exp)

                {

                    //HACK: Need to log the error

                }

           }

    Any help is appreciable.

    Thanks,
    Neetu


    neetu
    Monday, October 26, 2009 3:13 PM

Answers

  • CopyTo only works within one site.
    Hope this helps, Koen Vosters http://koenvosters.wordpress.com
    • Marked as answer by neetukanyal Monday, October 26, 2009 3:51 PM
    Monday, October 26, 2009 3:46 PM
  • CopyTo or MoveTo does not work in this case. you will have to use approach of adding the file yourself to destination by using SPWeb.Files.Add method.
    Please note that you will also have to move the version history yourself if you need version history in destination. It can be done by iterating on Versions of SPFile. Let me know if you need help around version history.
    Moonis Tahir MVP, MCPD, MCSD.net, MCTS BizTalk 2006/SQL 2005/SharePoint Server 2007 (Dev & Config)
    • Marked as answer by neetukanyal Monday, October 26, 2009 3:51 PM
    Monday, October 26, 2009 3:46 PM

All replies