A first chance exception of type 'System.NullReferenceException' occurred in CMS.GlobalHelper.dll error when it gets to this line in the code // Save to database
node.Update();
All other lines in the code contain values. The code needs to update a NodeAliasPath on one of the pages. // Create an instance of the Tree provider first
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
//Gets all the nodes that have the node alias path of Dinning-Commons
var nodes = tree.SelectNodes("SietName", "%contains part of nodealispath%", "en-us", false);
if (nodes != null)
{
// Loop through all documents
foreach (TreeNode node in nodes)
{
Console.WriteLine("NodeAliasPath before change " + node.NodeAliasPath);
file.WriteLine(" ");
file.WriteLine("NodeAliasPath before change " + node.NodeAliasPath);
Console.WriteLine(" ");
file.WriteLine(" ");
String newNodeAliasPath = node.NodeAliasPath.Replace("old node alias path", "new node alias path);
//Set the value this way
bool returnNodeValue = node.SetValue("NodeAliasPath", newNodeAliasPath);
Console.WriteLine(" returnNodeValue " + returnNodeValue);
//Or set value thos way
Console.WriteLine(" return value from Set Value -- NodeAlias Path " + node.SetValue("NodeAliasPath", newNodeAliasPath));
Console.WriteLine(" __________________________ ");
file.WriteLine(" return value from Set Value -- NodeAlias Path " + node.SetValue("NodeAliasPath", newNodeAliasPath));
file.WriteLine(" __________________________ ");
// Save to database----NULL REFERNCE IN CMSHELPER.DLL Here. Code hangs
node.Update();
↧