Copied to clipboard

Flag this post as spam?

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


  • Adnan Inayat 28 posts 98 karma points
    Jul 09, 2017 @ 00:13
    Adnan Inayat
    0

    Hi all,

    I hope you all doing well.

    I am currently working to publish content via code.

    I want to know can I get the published url of content which is published via code using umbraco content service's 'SaveAndPublish' method?

    Thanks, Adnan

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Jul 09, 2017 @ 11:56
    Damiaan
    0

    Why would you need the url immediately? That sounds like a code smell...

    If you need it anyway, I guess the only way is to use the returned ID against some of the ContentCache helpers.

    var contentCache = UmbracoContext.Current.ContentCache;
    var content = contentCache.GetById(1234);
    

    However using this approach would need you to be sure the content cache has been updated.

    We don't know your exact use case, but my best guess is you probably need some of the ContentService Events.

    Kind regards
    Damiaan

  • Adnan Inayat 28 posts 98 karma points
    Jul 10, 2017 @ 04:47
    Adnan Inayat
    0

    Well actually I am allowing users to create events/programs by submitting a form.

    When a user submits a form I just published it on website (no need for admin approval) but I'll give admin an email that this(URL) event/program is published on website.

  • Adnan Inayat 28 posts 98 karma points
    Jul 10, 2017 @ 04:48
    Adnan Inayat
    0

    And I'll try your solution and will inform you ASAP :)

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Jul 10, 2017 @ 09:10
    Damiaan
    1

    If it's a public site, that might be a bad idea. Because a republish will trigger cache/xml file updates. If your site gets flooded with requests, it will go down quickly.

    One way to solve it, is keep items unpublished and let the admin publish the submission, the only link you need to add in your e-mail is a link to the backend page: http://yourdomainname.com/umbraco/#/content/content/edit/1262 (where the last number is the page id). You could even create an (public) API, allowing your users to publish the page with one button click in the e-mail (see UmbracoApiController). Be careful on your decision concerning security...

    Another way of solving this is pushing the data to an external database table and handle all things yourself. It is more scalable if you have LOTS of submissions but will require much more development. For a smaller site the first solution is probably enough.

    Kind regards
    Damiaan

  • Adnan Inayat 28 posts 98 karma points
    Jul 10, 2017 @ 18:32
    Adnan Inayat
    0

    I knew about first one...

    But never used the api to publish with external link. I was looking for properties of published content.

    By the way thank you soo much for your help @Damiaan :)

    Regards,

    Adnan Inayat

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Jul 10, 2017 @ 18:37
    Damiaan
    0

    Glad to help you.

    An UmbracoApiController has the same concept as WebApi in .Net. It is an easy way to expose data or to change data.

    If you have other questions, don't hesitate to post a question on the forum.

    Kind regards Damiaan

  • Phil Atkinson 51 posts 244 karma points
    Jul 11, 2017 @ 08:14
    Phil Atkinson
    0

    Here's shanon's public umbraco api to get you started: https://github.com/umbraco/UmbracoRestApi

Please Sign in or register to post replies

Write your reply to:

Draft