create blog post from API
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
Hi Jmr,
Try setting bP.AutoGenerateUniqueUrl = true;
Kind regards,
Ivan Dimitrov
the Telerik team
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();
Hi
Some one help me please.
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
thank you very much its working.
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
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
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
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
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();
Ah, nevermind, I forgot the .Publish() before .SaveChanges()
Ryan
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();
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
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
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
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
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