Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • MirkoMaty 4 posts 24 karma points
    Jul 10, 2012 @ 14:32
    MirkoMaty
    0

    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?

     

  • Douglas Ludlow 210 posts 366 karma points
    Jul 10, 2012 @ 15:47
    Douglas Ludlow
    0

    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

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Jul 10, 2012 @ 16:44
    Richard Soeteman
    0

    Hi,

    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/

    Hope this helps you,

    Richard

     

  • MirkoMaty 4 posts 24 karma points
    Jul 10, 2012 @ 16:53
    MirkoMaty
    0

    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 

  • MirkoMaty 4 posts 24 karma points
    Jul 10, 2012 @ 17:34
    MirkoMaty
    0

    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: 

    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 

  • Douglas Ludlow 210 posts 366 karma points
    Jul 10, 2012 @ 17:42
    Douglas Ludlow
    0

    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:

    [RestExtension( "MatyMaintenance" )]
    public class MaintenanceClass
    {
    [RestExtensionMethod(allowAll=true)]
    public static string UpdateDocuments()
    {
    // Updating the documents
    }
    }
  • MirkoMaty 4 posts 24 karma points
    Jul 10, 2012 @ 17:50
    MirkoMaty
    0

    Thanks a lot! The /base in the url did the trick.

    If you ever come to Freising, you'll get some beer... ;-) 

    Mirko 

     

  • Douglas Ludlow 210 posts 366 karma points
    Jul 10, 2012 @ 17:57
    Douglas Ludlow
    0

    Glad I could help! Feel free to mark the topic as answered.

Please Sign in or register to post replies

Write your reply to:

Draft