1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / create blog post from API

create blog post from API

18 posts, 1 answered
  1. Jmr
    Jmr avatar
    53 posts
    Registered:
    21 Jan 2011
    09 Feb 2011
    Link to this post
    Hi

    i try to create using the below code it is working fine first time if no blogpost available.then i try to create blog post second time it shows error(Telerik.Sitefinity.Utilities.MS.ServiceModel.Web.WebProtocolException: An item with the URL '/blogPostTitle/2011/02/09/' already exists.) .

    CODE
    --------

    Guid DynamicGuid = Guid.NewGuid();
    App.WorkWith()
                   .Blog(parentID)
                   .CreateBlogPost()
                        .Do(bP =>
                        {
                            bP.Title = blogPostTitle + DynamicGuid.ToString();
                            bP.Content = content;
                            bP.Description = description;
                            bP.DateCreated = DateTime.Today;
                            bP.PublicationDate = DateTime.UtcNow;
                        })
                    .Publish() 
                    .SaveChanges();

    please let me know the solution
    thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Feb 2011
    Link to this post
    Hi Jmr,

    Try setting bP.AutoGenerateUniqueUrl = true;

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Jmr
    Jmr avatar
    53 posts
    Registered:
    21 Jan 2011
    09 Feb 2011
    Link to this post
    Thanks for Quick reply,

    if i do like that it shows me : cannot be assigned to -- it is read only.

    please explain me more may be i placed wrong place.

    App.WorkWith()
                   .Blog(parentID)
                   .CreateBlogPost()              
                        .Do(bP =>
                        {
                            bP.AutoGenerateUniqueUrl = true;  // cannot be assigned to -- it is read only.
                            bP.Title = sblogPostTitle + gDynamicGuid.ToString();
                            bP.Content = scontent;
                            bP.Description = sdescription;
                            bP.DateCreated = DateTime.Today;
                            bP.PublicationDate = DateTime.UtcNow;
                            bP.ExpirationDate = DateTime.Today.AddDays(200);    
                        })
                    .Publish() 
                    .SaveChanges();
  4. Jmr
    Jmr avatar
    53 posts
    Registered:
    21 Jan 2011
    09 Feb 2011
    Link to this post
    Hi

    Some one help me please.
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Feb 2011
    Link to this post
    Hi Jmr,

    You have to use the code below. You should set the parent inside the Do. There is a bug in the method you use

    var parentID = new Guid("2230ac16-4cd1-4e8f-b45b-51ac13c7c968");
               var fluent = App.WorkWith();
               Guid DynamicGuid = Guid.NewGuid();
               var blog = fluent.Blog(parentID)
                                         .Get();
                  fluent.BlogPost().CreateNew()
                                           .Do(bp =>
                                               {
                                                   bp.Parent = blog;
                                                   bp.Title = DynamicGuid.ToString();
                                                   bp.Content = "somecontent";
                                                   bp.Description = "somedesc";
                                                   bp.DateCreated = DateTime.UtcNow;
                                                   bp.PublicationDate = DateTime.UtcNow.AddDays(10);
                                               })
                                               .SaveChanges();


    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  6. Jmr
    Jmr avatar
    53 posts
    Registered:
    21 Jan 2011
    09 Feb 2011
    Link to this post
    thank you very much its working.
  7. Jmr
    Jmr avatar
    53 posts
    Registered:
    21 Jan 2011
    09 Feb 2011
    Link to this post
    Hi Ivan Dimitrov,

    Using fluent API 
    1) how do i set create permission (New Blog Post and New Blog) to Everyone.
    2) Is there any possible to add more colums in blog.if so please provide us API

    Thanks
    jmr
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Feb 2011
    Link to this post
    Hi Jmr,

    1. The blog post is ISecurdObject, so you can call GrantActions and Permissions.Add. Please check Permissions section from our dev manual.

    2. Owner is a property of BlogPost, so you can use an EVAL to display it.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Jmr
    Jmr avatar
    53 posts
    Registered:
    21 Jan 2011
    09 Feb 2011
    Link to this post
    Hi Ivan Dimitrov,
    yes dev manual veru usefull.
    now

    Using fluent API 
    Is there any possible to add more colums in blog.if so please provide us API

    Thanks
    jmr
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Feb 2011
    Link to this post
    Hi Jmr,

    You can add additional columns from the UI - Sitefinity/Administration/Settings/Advanced

    Blogs >> Controls >> BackendViews >> blogsBackendList >> View Modes >> Grid >> Columns

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    24 May 2011
    Link to this post
    Hi
    I'm trying this method for adding Blog posts, and while they do get added to the database, they are not visible in the administration backend, nor on the blog front end page.

    var parentID = new Guid("79525FB5-AD2D-4931-9055-53382996F186");
    var fluent = App.WorkWith();
    Guid DynamicGuid = Guid.NewGuid();
    var blog = fluent.Blog(parentID)
                              .Get();
    fluent.BlogPost().CreateNew()
                             .Do(bp =>
                             {
                                 bp.Parent = blog;
                                 bp.Title = strTitle;
                                 bp.Description = strDescription;
                                 bp.Content = strBody;
                                 bp.DateCreated = dtDateCreated;
                                 bp.PublicationDate = dtDateCreated;
                                 bp.AllowComments = false;
                                 bp.ApproveComments = true;
                                 bp.AllowTrackBacks = true;
                                 bp.ContentState = "PUBLISHED";
                                 bp.Status = ContentLifecycleStatus.Live;
                                 bp.ApprovalWorkflowState = "Published";
                                 bp.Summary = strDescription;
                                 bp.PostRights = PostRights.None;
                      
                             })
                                 .SaveChanges();
  12. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    24 May 2011
    Link to this post
    Ah, nevermind, I forgot the .Publish() before .SaveChanges()
    Ryan
  13. waqar
    waqar avatar
    76 posts
    Registered:
    28 Mar 2011
    29 Sep 2011
    Link to this post
    HI evryone!

    I am running this code to change the publish date of the news more than 200.
    var newsAll = App.WorkWith()
    .NewsItems()
    // .Where(nI => nI.Status == ContentLifecycleStatus.Live)
    .ForEach(nI =>
    {
    var val = nI.GetValue("NewsDate").ToString();
    var ss = DateTime.Parse(val);
    nI.PublicationDate = ss;
    nI.DateCreated = ss;
    })
    .SaveAndContinue();


    but foreach loop I am getting following error
    " An item with the URL '/2011/09/09/-بنك-دبي-الإسلامي-و-الأردن-دبي-كابيتال-و-دبي-انترناشونال-' already exists."

    Can you please help me on this? I have more than 200 news I can't repopulate them.

    Please come up with some solution.
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    30 Sep 2011
    Link to this post
    Hi Waqar,

    Try using something like this and make sure that you are working with the latest SP of Sitefinity

    App.WorkWith().NewsItems().Where(ni => ni.Id == newsItemId).ForEach(ni =>
                                                                                    {
                                                                                        ni.LastModified = DateTime.Now;
                                                                                        ni.Author = NewsFluentApiTests.TestAuthorEdit;
                                                                                        ni.Content = NewsFluentApiTests.TestContentEdit;
                                                                                        ni.Title = "Editted news item";
                                                                                    }).SaveChanges();

    You can replace some of the variables with the relevant one from the main news object.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  15. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    28 Feb 2012
    Link to this post
    Is it also possible to change the 'LastModified' property?
    I want to initially change it to the 'PublicationDate'.

    I've migrated my blog from 3.7 to 4.4 but in the backend the posts are not sorted in any way, because of a DateTime min value inside the database.

    Regards,
    Daniel
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    01 Mar 2012
    Link to this post
    Hello,

    There shouldn't  be a problem. This is a property with getter and setter. We use it inside the migration tool.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  17. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    01 Mar 2012
    Link to this post
    That's what I thought, but it doesn't seem to have effect.
    It stays on 1-1-1001. I change the CreateDate and PublicationDate and that works well.

    Regards,
    Daniel
  18. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    02 Mar 2012
    Link to this post
    Hello,


    If you use the API you should be able to set it

    App.WorkWith().NewsItems().Where(ni => ni.Id == newsItemId).ForEach(ni =>
                                                                                    {
                                                                                        ni.LastModified = DateTime.Now;
                                                                                        ni.Author = "admin";
                                                                                        ni.Content = "content";
                                                                                        ni.Title = "Editted news item";
                                                                                    }).SaveChanges();

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
18 posts, 1 answered