Can I start by saying I am using Umbraco version 4.0.2.1? I am using the following C# code in a user control to create new Document:
DocumentType docType = DocumentType.GetByAlias("MyDocType");
User oneUser = User.GetUser(0); // Hard reference to Administrator user
int currentNodeId = umbraco.presentation.UmbracoContext.Current.PageId.Value;
if ((My_TextBox.Text).Length > 0)
{
Document doc = Document.MakeNew("MyName", docType, oneUser, currentNodeId);
doc.getProperty("textBoxName").Value = My_TextBox.Text;
doc.Publish(oneUser);
umbraco.library.UpdateDocumentCache(docType.Id);
}
This code works - almost. It certainly creates the new document in Umbraco, and it publishes it (I think!), by virtue of it shows up as published. One important thing to note that "Link to document" has no value! There are two things I can do:
1. From the Umbraco back-end, I click the "Save and Publish" button. This finally gives value to "Link to document", and it is definitely published. OR
2. From the Content node, select "Reload nodes", then also select "Republish entire site". This rebuilds the sitemap, and now the newly created documents have a link, and they are published.
Obviously, it would be very nice to not have to manually do this every time. Does anybody tell me what the answers to the following questions?
1. If I upgrade to 4.0.3, will this solution be resolved?
2. Is there a way to ask Umbraco to "Reload nodes" and "Republish entire site" from C#?
Thank you everybody for your hard work on Umbraco! We think it a very worthy application, and we like that it is free for everybody!
Hello! Yes, that worked. I can see that the DocumentCache update requires the Document id, and not the DocumentType Id. Thanks to you so much for the reply!!
Document.Publish
Can I start by saying I am using Umbraco version 4.0.2.1? I am using the following C# code in a user control to create new Document:
Hi Genna,
I think I've spotted a typo. For the call to "UpdateDocumentCache()" try "doc.Id" instead of "docType.Id"?
Cheers, Lee.
Hello! Yes, that worked. I can see that the DocumentCache update requires the Document id, and not the DocumentType Id. Thanks to you so much for the reply!!
is working on a reply...