-
Notifications
You must be signed in to change notification settings - Fork 577
Expand file tree
/
Copy pathNewsFeedController.cs
More file actions
37 lines (35 loc) · 1019 Bytes
/
Copy pathNewsFeedController.cs
File metadata and controls
37 lines (35 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using BlogEngine.Core.Data.Models;
using System;
using System.Collections.Generic;
using System.ServiceModel.Syndication;
using System.Web.Http;
using System.Xml;
public class NewsFeedController : ApiController
{
public List<SelectOption> Get()
{
var items = new List<SelectOption>();
string url = "https://blogengine.io/news.xml";
try
{
var cnt = 0;
var reader = XmlReader.Create(url);
var feed = SyndicationFeed.Load(reader);
reader.Close();
foreach (SyndicationItem item in feed.Items)
{
var option = new SelectOption();
option.OptionName = item.Title.Text;
option.OptionValue = item.Id;
items.Add(option);
cnt++;
if (cnt > 5) break;
}
}
catch (Exception ex)
{
BlogEngine.Core.Utils.Log("Dashboard news feed", ex);
}
return items;
}
}