Create linked document

[C#]

 

using CMS.SettingsProvider;

using CMS.CMSHelper;

using CMS.DataEngine;

using CMS.GlobalHelper;

using CMS.TreeEngine;

using CMS.SiteProvider;

 

...

 

           // Prepare the TreeProvider

           // it must be initialized with user information when editing document structure

           UserInfo ui = UserInfoProvider.GetUserInfo("administrator");

           TreeProvider tree = new TreeProvider(ui);

          

           // Get the document (current culture)

           CMS.TreeEngine.TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/TestingNews", CMSContext.CurrentUser.PreferredCultureCode, false, null, false);

           if (node != null)

           {

               // Update the data

               node.SetValue("NodeAlias", "TestingNewsLink");

              

               // Insert new culture version of the document in the same site section

               node.InsertAsLink(node.NodeParentID);

 

               this.lblInfo.Text = "New link '" + node.NodeAliasPath + "' to the document '/TestingNews' has been created.";

           }