create blog post from API

Posted by Community Admin on 03-Aug-2018 11:52

create blog post from API

All Replies

Posted by Community Admin on 09-Feb-2011 00:00

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

Posted by Community Admin on 09-Feb-2011 00:00

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

Posted by Community Admin on 09-Feb-2011 00:00

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();

Posted by Community Admin on 09-Feb-2011 00:00

Hi

Some one help me please.

Posted by Community Admin on 09-Feb-2011 00:00

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

Posted by Community Admin on 09-Feb-2011 00:00

thank you very much its working.

Posted by Community Admin on 09-Feb-2011 00:00

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

Posted by Community Admin on 09-Feb-2011 00:00

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

Posted by Community Admin on 09-Feb-2011 00:00

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

Posted by Community Admin on 09-Feb-2011 00:00

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

Posted by Community Admin on 24-May-2011 00:00

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();

Posted by Community Admin on 24-May-2011 00:00

Ah, nevermind, I forgot the .Publish() before .SaveChanges()
Ryan

Posted by Community Admin on 29-Sep-2011 00:00

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.

Posted by Community Admin on 30-Sep-2011 00:00

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

Posted by Community Admin on 28-Feb-2012 00:00

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

Posted by Community Admin on 01-Mar-2012 00:00

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

Posted by Community Admin on 01-Mar-2012 00:00

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

Posted by Community Admin on 02-Mar-2012 00:00

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

This thread is closed