I am having a hard time updating a node and make the changes reflect on the site. When i only call node.Save(), the changes isn't reflected on the site as expected. If i look in the backoffice, the nodes appears as unpublished (or at least have a unpublished version). So i want the changes to go live immediately. Therefore i called node.SaveAndPublish(new User(0)) instead. Now when i look in the backoffice, there is no unpublished version. However the changes to the node isn't published. It's first when i press the publish-button in the backoffice as the changes actually go live, even though the node appeared as published.
Is this a bug in the API or what? How do i solve this?
public static string Set()
{
string state = HttpContext.Current.Request["a"];
string ev = HttpContext.Current.Request["e"];
if ((state == "true" || state == "false") && ev.Length >= 4)
{
Member m = Member.GetCurrentMember();
var node = new Document(Convert.ToInt16(ev));
if (node == null)
return "error";
else
{
var users = (from p in node.getProperty("guests").Value.ToString().Split(',')
where p != m.Id.ToString()
select p).ToList();
if (state == "true" && !users.Contains(m.Id.ToString()))
{
users.Add(m.Id.ToString());
}
else if (state == "false")
{
users = (from p in users
where p != m.Id.ToString()
select p).ToList();
}
node.getProperty("guests").Value = String.Join(",", users);
node.SaveAndPublish(new User(0));
return "success";
}
}
else
return "error";
}
//Get the document
var doc = new Document(1234);
//create and store a xml representation of the document
doc.Publish(user);
//tell the runtime to retrieve the xml from the database and store in cache
umbraco.library.UpdateDocumentCache(doc.Id);
I should add that if you were to use the v6 API (rather than the v4 API) then you don't need to worry about flushing the cache (a great improvement). v6 API ContentService documentation is available here
SaveAndPublish doesn't work
I am having a hard time updating a node and make the changes reflect on the site. When i only call node.Save(), the changes isn't reflected on the site as expected. If i look in the backoffice, the nodes appears as unpublished (or at least have a unpublished version). So i want the changes to go live immediately. Therefore i called node.SaveAndPublish(new User(0)) instead. Now when i look in the backoffice, there is no unpublished version. However the changes to the node isn't published. It's first when i press the publish-button in the backoffice as the changes actually go live, even though the node appeared as published.
Is this a bug in the API or what? How do i solve this?
Hi Anton,
Can I ask what version of Umbraco are you using as there have been quite a few changes to this method depending on version?
Thanks,
Jeavon
Hi Jeavon,
Thank you for your reply.
The version is 6.0.5.
Ok, I think you just need to clear the cache after calling SaveAndPublish,
Below is snippet from the documentation for the Publish method but it should be the same
See if that works for you?
I should add that if you were to use the v6 API (rather than the v4 API) then you don't need to worry about flushing the cache (a great improvement). v6 API ContentService documentation is available here
is working on a reply...