You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Copy/Paste is tightly related to Clone. This is how it can be done :

ProjectService.CopyTo(IFolderItem targetContainer,IFolderItem sourceItem)
{
   if (!targetContainer can accept sourceItem)
      return;//should never get here we try to paste a folder in a model or something
   
   //clone the sourceItem
   var target = sourceItem.Clone();
   var fileItems = target.GetAllItemsRecursive<IFileBased>();
   foreach (IFileBased fileBasedItem in fileItems)
   {
      //create a copy of the file if it is projectdata to prevent unwanted relations
      if (item is projectdata/internal)
      {
          string newPath = GetSomeNewGuidName();
          //this will copy internal and reconnect the file to the new source
          fileBasedItem.Relocate(newPath);
      }
   }
}

  • No labels