次の方法で共有


MCMS 2002 to MOSS migration issue : Leaf names are not unique

Unfortunately MCMS 2002 Site Manager doesn’t allow you to rename the postings or resource gallery items. In some situation you may end up duplicate entries in the resource gallery item names. MCMS 2002 allows you to have multiple resource items or postings with same name. The items will be differentiated by using their GUIDs. But this will end up a problem when you are migrating to MOSS 2007, and you will get "Leaf names are not unique." error message. And the only work-around is renaming all those files.

Untitled

But we can work-around this issue using MCMS PAPI. I have created an utility to find out all the duplicated postings and resources and rename all of them in a single shot. I have written the code in a .NET console based application. We have to run this code in the MCMS server by login to your machine as a user who has edit permission. I would recommend executing this code by login as MCMS administrator.

    1: using System;
    2: using System.Security.Principal;
    3: using System.IO;
    4: using Microsoft.ContentManagement.Publishing;
    5: using System.Collections;
    6:  
    7: namespace RenameTheChannels
    8: {
    9:     /// <summary>
   10:     /// Summary description for Class1.
   11:     /// </summary>
   12:     class Class1
   13:     {
   14:         /// <summary>
   15:         /// The main entry point for the application.
   16:         /// </summary>
   17:         public static CmsApplicationContext appContext = null;
   18:         public static TextWriter oTextWriter = null;
   19:         [STAThread]
   20:         static void Main(string[] args)
   21:         {
   22:             try
   23:             {
   24:                 oTextWriter = new StreamWriter("FixDuplicateEntries.txt");
   25:                 appContext = new CmsApplicationContext();
   26:                 WindowsIdentity ident = WindowsIdentity.GetCurrent();
   27:                 appContext.AuthenticateUsingUserHandle((System.IntPtr)ident.Token.ToInt32(),PublishingMode.Update);        
   28:                 Console.WriteLine("********************************************Renaming Postings*********************************************");
   29:                 IterateAllChannels(appContext.RootChannel);
   30:                 Console.WriteLine("******************************************** End of Renaming Postings*************************************");
   31:                 Console.WriteLine("******************************************** Renaming Resources*******************************************");
   32:                 IterateResourceGallery(appContext.RootResourceGallery);
   33:                 Console.WriteLine("******************************************** End of Renaming Resources************************************");
   34:                 
   35:             }
   36:             catch(Exception ex)
   37:             {
   38:                 Console.WriteLine(ex.Message);
   39:             }
   40:             finally 
   41:             {
   42:                 appContext.Dispose();
   43:                 oTextWriter.Close();
   44:                 Console.WriteLine("Operation has been completed !");
   45:                 Console.ReadLine();
   46:             }
   47:         }
   48:  
   49:         public static void IterateResourceGallery(ResourceGallery oRootResourceGallery)
   50:         {
   51:             foreach(ResourceGallery oChildResourceGallery in oRootResourceGallery.ResourceGalleries)
   52:             {
   53:                 string[] childResources = FinalResources(oChildResourceGallery);
   54:                 IterateResourceGallery(oChildResourceGallery);
   55:             }
   56:         }
   57:  
   58:         public static string[] FinalResources(ResourceGallery oChildResourceGallery)
   59:         {
   60:             string[] Resources = new string[oChildResourceGallery.Resources.Count];
   61:             
   62:             //bool hasChange = false;
   63:  
   64:             if(oChildResourceGallery.Resources.Count >0)
   65:             {
   66:                 ArrayList oResourceList = new ArrayList();
   67:                 for(int i=0;i<oChildResourceGallery.Resources.Count;i++)
   68:                 {                    
   69:                     oResourceList.Add(oChildResourceGallery.Resources[i]);
   70:                 }    
   71:                 
   72:                 int iCount = 1;
   73:  
   74:                 foreach(Resource oCompareResource in oChildResourceGallery.Resources)
   75:                 {                    
   76:                     int i=0;
   77:                     foreach(Resource oResource in oResourceList)
   78:                     {
   79:                         if(oResource.Name == oCompareResource.Name )
   80:                         {    
   81:                             i++;
   82:                             if(i>1)
   83:                             {
   84:                                 string[] strName = oResource.Name.Split('.');
   85:  
   86:                                 string strOldName = oResource.Name;                                
   87:                                 string strNewName = strName[0] + i.ToString() +"." + strName[1];;
   88:  
   89:                                 oResource.Name = strNewName;
   90:                                 oResource.DisplayName = strNewName;                                                                
   91:                                 appContext.CommitAll();
   92:                                 Console.WriteLine("Resource Gallery : " + oChildResourceGallery.Name + "old name: " + strOldName + " New Name :" + strNewName );
   93:                                 oTextWriter.WriteLine("Resource Gallery : " + oChildResourceGallery.Name + "old name: " + strOldName + " New Name :" + strNewName );
   94:                             }
   95:                             
   96:                         }
   97:                     }
   98:                     iCount ++;
   99:                 }
  100:             }            
  101:             return Resources;        
  102:         }
  103:  
  104:         public static void IterateAllChannels(Channel oRootChannel)
  105:         {            
  106:             
  107:             foreach(Channel oChildChannel in oRootChannel.Channels)
  108:             {
  109:                 string[] childrenPosting = FinalPosting(oChildChannel);
  110:                 IterateAllChannels(oChildChannel);
  111:             }
  112:         }
  113:  
  114:         public static string[] FinalPosting(Channel oChildChannel)
  115:         {
  116:             string[] Postings = new string[oChildChannel.Postings.Count];
  117:         
  118:  
  119:             if(oChildChannel.Postings.Count >0)
  120:             {
  121:                 ArrayList oPostingList = new ArrayList();
  122:                 for(int i=0;i<oChildChannel.Postings.Count;i++)
  123:                 {                    
  124:                     oPostingList.Add(oChildChannel.Postings[i]);
  125:                 }    
  126:                 
  127:                 int iCount = 1;
  128:  
  129:                 foreach(Posting oComparePosting in oChildChannel.Postings)
  130:                 {                    
  131:                     int i=0;
  132:                     foreach(Posting oPosting in oPostingList)
  133:                     {
  134:                         if(oPosting.Name == oComparePosting.Name )
  135:                         {    
  136:                             i++;
  137:                             if(i>1)
  138:                             {
  139:                                 
  140:                                 string strOldName = oPosting.Name;                                
  141:                                 string strNewName = strOldName + i.ToString();
  142:  
  143:                                 oPosting.Name = strNewName;
  144:                                 oPosting.DisplayName = strNewName;    
  145:                                 oPosting.Approve();
  146:         
  147:                                 appContext.CommitAll();
  148:                                 Console.WriteLine("Channel : " + oChildChannel.Name + "old name: " + strOldName + " New Name :" + strNewName );
  149:                                 oTextWriter.WriteLine("Channel : " + oChildChannel.Name + "old name: " + strOldName + " New Name :" + strNewName );
  150:                             }                            
  151:                         }
  152:                     }
  153:                     iCount ++;
  154:                 }
  155:             }            
  156:             return Postings;
  157:         }
  158:  
  159:     }
  160: }
  161:  
  162:  
  163:  

MCMS 2002 Migration: https://msdn.microsoft.com/en-us/library/aa480227.aspx

Comments

  • Anonymous
    September 09, 2008
    PingBack from http://hoursfunnywallpaper.cn/?p=5431

  • Anonymous
    July 02, 2009
    Its a nice article. Can you tell me where to code the above mention code and how to run. I mean step by step. Kindly Help

  • Anonymous
    July 02, 2009
    that code was developed for  .Net console based application. You can wrap it in a .net cosole application and run it in the MCMS server. Thanks, Sowmyan

  • Anonymous
    July 06, 2009
    But how to run in MCMS Server- I mean can you tell me the steps.

  • Anonymous
    July 24, 2009
    First you have to create .Net console application with the code that I have provided here, once you compile the application it will create an execuatable (.exe) file for you. you can just double click on it and it will run, or if you are developing the application in CMS server then can run it directly from the VS by pressing F5.

  • Anonymous
    December 20, 2010
    The comment has been removed

  • Anonymous
    December 20, 2010
    ah - I see the links are updated in the site anyhow - so I guess it doesn't matter how the renaming works. Sorry for odd question! Thank you again for posting this - especially the code.