В веб части новостей, не прогружаются все новости
#39223522
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
|
|
Не могу никак разрулить ситуацию, есть код на шарпе, веб части отвечающей за новости на портале. Он работает все ок. Но случилась ситуация что но новостной блок перестал отображать новые новости после 14 апреля этого года, хотя сами страницы на сервере есть.
Осторожно много кода, но он не сложный
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. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220. 221. 222. 223. 224. 225. 226. 227. 228. 229. 230. 231. 232. 233. 234. 235. 236. 237. 238. 239. 240. 241. 242. 243. 244. 245. 246. 247. 248. 249. 250. 251. 252. 253. 254. 255. 256. 257. 258. 259. 260. 261. 262. 263. 264. 265. 266. 267. 268. 269. 270. 271. 272. 273. 274. 275. 276. 277. 278. 279. 280. 281. 282. 283. 284. 285. 286. 287. 288. 289. 290. 291. 292. 293. 294. 295. 296. 297. 298. 299. 300. 301. 302. 303. 304. 305. 306. 307. 308. 309. 310. 311. 312. 313. 314. 315. 316. 317. 318. 319. 320. 321. 322. 323. 324. 325. 326. 327. 328. 329. 330. 331. 332. 333. 334. 335. 336. 337. 338. 339. 340. 341. 342. 343. 344. 345. 346. 347. 348. 349. 350. 351. 352. 353.
using Microsoft.Office.Server.SocialData;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing.Fields;
using Microsoft.SharePoint.Utilities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Linq;
using xxx.Intranet.ObjectModel;
namespace xxx.Intranet.WebParts.NewsMainPageWebPart
{
public partial class NewsMainPageWebPartUserControl : UserControl
{
public class News
{
public int ID;
public string Title;
public DateTime npDateTime;
public string ImageUrl;
public string Comments;
public string Href;
public string LikesCount;
public bool LikedByMe;
public string ListId;
public string HrefFile;
public int CommentsCount;
public string NEWS_PAGES_NEWSTYPE;
public string NewsUrlRelative;
}
public class NewsDS
{
public NewsDS()
{
}
public List<News> GetNews()
{
List<News> res = new List<News>();
SPListItemCollection items;
SPUser curUser = SPContext.Current.Web.CurrentUser;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (new SPMonitoredScope("GetMyDAIRequestsDS запросы к DaiRequestsNew"))
using (SPSite elevSite = new SPSite(SPContext.Current.Site.ID))
using (SPWeb elevWeb = elevSite.OpenWeb(SPUrlUtility.CombineUrl(SPContext.Current.Site.RootWeb.ServerRelativeUrl, "/news")))
{
SPServiceContext context = SPServiceContext.GetContext(elevSite);
SocialCommentManager socialCommentManager = new SocialCommentManager(context);
SPList elevNewsList = elevWeb.Lists["Страницы"];
SPQuery qry = new SPQuery();
SPListItemCollection colItems = null;
colItems = elevNewsList.GetItems(qry);
foreach (SPListItem newsItem in colItems)
{
News dai = new News();
dai.ID = newsItem.ID;
dai.NewsUrlRelative = "/news";
dai.Title = newsItem[newsItem.Fields.GetFieldByInternalName("Title").Id].ToString();
if (newsItem[newsItem.Fields.GetFieldByInternalName(Constants.Fields.NEWS_PAGES_DATETIME).Id] != null)
dai.npDateTime = Convert.ToDateTime(newsItem[newsItem.Fields.GetFieldByInternalName(Constants.Fields.NEWS_PAGES_DATETIME).Id].ToString());
else
dai.npDateTime = new DateTime(2000, 1, 1);
if (newsItem[newsItem.Fields.GetFieldByInternalName("PublishingPageImage").Id] != null)
dai.ImageUrl = ((ImageFieldValue)newsItem[newsItem.Fields.GetFieldByInternalName("PublishingPageImage").Id]).ImageUrl;
else
dai.ImageUrl = "/_layouts/15/xxx.Intranet/images/news_no_picture.png";
if (newsItem[newsItem.Fields.GetFieldByInternalName("Comments").Id] != null)
dai.Comments = newsItem[newsItem.Fields.GetFieldByInternalName("Comments").Id].ToString();
dai.HrefFile = SPUrlUtility.CombineUrl(elevWeb.ServerRelativeUrl, newsItem.Url);
dai.Href = newsItem.ParentList.DefaultDisplayFormUrl + "?ID=" + newsItem.ID;
if (newsItem[newsItem.Fields.GetFieldByInternalName(Constants.Fields.NEWS_PAGES_NEWSTYPE).Id] != null)
dai.NEWS_PAGES_NEWSTYPE = ((Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue)newsItem[newsItem.Fields.GetFieldByInternalName(Constants.Fields.NEWS_PAGES_NEWSTYPE).Id]).Label;
dai.CommentsCount = 0;
try
{
string url = SPUrlUtility.CombineUrl(elevWeb.Url, newsItem.Url);
SocialComment[] comments = socialCommentManager.GetComments(new Uri(url));
dai.CommentsCount = comments.Length;
}
catch { }
dai.LikesCount = "0";
if (newsItem[newsItem.Fields.G etFieldByInternalName("LikesCount").Id] != null)
dai.LikesCount = newsItem[newsItem.Fields.GetFieldByInternalName("LikesCount").Id].ToString();
if (newsItem[newsItem.Fields.GetFieldByInternalName("LikedBy").Id] != null)
{
SPFieldUserValueCollection usersVal = new SPFieldUserValueCollection(elevWeb, newsItem[newsItem.Fields.GetFieldByInternalName("LikedBy").Id].ToString());
foreach (SPFieldUserValue userVal in usersVal)
if (userVal.User.ID == curUser.ID)
dai.LikedByMe = true;
}
dai.ListId = newsItem.ParentList.ID.ToString();
res.Add(dai);
}
res = res.OrderByDescending(x => x.npDateTime).ToList();
}
});
return res;
}
}
private List<News> _items = null;
private List<LinkButton> allListColHeaders = new List<LinkButton>();
public List<News> Items
{
get
{
using (new SPMonitoredScope("MyDAITasksWebPart Items"))
{
if (_items == null)
_items = new NewsDS().GetNews();
return _items;
}
}
set
{
_items = value;
}
}
private string taskListId;
protected void Page_Load(object sender, EventArgs e)
{
}
private void AddErrorMessage(Exception ex)
{
CustomValidator val = new CustomValidator();
val.ValidationGroup = "myTasks";
val.IsValid = false;
val.ErrorMessage = ex.Message;
val.Visible = false;
this.Controls.Add(val);
}
protected void newsRepeaterItemCommand(object sender, RepeaterCommandEventArgs e)
{
}
protected void newsRepeaterItemDataBound(object sender, RepeaterItemEventArgs e)
{
News item = (News)e.Item.DataItem;
Label lblCreated = (Label)e.Item.FindControl("lblCreated");
lblCreated.Text = item.npDateTime.ToString("dd.MM.yyyy");
Label lblType = (Label)e.Item.FindControl("lblType");
lblType.Text = item.NEWS_PAGES_NEWSTYPE;
HiddenField hdnID = (HiddenField)e.Item.FindControl("hdnID");
hdnID.Value = item.ID.ToString();
HtmlImage imgNews = (HtmlImage)e.Item.FindControl("imgNews");
imgNews.Src = item.ImageUrl;
HtmlAnchor linkTitle = (HtmlAnchor)e.Item.FindControl("linkTitle");
linkTitle.InnerText = item.Title;
linkTitle.HRef = item.HrefFile;
HtmlGenericControl pText = (HtmlGenericControl)e.Item.FindControl("pText");
pText.InnerText = item.Comments;
HtmlAnchor linkLike = (HtmlAnchor)e.Item.FindControl("linkLike");
if (item.LikedByMe)
linkLike.InnerText = item.LikesCount + " не нравится";
else
linkLike.InnerText = item.LikesCount + " нравится";
string classid = item.NewsUrlRelative.Replace("/", "") + item.ID;
linkLike.Attributes.Add("class", "likecount" + classid);
linkLike.Attributes.Add("onclick", "javascript:LikeItem('" + item.ListId + "','" + item.ID + "','" + classid + "','" + item.NewsUrlRelative + "'); javascript:return false;");
HtmlGenericControl hdnLikedByMe = (HtmlGenericControl)e.Item.FindControl("hdnLikedByMe");
if (item.LikedByMe)
hdnLikedByMe.InnerText = "1";
else
hdnLikedByMe.InnerText = "0";
hdnLikedByMe.Attributes.Add("class", "likebyme" + classid);
HtmlGenericControl hdnlikeCount = (HtmlGenericControl)e.Item.FindControl("hdnlikeCount");
hdnlikeCount.InnerText = item.LikesCount.ToString();
hdnlikeCount.Attributes.Add("class", "likescounthidden" + classid);
HtmlAnchor linkComments = (HtmlAnchor)e.Item.FindControl("linkComments");
linkComments.HRef = item.HrefFile; ;// item.Href;
linkComments.InnerHtml = "<i class=\"icon-comments\"></i>" + item.CommentsCount + " Комментариев";
}
protected override void OnPreRender(EventArgs e)
{
try
{
using (new SPMonitoredScope("MyDAITasksWebPart OnPreRender"))
{
LoadData(Items.Count);
Items = CutItems(Items);
newsRepeater.DataSource = Items;
newsRepeater.DataBind();
if (Items.Count == 0)
{
lblError.Visible = true;
lblError.Text = "Нет записей.";
}
else
{
lblError.Visible = false;
lblError.Text = string.Empty;
}
}
}
catch (Exception ex)
{
AddErrorMessage(ex);
}
}
#region Paging
private void LoadData(int rowCount)
{
using (new SPMonitoredScope("MyDAITasksWebPartUserControl LoadData"))
{
var PageCount = rowCount / PageSize + (rowCount % PageSize == 0 ? 0 : 1);
if (PageCount > 0)
{
rptPages.Visible = true;
ArrayList pages = new ArrayList();
for (int i = 0; i < PageCount; i++)
pages.Add((i + 1).ToString());
rptPages.DataSource = pages;
rptPages.DataBind();
}
else
rptPages.Visible = false;
//ListItemsGrid.PageSize = PageSize;
if (PageNumber >= PageCount)
PageNumber = PageCount == 0 ? 0 : PageCount - 1;
// BldRepeater.DataSource = CutItems(items);
//BldRepeater.DataBind();
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
rptPages.ItemCommand += new RepeaterCommandEventHandler(rptPages_ItemCommand);
rptPages.ItemDataBound += new RepeaterItemEventHandler(rptPages_ItemDataBound);
}
void rptPages_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.DataItem != null && e.Item.DataItem.ToString() == (PageNumber + 1).ToString())
{
((LinkButton)e.Item.FindControl("btnPage")).Visible = false;
Label btnLabel = (System.Web.UI.WebControls.Label)e.Item.FindControl("btnLabel");
btnLabel.Visible = true;
btnLabel.Attributes.Add("class", "active");
}
}
void rptPages_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
}
void rptPageSize_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.DataItem != null && e.Item.DataItem.ToString() == (PageSize).ToString())
{
((LinkButton)e.Item.FindControl("btnPage")).Visible = false;
((System.Web.UI.WebControls.Label)e.Item.FindControl("btnLabel")).Visible = true;
}
}
public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
return Convert.ToInt32(ViewState["PageNumber"]);
else
return 0;
}
set
{
ViewState["PageNumber"] = value;
}
}
public int PageSize
{
get
{
if (ViewState["PageSize"] != null)
return Convert.ToInt32(ViewState["PageSize"]);
else
return 10;
}
set
{
ViewState["PageSize"] = value;
}
}
void rptPageSize_ItemCommand(object source, RepeaterCommandEventArgs e)
{
try
{
PageSize = Convert.ToInt32(e.CommandArgument);
}
catch (Exception) { PageSize = int.MaxValue; }
}
private List<News> CutItems(List<News> items)
{
using (new SPMonitoredScope("MyDAITasksWebPart CutItems"))
{
//new UsersDS().Users;
var newList = new List<News>();
//compute pages count
int pagesCount = items.Count / PageSize;
//add new page if itemsCount don't evenly divisible, i.e. 21/10 = 3 pages
pagesCount += ((items.Count / PageSize == 0) ? 0 : 1);
if (pagesCount == 0)
pagesCount++;
var currentPageNumber = PageNumber > pagesCount ? pagesCount : PageNumber;
for (int i = 0; i < items.Count; i++)
{
if (i >= (currentPageNumber) * PageSize && i < (currentPageNumber) * PageSize + PageSize)
newList.Add(items[i]);
}
return newList;
}
}
#endregion
}
}
aspx страничка, поставил дебаг <%=Convert.ToString(new NewsDS().GetNews().Count)%>, получаю 996, хотя по факту их 1010, почему выгружаются не все.
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. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123.
<%@ Assembly Name="XXX.Intranet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b4b16d7348366942" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="NewsMainPageWebPartUserControl.ascx.cs" Inherits="XXX.Intranet.WebParts.NewsMainPageWebPart.NewsMainPageWebPartUserControl" %>
<SharePoint:ScriptLink Language="javascript" Name="reputation.js" OnDemand="false" LoadAfterUI="true" runat="server" Localizable="false" />
<script type="text/javascript">
function LikeItem(listid, itemid, classid, weburl) {
var elementsLiked = document.getElementsByClassName("likebyme" + classid);
var makeLike = true;
if (elementsLiked[0].innerHTML == '1')
makeLike = false;
else
makeLike = true;
var aContextObject = new SP.ClientContext(_spPageContextInfo.siteServerRelativeUrl + weburl);
//var aContextObject = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
EnsureScriptFunc('reputation.js', 'Microsoft.Office.Server.ReputationModel.Reputation', function () {
Microsoft.Office.Server.ReputationModel.Reputation.setLike(aContextObject, listid, itemid, makeLike);
aContextObject.executeQueryAsync(
function () {
var elements = document.getElementsByClassName("likecount" + classid);
var elementsLiked = document.getElementsByClassName("likebyme" + classid);
var elementsLikeCount = document.getElementsByClassName("likescounthidden" + classid);
var count = parseInt(elementsLikeCount[0].innerHTML);
if (!makeLike) {
count--;
elements[0].innerHTML = count.toString() + " нравится";
elementsLiked[0].innerHTML = "0";
} else {
count++;
elements[0].innerHTML = count.toString() + " не нравится";
elementsLiked[0].innerHTML = "1";
}
elementsLikeCount[0].innerHTML = count.toString();
},
function (sender, args) {
// Custom error handling if needed
});
});
}
</script>
<asp:UpdatePanel ChildrenAsTriggers="true" ID="updPanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<div class="news-block">
<a style="text-decoration: none; font-size: 30px; color:black;" href="/news">Новости</a>
<table style="width: 100%;">
<tr>
<td style="text-align: left; vertical-align: top;">
<div style="display: none;">
<%=Convert.ToString(new NewsDS().GetNews().Count)%> - вот здесь
</div>
<ul class="news-list">
<asp:Repeater ID="newsRepeater" runat="server" OnItemCommand="newsRepeaterItemCommand"
OnItemDataBound="newsRepeaterItemDataBound">
<ItemTemplate>
<li style="text-align: left; min-height: 200px;">
<table style="width: 100%;">
<tr>
<td>
<asp:Label runat="server" ID="lblCreated"></asp:Label>
<asp:HiddenField ID="hdnID" Value="" runat="server" />
<span style="visibility: hidden;" runat="server" id="hdnLikedByMe"></span>
<span style="visibility: hidden;" runat="server" id="hdnlikeCount"></span>
</td>
<td style="text-align: right;">
<asp:Label runat="server" ID="lblType"></asp:Label>
</td>
</tr>
</table>
<div class="image-holder">
<a href="#">
<img style="width: 80px;" runat="server" id="imgNews" /></a>
</div>
<h2><a runat="server" id="linkTitle" href=""></a></h2>
<p runat="server" id="pText"></p>
<div class="news-footer">
<span>
<img src="/_layouts/15/images/LikeFull.11x11x32.png?rev=23" style="display: inline-block;" />
<a runat="server" id="linkLike" href="#"></a></span>
<span><a runat="server" id="linkComments" href="#"></a></span>
</div>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</td>
</tr>
</table>
<table style="width: 100%;">
<tr>
<td style="text-align: center; vertical-align: central;">
<asp:Repeater ID="rptPages" runat="server">
<ItemTemplate>
<asp:LinkButton ID="btnPage" CommandName="Page" CommandArgument="<%#Container.DataItem %>"
CssClass="text" runat="server"><%# Container.DataItem %></asp:LinkButton>
<asp:Label ID="btnLabel" runat="server" Visible="false"><%# Container.DataItem %></asp:Label>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
</td>
</tr>
</table>
<div style="display: none">
<asp:Label runat="server" ID="lblError"></asp:Label>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Но повершеллом я спокойно получаю все элементы, полный список все 1010 новостей
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24.
cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
$sourceWebURL = "https://myportal.com/news"
$sourceListName = "Страницы"
$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]
$spSourceItems = $spSourceList.GetItems()
$count = 0;
$spSourceItems | ForEach-Object {
$count = $count+1
Write-Host $count
Write-Host $_['PublishingPageImage']
Write-Host $_['Title']
Write-Host $_['npDateTime']
Write-Host $_['Comments']
Write-Host $_['Href']
Write-Host '_______________________________________________________ '
}
|
|