Question

On a refactoring exercise we are working on, we have to change Page Templates for select websites. Most page get localized and have their page templates updated by the code below but for a few we get the following error:

"Name, File Name must be unique for items of type: Page within its Structure Group and its Blueprint context. Source or sources of conflict tcm:121:3456-64".

I checked both the current page being processed and the page mentioned in the error and both have unique names and filenames. Any ideas what might be causing the issue?

P.S. I was able to solve the earlier error with the excellent suggestions posted to my question. Expecting a similar response this time.

try
{
pData = client.Read(page.Attribute("ID").Value, null) as PageData;
//Localize Page
if (!(bool)pData.BluePrintInfo.IsLocalized)
{
    client.Localize(pData.Id, new ReadOptions());
    if (dTemplateIDs.ContainsKey(pData.PageTemplate.IdRef.ToString()))
    {
        pData.IsPageTemplateInherited = false;
        pData.PageTemplate.IdRef = dTemplateIDs[pData.PageTemplate.IdRef];
        client.Update(pData, new ReadOptions());
    }
}
}
catch (Exception ex)
{
 Console.WriteLine("Error Inner " + ex.Message);
} 
Was it helpful?

Solution

There're some mistakes in your code, not sure they are calling exception, but worth fixing anyway. First of all you do not really read the page as your ReadOptions are null when you read it. Second, you should get your page from Localize method and then update localized version of the page. Like this:

try
{
    // You need read options here
   pData = (PageData) client.Read(page.Attribute("ID").Value, new ReadOptions()); 
   //Localize Page
   if (!(bool)pData.BluePrintInfo.IsLocalized)
   {
    // Get localized page here      
    pData = (PageData) client.Localize(pData.Id, new ReadOptions());
    if (dTemplateIDs.ContainsKey(pData.PageTemplate.IdRef.ToString()))
    {
        pData.IsPageTemplateInherited = false;
        pData.PageTemplate.IdRef = dTemplateIDs[pData.PageTemplate.IdRef];
        // You do not need read options here
        client.Update(pData, null);
    }
}
}
catch (Exception ex)
{
 Console.WriteLine("Error Inner " + ex.Message);
}  

And finally, if it all will not help,can you post stack trace as well?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top