1

I have 2 site collections with matching "Master Page Gallery" lists and one has corrupted values. To fix this I wish to overwrite all files and folders with the data found in the good list.

I have disabled moderation & versioning.

I skip the "Forms" folder & the "v4.master"

I use

  private void start(SPList good, SPList bad){
      SPFolder badRoot = bad.RootFolder;

      foreach(SPFolder f in good.RootFolders.SubFolders){
          If(f.name != "Forms") badRoot= MyRecursive(f, badRoot);
      }

      foreach(SpFile file in good.files)
           badRoot = CopyFiles(file, badRoot);
  }

  Private SPFolder MyRecursive(SPFolder f, SPFolder badRoot){
       foreach(SPFolder sub in f.subfolders)
             badRoot = MyRecursive(sub,badRoot.SubFolders[f.url])


       foreach(SPFile file in f.Files)
              badRoot = CopyFile(file,badRoot);

       return badRoot;
  }

  private void CopyFile(SPFile file, SPFolder folder){
      Try{
         folder.Files.Add(file.url , file.OpenBinaryStream(), file.Properties, true);
         folder.update()
      }catch{}
      return folder;
  }

I get all the files & all the metadata correct except Existing 'Forwardlinks' become "00000000-0000-0000-0000-000000000000" and exisiting 'Backwardlinks' become null.

Does anybody know how to correct this? Or a better method?

  • If you have SharePoint Designer, you can open both site and copy the master page contents. Else you can download all files from good site add into bad site by creating features with modules. Refer this link.. (sharepoint.stackexchange.com/questions/13065/…) – Suren Apr 26 '13 at 7:12

Your Answer

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

Browse other questions tagged or ask your own question.