I need to programmatically add documents in Umbraco. There is a process which updates the documents in certain intervals according to data residing on another machine.
I found these two links, which work well in a user control:
The downside of this approach is, that I need to have a dummy maintainence page containing a user control with the code in the PageLoad event. The above mentioned process fetches the maintainence page using an HttpRequest and that way runs the code of the user control.
Is there a way to work with the Api directly, i.e. without placing a user control in some page, of which the customer doesn't have any glue, why it exists?
You've got a couple of choices. You can either a.) Hookup to the Umbraco events (on publish, on save, on delete, etc.), or b.) create a /base rest extension that will allow you to call your method by going to http://yourdomain.com/base/yourAlias/yourMethod/.
Using subscribing to Umbraco's events may not be what you'd need, especially if you want to run your maintenance at a specific time each day. But here's a few links showing what events are available and how you'd go about using them:
Umbraco base would be the best choice if you are wanting to schedule your maintenance to run at specific times. After you build a base class you can set it to run at intervals using Umbraco's scheduled tasks. There's event a nice package that allows you to manage the scheduled tasks, called TaskScheduler. Here are some links:
Not to plug CMSImport too much but it's exactly what you are after:
Import documents from a different location based on various datasources.
Update documents
Schedule import definitions
Only downside is that the update and schedule feature isn't included into the free edition. You might want to check out the free edition and video's on http://cmsimport.com/
It seems as if /Base is exactly what I'm searching for - it doesn't appear in the backend. I'll test this solution later and let you know, if it worked.
I tried to apply the base sample and used the following code:
[RestExtension( "MatyMaintenance" )] public class MaintenanceClass { [RestExtensionMethod()] public static string UpdateDocuments() { // Updating the documents } }
I wanted to start the code with showing the page in the browser:
But it shows me a 404. Do I need to install or configure something? The article about /Base says, that umbraco finds the extension automatically, if it is marked with the custom attributes.
Also, if you get permission errors you may want to add allowAll=true to the RestExtensionMethod annotation:
[RestExtension( "MatyMaintenance" )] public class MaintenanceClass { [RestExtensionMethod(allowAll=true)] public static string UpdateDocuments() { // Updating the documents } }
Programmatically add documents
I need to programmatically add documents in Umbraco. There is a process which updates the documents in certain intervals according to data residing on another machine.
I found these two links, which work well in a user control:
http://en.wikibooks.org/wiki/Umbraco/Samples_and_Articles/Creating_umbraco_pages_programmatically
http://our.umbraco.org/forum/developers/api-questions/3477-Creating-Media-Programatically
The downside of this approach is, that I need to have a dummy maintainence page containing a user control with the code in the PageLoad event. The above mentioned process fetches the maintainence page using an HttpRequest and that way runs the code of the user control.
Is there a way to work with the Api directly, i.e. without placing a user control in some page, of which the customer doesn't have any glue, why it exists?
You've got a couple of choices. You can either a.) Hookup to the Umbraco events (on publish, on save, on delete, etc.), or b.) create a /base rest extension that will allow you to call your method by going to http://yourdomain.com/base/yourAlias/yourMethod/.
Using subscribing to Umbraco's events may not be what you'd need, especially if you want to run your maintenance at a specific time each day. But here's a few links showing what events are available and how you'd go about using them:
Overview of all events
Event Examples
Umbraco base would be the best choice if you are wanting to schedule your maintenance to run at specific times. After you build a base class you can set it to run at intervals using Umbraco's scheduled tasks. There's event a nice package that allows you to manage the scheduled tasks, called TaskScheduler. Here are some links:
Umbraco /Base
Simple /base examples
Returning Json instead of XML with Umbraco Base
Hi,
Not to plug CMSImport too much but it's exactly what you are after:
Only downside is that the update and schedule feature isn't included into the free edition. You might want to check out the free edition and video's on http://cmsimport.com/
Hope this helps you,
Richard
It seems as if /Base is exactly what I'm searching for - it doesn't appear in the backend. I'll test this solution later and let you know, if it worked.
Thanks a lot for your answers.
Mirko
I tried to apply the base sample and used the following code:
I wanted to start the code with showing the page in the browser:
http://localhost:33621/MatyMaintenance/UpdateDocuments
But it shows me a 404. Do I need to install or configure something? The article about /Base says, that umbraco finds the extension automatically, if it is marked with the custom attributes.
Thanks in advance
Mirko
You'll need to add /base to the url:
http://localhost:33621/base/MatyMaintenance/UpdateDocuments
Also, if you get permission errors you may want to add allowAll=true to the RestExtensionMethod annotation:
Thanks a lot! The /base in the url did the trick.
If you ever come to Freising, you'll get some beer... ;-)
Mirko
Glad I could help! Feel free to mark the topic as answered.
is working on a reply...