NewsManager , some question...
Hello,
I'm tring to use the newsmanager (since I need some user to write the news and the others only to read them)... I've written this test application :
NewsManager newsManager = new NewsManager();
NewsItem newsItem = newsManager.CreateNewsItem(Guid.NewGuid());
newsItem.ApplicationName = "/News";
newsItem.Content = "Test news";
newsItem.Author = "Paolo";
newsItem.Title = "Paolo's";
newsItem.Summary = "Prova inserimento url";
newsItem.UrlName.Value = "newsprovaurl";
newsItem.DateCreated = DateTime.Now.Date;
//newsItem.AutoGenerateUniqueUrl = true;
newsItem.AllowComments = false;
newsManager.RecompileItemUrls(newsItem);
newsManager.Publish(newsItem);
newsManager.SaveChanges();
e
AutoGenerateUniqueUrl
to true?The item does not have default url.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.InvalidDataException: The item does not have default url.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Hello Paolo,
Thank you for using our services.
The UrlName property needs to be set before you publish the item. you can try this code bellow:
public
void
CreateNews(
string
newsTitle,
string
newsContent,
string
author)
//Initializing the NewsManager with the default News provider
NewsManager manager = NewsManager.GetManager();
//creating a new news item
NewsItem item = manager.CreateNewsItem();
//setting the item's properties, content, etc.
item.Title = newsTitle;
item.Author = author;
item.Content = newsContent;
item.UrlName =
"native-api"
;
item.ApprovalWorkflowState =
"Published"
;
//generate URL and save changes
manager.RecompileItemUrls<NewsItem>(item);
//up to now, the item is in Draft State. We have to call Publish method to publish it.
item = manager.Publish(item);
manager.SaveChanges();
public
NewsItem CreateNewsItemFluent(
string
newsTitle,
string
newsContent,
string
author)
var item = App.WorkWith().NewsItem().CreateNew()
.Do(nI =>
nI.Title = newsTitle;
nI.Author = author;
nI.Content = newsContent;
)
//without the publish method, the news item is saved as draft.
.Publish()
.SaveAndContinue().Get();
return
item;
Hi,
How do i set AutoGenerateUniqueUrl while create custom blog post using fluent API.
Thanks
jmr
Hi Paolo,
AutoGenerateUniqueUrl does not have a setter. You should use the code blow
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();
All the best,
Ivan Dimitrov
the Telerik team
Hi, how to set categories in this example code
Hello,
There is a data extension method
SetValue that you can use
1. Add reference to Telerik.Sitefinity.Model ( using Telerik.Sitefinity.Model;)
2. Call mynews.SetValue("Category", "name of existing category");
All the best,
Ivan Dimitrov
the Telerik team