Ejemplo n.º 1
0
 public int DeleteUsers(string sDomainUsers, Credentials credentials) {
     object[] results = this.Invoke("DeleteUsers", new object[] {
                 sDomainUsers,
                 credentials});
     return ((int)(results[0]));
 }
Ejemplo n.º 2
0
 /// <remarks/>
 public void DeleteUsersAsync(string sDomainUsers, Credentials credentials) {
     this.DeleteUsersAsync(sDomainUsers, credentials, null);
 }
Ejemplo n.º 3
0
 /// <remarks/>
 public void CreateStandardValuesAsync(string strItem, Credentials credentials) {
     this.CreateStandardValuesAsync(strItem, credentials, null);
 }
Ejemplo n.º 4
0
        private Sitecore6xItem CopyItemTo(IItem CopyFrom)
        {
            Sitecore6xItem returnItem = null;

            Util.SetStatus("Copying from: " + CopyFrom.Path, "Copying to: " + _sPath);

            // *** Create templates ***
            string sTemplatePath = null;

            // Don't create templates if we are using names instead of id's
            if (this.Options.CopyOperation == CopyOperations.UseNames)
            {
                sTemplatePath = CopyFrom.Templates[0].Path;
            }
            else
            {
                if (CREATE_NEW_BASE_TEMPLATE)
                {
                    // Check to see if Template import folder has been created
                    Sitecore6xItem templateFolder = GetSitecore61Item(TEMPLATE_IMPORT_FOLDER);
                    if (templateFolder == null)
                    {
                        CreateTemplate(TEMPLATE_IMPORT_FOLDER.Remove(TEMPLATE_IMPORT_FOLDER.LastIndexOf("/")),
                                        "/sitecore/templates/common/folder",
                                        TEMPLATE_IMPORT_FOLDER.Remove(0, TEMPLATE_IMPORT_FOLDER.LastIndexOf("/") + 1));
                    }
                    else
                        AddItemToCache(templateFolder);
                }

                // *** Find and create base template from current item ***
                string sBaseTemplatePath = "";
                if (CopyFrom.BaseTemplate != null)
                {
                    Sitecore6xItem baseTemplateItem = null;
                    if (CREATE_NEW_BASE_TEMPLATE)
                    {
                        // Get alternate base template from name, because we don't want to use the "normal" standard template
                        sBaseTemplatePath = TEMPLATE_IMPORT_FOLDER + "/" + CopyFrom.BaseTemplate.Name;
                        baseTemplateItem = GetSitecore61Item(sBaseTemplatePath);
                    }
                    else
                    {
                        // Get normal standard template
                        baseTemplateItem = GetSitecore61Item(CopyFrom.BaseTemplate.ID);
                        if (baseTemplateItem != null)
                            sBaseTemplatePath = baseTemplateItem.ID;
                    }

                    if (baseTemplateItem != null)
                        AddItemToCache(baseTemplateItem);
                }

                // *** Create Template from current item ***
                string sInheritedTemplateIDs = "";
                // Create the templates inherited templates
                RecursivelyCreateTemplates(CopyFrom, out sInheritedTemplateIDs, sBaseTemplatePath);

                // Finally create the items template
                sTemplatePath = CopyFrom.Templates[0].ID;
                //            sTemplatePath = CreateTemplate(CopyFrom.Templates[0], Util.GuidToSitecoreID(CopyFrom.Templates[0].ID), sInheritedTemplateIDs);

                // Normal items only has one template, sTemplatePath will point to the right template.
                // The current item must be a template item because there is more than one template, so the
                // "standard template" is used as "base template" for this template item.
                if (CopyFrom.Templates.Length > 1)
                {
                    sTemplatePath = CopyFrom.BaseTemplate.ID;
                }
            }

            // *** Create Item ***
            string sItemVersion = "1";
            string sNewItemID = "";
            Sitecore6xItem templateItem = null;
            if (this.Options.CopyOperation == CopyOperations.Overwrite)
            {
                // Find existing item
                returnItem = GetSitecore61Item(CopyFrom.ID, this);
                if ((returnItem == null) && (!Util.IsTemplateOnIgnoreList(CopyFrom.Templates)))
                {
                    // No item was found, create new using existing item id's
                    CreateTemplateItemWithSpecificID(this.ID, sTemplatePath, CopyFrom.ID, CopyFrom.Name);
                }
                sNewItemID = CopyFrom.ID;
            }
            // Generate new items id's
            else if (this.Options.CopyOperation == CopyOperations.GenerateNewItemIDs)
            {
                sNewItemID = "";
                CreateTemplateItemWithSpecificID(this.ID, sTemplatePath, ref sNewItemID, CopyFrom.Name);
            }
            // Skip existing items id's
            else if (this.Options.CopyOperation == CopyOperations.SkipExisting)
            {
                returnItem = GetSitecore61Item(CopyFrom.ID, this);
                if (returnItem == null)
                {
                    // Use existing item id's
                    CreateTemplateItemWithSpecificID(this.ID, sTemplatePath, CopyFrom.ID, CopyFrom.Name);
                    sNewItemID = CopyFrom.ID;
                }
            }
            // Use names to identify items, instead of ID's
            else if (this.Options.CopyOperation == CopyOperations.UseNames)
            {
                // If the template cannot be found then skip this item
                templateItem = GetSitecore61Item(sTemplatePath);
                if (templateItem == null)
                    returnItem = null;
                else
                {
                    // Find existing item
                    returnItem = GetSitecore61Item(this.Path + "/" + CopyFrom.Name, this);
                    if (returnItem != null)
                        sNewItemID = returnItem.ID;
                    else
                    {
                        sNewItemID = "";
                        CreateTemplateItemWithSpecificID(this.ID, sTemplatePath, ref sNewItemID, CopyFrom.Name);
                    }
                }
            }

            // If we are skipping existing then do nothing here
            if ((returnItem != null) &&
                ((this.Options.CopyOperation == CopyOperations.SkipExisting) /* ||
                 (this.Options.CopyOperation == CopyOperations.UseNames) */))
            { }
            else if ((templateItem == null) &&
                (this.Options.CopyOperation == CopyOperations.UseNames))
            {
                returnItem = GetSitecore61Item(this.Path + "/" + CopyFrom.Name);
            }
            else if (Util.IsTemplateOnIgnoreList(CopyFrom.Templates))
            {
                // skip this
            }
            // Otherwise populate data fields
            else
            {
                XmlNode contentItem = GetItemXml(sNewItemID);

                // Set language
                XmlNodeList versionNodes = contentItem.SelectNodes("//item/version[@language = '" + this.Options.Language + "']");
                if ((versionNodes == null) || (versionNodes.Count == 0))
                {
                    // If language version is missing, we create it
                    CheckSitecoreReturnValue(_sitecoreApi.AddVersion(sNewItemID, this.Options.Language, Util.CurrentDatabase, _credentials));
                    contentItem = GetItemXml(sNewItemID);
                }
                else
                {
                    sItemVersion = GetItemVersion(contentItem);
                }

                // Save item by creating a new or overwrite existing
                if (returnItem == null)
                {
                    // Update existing fields
                    foreach (IField field in CopyFrom.Fields)
                    {
                        contentItem = ModifyItemField(contentItem, field.TemplateFieldID, field.Key, field.Type, field.Content);
                    }

                    CheckSitecoreReturnValue(_sitecoreApi.InsertXML(this.ID, contentItem.OuterXml, false, Util.CurrentDatabase, _credentials));

                    // Should get returnItem even though it already existed, the fields might have been updated
                    if (this.Options.CopyOperation == CopyOperations.UseNames)
                        returnItem = GetSitecore61Item(sNewItemID, this, true);
                    else
                        returnItem = GetSitecore61Item(sNewItemID, this);
                }

                // Create "Sortorder" field (actually stored on item as an attribute)
                AddFieldFromTemplate(returnItem, "/sitecore/templates/System/Templates/Sections/Appearance/Appearance/__Sortorder", CopyFrom.SortOrder);
                returnItem.SortOrder = CopyFrom.SortOrder;

                // Copy all the fields
                foreach (IField fromField in CopyFrom.Fields)
                {
                    // Fetch field using Key this is neccesary because the field constructor only reads the key, not the name
                    IField toField = Util.GetFieldByName(fromField.Key, returnItem.Fields);
                    if (toField == null)
                    {
                        Sitecore6xField field = new Sitecore6xField(fromField.Name, fromField.Key,
                                    fromField.Type, new Guid(fromField.TemplateFieldID), fromField.Content, fromField.SortOrder, fromField.Section);
                        returnItem._fields.Add(field);
                        toField = field;
                    }
                    toField.Content = ConvertFieldContent(CopyFrom, fromField);
                }

                // Call plugins and update user interface
                if (this.Options.CopyItem != null)
                {
                    this.Options.CopyItem(CopyFrom, this, returnItem);
                }

                // Save item by overwriting existing, neccessary if any returnItem fields have been changed
                returnItem.Save();

                // Copy security rights - if they exist
                if ((this.Options.CopySecuritySettings) && (CopyFrom.Roles != null))
                {
                    try
                    {
                        ExtendedSitecoreAPI.Credentials credential = new ExtendedSitecoreAPI.Credentials();
                        credential.UserName = _credentials.UserName;
                        credential.Password = _credentials.Password;

                        if ((!this.Options.UsersCopied) && (CopyFrom.Users != null))
                        {
                            for (int t = 0; t < CopyFrom.Users.Count(); t++)
                            {
                                bool bIsAdmin = false;
                                if (CopyFrom.Users[t].UserSettings["IsAdmin"].ToLower() == "true")
                                    bIsAdmin = true;
                                ExtendedWebService.CreateUser(
                                            CopyFrom.Users[t].Name,
                                            CopyFrom.Users[t].UserSettings["PassWord"],
                                            CopyFrom.Users[t].UserSettings["Email"],
                                            CopyFrom.Users[t].UserSettings["FullName"],
                                            CopyFrom.Users[t].UserSettings["Roles"],
                                            bIsAdmin,
                                            credential);

                            }
                            this.Options.UsersCopied = true;
                        }

                        for (int t = 0; t < CopyFrom.Roles.Count(); t++)
                        {
                            string sRole = CopyFrom.Roles[t].Name;
                            sRole = Util.MakeValidRoleName(sRole);

                            //                            if (sRole == "__Everyone")
                            //                                sRole = "Everyone";

                            // Add domain name to role, if it isn't already a part of a domain
                            if ((sRole.IndexOf("\\") == -1) && (this.Options.DefaultSecurityDomain != ""))
                                sRole = this.Options.DefaultSecurityDomain + "\\" + sRole;

                            // Allow
                            string sRight = "";
                            if ((CopyFrom.Roles[t].AccessRight & AccessRights.Read) == AccessRights.Read)
                                sRight += "item:read|";

                            if ((CopyFrom.Roles[t].AccessRight & AccessRights.Write) == AccessRights.Write)
                                sRight += "item:write|";

                            if ((CopyFrom.Roles[t].AccessRight & AccessRights.Create) == AccessRights.Create)
                                sRight += "item:create|";

                            if ((CopyFrom.Roles[t].AccessRight & AccessRights.Delete) == AccessRights.Delete)
                                sRight += "item:delete|";

                            if ((CopyFrom.Roles[t].AccessRight & AccessRights.Rename) == AccessRights.Rename)
                                sRight += "item:rename|";

                            if ((CopyFrom.Roles[t].AccessRight & AccessRights.Administer) == AccessRights.Administer)
                                sRight += "item:admin|";

                            // Deny
                            string sDenyRight = "";
                            if ((CopyFrom.Roles[t].AccessRight & AccessRights.DenyRead) == AccessRights.DenyRead)
                                sDenyRight += "item:read|";

                            if ((CopyFrom.Roles[t].AccessRight & AccessRights.DenyWrite) == AccessRights.DenyWrite)
                                sDenyRight += "item:write|";

                            if ((CopyFrom.Roles[t].AccessRight & AccessRights.DenyCreate) == AccessRights.DenyCreate)
                                sDenyRight += "item:create|";

                            if ((CopyFrom.Roles[t].AccessRight & AccessRights.DenyDelete) == AccessRights.DenyDelete)
                                sDenyRight += "item:delete|";

                            if ((CopyFrom.Roles[t].AccessRight & AccessRights.DenyRename) == AccessRights.DenyRename)
                                sDenyRight += "item:rename|";

                            if ((CopyFrom.Roles[t].AccessRight & AccessRights.DenyAdminister) == AccessRights.DenyAdminister)
                                sDenyRight += "item:admin|";

                            // Get existing rights and subtract them from the ones we want to set
                            if (! this.Options.SetItemRightsExplicitly)
                            {
                                string sExistingRights = ExtendedWebService.GetRight(Util.CurrentDatabase, returnItem.ID, CopyFrom.Roles[t].Name,
                                                            CMSConverter.Core.ExtendedSitecoreAPI.SecurityPermission.AllowAccess, credential);
                                sRight = Util.SubtractRights(sExistingRights, sRight);

                                string sExistingDenyRights = ExtendedWebService.GetRight(Util.CurrentDatabase, returnItem.ID, CopyFrom.Roles[t].Name,
                                                            CMSConverter.Core.ExtendedSitecoreAPI.SecurityPermission.DenyAccess, credential);
                                sDenyRight = Util.SubtractRights(sExistingDenyRights, sDenyRight);
                            }

                            // This is a user
                            if (CopyFrom.Roles[t].UserSettings.Count > 0)
                            {
                                bool bIsAdmin = false;
                                if (CopyFrom.Roles[t].UserSettings["IsAdmin"].ToLower() == "true")
                                    bIsAdmin = true;

                                ExtendedWebService.CreateUser(
                                            CopyFrom.Roles[t].Name,
                                            CopyFrom.Roles[t].UserSettings["PassWord"],
                                            CopyFrom.Roles[t].UserSettings["Email"],
                                            CopyFrom.Roles[t].UserSettings["FullName"],
                                            CopyFrom.Roles[t].UserSettings["Roles"],
                                            bIsAdmin,
                                            credential);
                            }
                            // This is a role
                            else
                            {
                                ExtendedWebService.CreateRole(sRole, credential);
                                // This role should inherit from another rootrole
                                if ((!_roleNames.ContainsKey(sRole)) && (this.Options.RootRole != ""))
                                {
                                    string sRootRole = this.Options.RootRole;
                                    if (this.Options.DefaultSecurityDomain != "")
                                        sRootRole = this.Options.DefaultSecurityDomain + "\\" + sRootRole;
                                    ExtendedWebService.AddRoleToRole(sRole, sRootRole, credential);

                                    _roleNames.Add(sRole, sRole);
                                }
                            }

                            // We also need to set rights
                            if (sRight != "")
                            {
                                ExtendedWebService.SetRight(Util.CurrentDatabase,
                                            returnItem.ID, sRole, sRight,
                                            CMSConverter.Core.ExtendedSitecoreAPI.AccessPermission.Allow,
                                            CMSConverter.Core.ExtendedSitecoreAPI.PropagationType.Any,
                                            credential);
                            }
                            if (sDenyRight != "")
                            {
                                ExtendedWebService.SetRight(Util.CurrentDatabase,
                                            returnItem.ID, sRole, sDenyRight,
                                            CMSConverter.Core.ExtendedSitecoreAPI.AccessPermission.Deny,
                                            CMSConverter.Core.ExtendedSitecoreAPI.PropagationType.Any,
                                            credential);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        this.Options.CopySecuritySettings = false;
                        Util.AddWarning("An exception occured while transferring security settings, copying security is now disabled.");
                        Util.AddWarning("The security exception was: " + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return returnItem;
        }
Ejemplo n.º 5
0
 public string GetRight(string strDatabase, string strItem, string strAccount, SecurityPermission rightState, Credentials credentials) {
     object[] results = this.Invoke("GetRight", new object[] {
                 strDatabase,
                 strItem,
                 strAccount,
                 rightState,
                 credentials});
     return ((string)(results[0]));
 }
Ejemplo n.º 6
0
 /// <remarks/>
 public void GetRightAsync(string strDatabase, string strItem, string strAccount, SecurityPermission rightState, Credentials credentials, object userState) {
     if ((this.GetRightOperationCompleted == null)) {
         this.GetRightOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRightOperationCompleted);
     }
     this.InvokeAsync("GetRight", new object[] {
                 strDatabase,
                 strItem,
                 strAccount,
                 rightState,
                 credentials}, this.GetRightOperationCompleted, userState);
 }
Ejemplo n.º 7
0
 /// <remarks/>
 public void GetRolesAsync(Credentials credentials, object userState) {
     if ((this.GetRolesOperationCompleted == null)) {
         this.GetRolesOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRolesOperationCompleted);
     }
     this.InvokeAsync("GetRoles", new object[] {
                 credentials}, this.GetRolesOperationCompleted, userState);
 }
Ejemplo n.º 8
0
 /// <remarks/>
 public void SetRightAsync(string strDatabase, string strItem, string strAccount, string strRights, AccessPermission rightState, PropagationType propagationType, Credentials credentials) {
     this.SetRightAsync(strDatabase, strItem, strAccount, strRights, rightState, propagationType, credentials, null);
 }
Ejemplo n.º 9
0
 public string[] GetRoles(Credentials credentials) {
     object[] results = this.Invoke("GetRoles", new object[] {
                 credentials});
     return ((string[])(results[0]));
 }
Ejemplo n.º 10
0
 /// <remarks/>
 public void GetRolesAsync(Credentials credentials) {
     this.GetRolesAsync(credentials, null);
 }
Ejemplo n.º 11
0
 /// <remarks/>
 public void CreateUserAsync(string sDomainUser, string sPassword, string sEmail, string sFullName, string sRoles, bool bIsAdmin, Credentials credentials, object userState) {
     if ((this.CreateUserOperationCompleted == null)) {
         this.CreateUserOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateUserOperationCompleted);
     }
     this.InvokeAsync("CreateUser", new object[] {
                 sDomainUser,
                 sPassword,
                 sEmail,
                 sFullName,
                 sRoles,
                 bIsAdmin,
                 credentials}, this.CreateUserOperationCompleted, userState);
 }
Ejemplo n.º 12
0
 /// <remarks/>
 public void CreateUserAsync(string sDomainUser, string sPassword, string sEmail, string sFullName, string sRoles, bool bIsAdmin, Credentials credentials) {
     this.CreateUserAsync(sDomainUser, sPassword, sEmail, sFullName, sRoles, bIsAdmin, credentials, null);
 }
Ejemplo n.º 13
0
 public bool CreateUser(string sDomainUser, string sPassword, string sEmail, string sFullName, string sRoles, bool bIsAdmin, Credentials credentials) {
     object[] results = this.Invoke("CreateUser", new object[] {
                 sDomainUser,
                 sPassword,
                 sEmail,
                 sFullName,
                 sRoles,
                 bIsAdmin,
                 credentials});
     return ((bool)(results[0]));
 }
Ejemplo n.º 14
0
 /// <remarks/>
 public void DeleteUsersAsync(string sDomainUsers, Credentials credentials, object userState) {
     if ((this.DeleteUsersOperationCompleted == null)) {
         this.DeleteUsersOperationCompleted = new System.Threading.SendOrPostCallback(this.OnDeleteUsersOperationCompleted);
     }
     this.InvokeAsync("DeleteUsers", new object[] {
                 sDomainUsers,
                 credentials}, this.DeleteUsersOperationCompleted, userState);
 }
Ejemplo n.º 15
0
 public bool AddRoleToRole(string sDomainRole, string sTargetRole, Credentials credentials) {
     object[] results = this.Invoke("AddRoleToRole", new object[] {
                 sDomainRole,
                 sTargetRole,
                 credentials});
     return ((bool)(results[0]));
 }
Ejemplo n.º 16
0
 public void SetRight(string strDatabase, string strItem, string strAccount, string strRights, AccessPermission rightState, PropagationType propagationType, Credentials credentials) {
     this.Invoke("SetRight", new object[] {
                 strDatabase,
                 strItem,
                 strAccount,
                 strRights,
                 rightState,
                 propagationType,
                 credentials});
 }
Ejemplo n.º 17
0
 /// <remarks/>
 public void AddRoleToRoleAsync(string sDomainRole, string sTargetRole, Credentials credentials) {
     this.AddRoleToRoleAsync(sDomainRole, sTargetRole, credentials, null);
 }
Ejemplo n.º 18
0
 /// <remarks/>
 public void SetRightAsync(string strDatabase, string strItem, string strAccount, string strRights, AccessPermission rightState, PropagationType propagationType, Credentials credentials, object userState) {
     if ((this.SetRightOperationCompleted == null)) {
         this.SetRightOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSetRightOperationCompleted);
     }
     this.InvokeAsync("SetRight", new object[] {
                 strDatabase,
                 strItem,
                 strAccount,
                 strRights,
                 rightState,
                 propagationType,
                 credentials}, this.SetRightOperationCompleted, userState);
 }
Ejemplo n.º 19
0
 /// <remarks/>
 public void AddRoleToRoleAsync(string sDomainRole, string sTargetRole, Credentials credentials, object userState) {
     if ((this.AddRoleToRoleOperationCompleted == null)) {
         this.AddRoleToRoleOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAddRoleToRoleOperationCompleted);
     }
     this.InvokeAsync("AddRoleToRole", new object[] {
                 sDomainRole,
                 sTargetRole,
                 credentials}, this.AddRoleToRoleOperationCompleted, userState);
 }
Ejemplo n.º 20
0
 /// <remarks/>
 public void GetRightAsync(string strDatabase, string strItem, string strAccount, SecurityPermission rightState, Credentials credentials) {
     this.GetRightAsync(strDatabase, strItem, strAccount, rightState, credentials, null);
 }
Ejemplo n.º 21
0
 public bool DeleteRole(string sDomainRole, Credentials credentials) {
     object[] results = this.Invoke("DeleteRole", new object[] {
                 sDomainRole,
                 credentials});
     return ((bool)(results[0]));
 }
Ejemplo n.º 22
0
 public string CreateStandardValues(string strItem, Credentials credentials) {
     object[] results = this.Invoke("CreateStandardValues", new object[] {
                 strItem,
                 credentials});
     return ((string)(results[0]));
 }
Ejemplo n.º 23
0
 /// <remarks/>
 public void DeleteRoleAsync(string sDomainRole, Credentials credentials) {
     this.DeleteRoleAsync(sDomainRole, credentials, null);
 }
Ejemplo n.º 24
0
 /// <remarks/>
 public void CreateStandardValuesAsync(string strItem, Credentials credentials, object userState) {
     if ((this.CreateStandardValuesOperationCompleted == null)) {
         this.CreateStandardValuesOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateStandardValuesOperationCompleted);
     }
     this.InvokeAsync("CreateStandardValues", new object[] {
                 strItem,
                 credentials}, this.CreateStandardValuesOperationCompleted, userState);
 }
Ejemplo n.º 25
0
        private string CreateTemplate(IItem fromTemplate, string sTemplatePath, string sInheritedTemplateIDs)
        {
            Sitecore6xItem templateItem = GetSitecore61Item(sTemplatePath);
            if (templateItem == null)
            {
                if (sTemplatePath.ToLower().IndexOf("/sitecore/templates/system/") > -1)
                    throw new Exception("'/sitecore/templates/system/xxx' templates must not be written to! This template path is: " + sTemplatePath);

                // Create new template
                if (fromTemplate.ID == this.BaseTemplate.ID)
                    // Never create a template with the same id as the base template, as this will cause the "standard template" to be overwritten
                    sTemplatePath = CreateTemplateItemWithSpecificID(fromTemplate.Path.Remove(fromTemplate.Path.LastIndexOf("/") + 1), "/sitecore/templates/System/Templates/Template", "", fromTemplate.Name);
                else
                {
                    if (CREATE_NEW_BASE_TEMPLATE)
                        sTemplatePath = CreateTemplateItemWithSpecificID(TEMPLATE_IMPORT_FOLDER, "/sitecore/templates/System/Templates/Template", fromTemplate.ID, fromTemplate.Name);
                    else
                    {
                        string sFolder = fromTemplate.Path.Remove(fromTemplate.Path.LastIndexOf("/") + 1);
                        Sitecore6xItem folderItem = GetSitecore61Item(sFolder);
                        // Folders to the template are missing
                        if (folderItem == null)
                        {
                            if (sFolder.IndexOf("/sitecore/templates/") == -1)
                                throw new Exception("Error template source path not in /sitecore/templates/, the illegal path was:" + sFolder);
                            // Create all missing template folders
                            string sTempName = sFolder.Remove( 0, "/sitecore/templates/".Length);
                            string sMissingFolder = "/sitecore/templates/";
                            while (sTempName != "")
                            {
                                string sMissingFolderName = sTempName.Remove(sTempName.IndexOf("/"), sTempName.Length - sTempName.IndexOf("/"));
                                folderItem = GetSitecore61Item(sMissingFolder + sMissingFolderName);
                                if (folderItem == null)
                                    CreateTemplate(sMissingFolder, "/sitecore/templates/System/Templates/Template Folder", sMissingFolderName);

                                sMissingFolder = sMissingFolder + sMissingFolderName + "/";
                                sTempName = sTempName.Remove(0, sTempName.IndexOf("/") + 1);
                            }
                        }
                        sTemplatePath = CreateTemplateItemWithSpecificID(fromTemplate.Path.Remove(fromTemplate.Path.LastIndexOf("/") + 1), "/sitecore/templates/System/Templates/Template", fromTemplate.ID, fromTemplate.Name);
                    }
                }

                // Get new templateItem
                templateItem = GetSitecore61Item(sTemplatePath);

                // Add icon path
                AddFieldFromTemplate(templateItem, "/sitecore/templates/System/Templates/Sections/Appearance/Appearance/__Icon", fromTemplate.Icon);

                // Change template inheritance - MUST BE AFTER ADDING FIELD VALUES OTHERWISE IT DOESN'T WORK
                if (sInheritedTemplateIDs != "")
                    templateItem._fields.Add(new Sitecore6xField("__base template", "__base template", "tree list", new Guid("{12C33F3F-86C5-43A5-AEB4-5598CEC45116}"), sInheritedTemplateIDs, null, ""));

                templateItem.Save(templateItem.Fields, this.Options.Language, "1");

                // Create all template fields
                foreach (IField field in fromTemplate.Fields)
                {
                    // It is better to check for missing fields using id, because then it will also be found even if it is placed elsewhere
                    if (! Util.IsTemplateFieldOnIgnoreList(field.TemplateFieldID.ToString()) &&
                       (GetItem(field.TemplateFieldID) == null))
                        AddTemplateField(sTemplatePath, field);
                }

                // Create standard values
                if (templateItem.Path.IndexOf("/sitecore/templates/System") == -1)
                {
                    bool bContainsStandardValues = false;
                    foreach (IField field in fromTemplate.Fields)
                    {
                        if (field.Content != "")
                            bContainsStandardValues = true;
                    }
                    if (bContainsStandardValues)
                    {
                        ExtendedSitecoreAPI.Credentials credential = new ExtendedSitecoreAPI.Credentials();
                        credential.UserName = _credentials.UserName;
                        credential.Password = _credentials.Password;
                        try
                        {
                            string sID = ExtendedWebService.CreateStandardValues(templateItem.ID, credential);

                            Sitecore6xItem standardValuesItem = templateItem.GetSitecore61Item(sID);
                            //                Sitecore6xItem standardValuesItem = templateItem.GetSitecore61Item(templateItem.Path + "/__Standard Values");
                            // standardValuesItem = CreateItem(templateItem.Path, Util.GuidToSitecoreID(templateItem.ID), "__Standard Values");
                            CheckSitecoreReturnValue(_sitecoreApi.AddVersion(
                                            standardValuesItem.ID, this.Options.Language, Util.CurrentDatabase, _credentials));
                            standardValuesItem.Save(fromTemplate.Fields, this.Options.Language, "1.0");
                        }
                        catch (Exception ex)
                        {
                            Util.AddWarning("Standard values exception in Sitecore6xItem: " + ex.Message + "\n" + ex.StackTrace);
                        }
                    }
                }

                // Set sortorder on sections
                {
                    int t = 10;
                    // Basetemplate section sortorder begins from 1000
                    if ((fromTemplate.BaseTemplate != null) && (templateItem.Key == fromTemplate.BaseTemplate.Key))
                        t = 1000;
                    IItem[] childSections = templateItem.GetChildren();
                    foreach (IItem section in childSections)
                    {
                        if (section.Templates[0] == null)
                            continue;

                        if (section.Templates[0].Key == "template section")
                        {
                            if (section.SortOrder != t.ToString())
                            {
                                section.SortOrder = t.ToString();
                                section.Save();
                            }
                            // Basetemplate section sortorder is increased by 1000
                            if ((fromTemplate.BaseTemplate != null) && (templateItem.Key == fromTemplate.BaseTemplate.Key))
                                t += 1000;
                            else
                                t += 10;
                        }
                    }
                }

                // Call plugins and update user interface
                if (this.Options.CopyItem != null)
                {
                    //                    templateItem = GetSitecore61Item(sTemplatePath);
                    this.Options.CopyItem(fromTemplate, templateItem.Parent, templateItem);
                    templateItem.Save();
                }
            }
            // Template already exists, but it is not in the cache
            else if (!_Options.ExistingTemplates.ContainsKey(templateItem.ID.ToLower()))
            {
                // Does all the fields exist?
                foreach (IField field in fromTemplate.Fields)
                {
                    // A new field exists
                    if (Util.GetFieldByID(field.TemplateFieldID, templateItem.Fields) == null)
                    {
                        // Create and add it to the template
                        if (! Util.IsTemplateFieldOnIgnoreList(field.TemplateFieldID) &&
                           (GetItem(field.TemplateFieldID) == null))
                        {
                            AddTemplateField(templateItem.Path, field);
                            Util.AddWarning("Added new field to template: " + templateItem.Path + "\nField name:" + field.Name);
                        }
                    }
                }
            }
            // Always cache the template
            AddItemToCache(templateItem);

            return sTemplatePath;
        }