我需要关于与处理对象相关的sharepoint日志的建议。
我在查看日志时发现了这些:
意外检测到对以前关闭的SPWeb对象使用了SPRequest。请在处理所有从它们获得的对象时关闭SPWeb对象,但在此之前请关闭。
Stack trace:
at Microsoft.SharePoint.SPFile.PropertiesCore(Boolean throwException)
at Microsoft.SharePoint.SPFile.get_CheckInComment()
...在此线程结束之前没有释放可监视的SPRequest对象。
为了避免浪费系统资源,在使用完该对象或其父对象(例如SPSite或SPWeb)之后,立即处理它。现在将释放此对象。
This SPRequest was allocated at
at Microsoft.SharePoint.Library.SPRequest..ctor()
at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(SPSite site, String name, Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous)
at Microsoft.SharePoint.SPWeb.InitializeSPRequest()
at Microsoft.SharePoint.SPWeb.GetFileOrFolderProperties(String strUrl, ListDocsFlags listDocsFlags, Boolean throwException, SPBasePermissions& permMask)
at Microsoft.SharePoint.SPFile.PropertiesCore(Boolean throwException)
at Microsoft.SharePoint.SPFile.get_CheckInComment()
...我不知道这两种代码之间的主要区别是什么,因为我以同样的方式处理对象。
For循环出什么问题了?
创建日志错误的代码:
using (SPSite site = new SPSite(url))
{
using (SPWeb web = site.OpenWeb())
{
string serverRelativeUrl = SPUrlUtility.CombineUrl(web.ServerRelativeUrl, listRelativeUrl);
SPList lst = web.GetList(serverRelativeUrl);
items = lst.Items;
if (items != null)
{
int nb = items.Count;
for (int i = nb - 1; i > -1; i--)
{
currItem =items[i];
if (currItem.File.CheckInComment.Equals(comment1) || currItem.File.CheckInComment.Equals(comment2))
{
publish = true;
}
if(publish)
{
//do stuff with currItem data
}
}
}
}
}不创建日志错误的代码:
using (SPSite site = new SPSite(url))
{
using (SPWeb web = site.OpenWeb())
{
string serverRelativeUrl = SPUrlUtility.CombineUrl(web.ServerRelativeUrl, listRelativeUrl);
SPList lst = web.GetList(serverRelativeUrl);
items = lst.Items;
if (items != null)
{
foreach(SPListItem currItem in items )
{
if (currItem.File.CheckInComment.Equals(comment1) || currItem.File.CheckInComment.Equals(comment2))
{
publish = true;
}
if(publish)
{
//do stuff with currItem data
}
}
}
}
}我需要使用For循环,因为我需要在枚举中删除项,这是我无法使用foreach循环做的事情。
如果你有什么办法帮我的话。
谢谢。
发布于 2016-10-05 14:08:37
我会在数字集合中捕获要删除的项的ID。一个数组或对象列表就足够了。
然后,先检查您的集合是否包含任何ID。然后执行
for(int i = 0, i < collection.count(), ++i){
#get your item
#delete your item
#call the correct update method on your list.
}我不能告诉你你为什么要处理这个问题。
干杯
特鲁兹
https://stackoverflow.com/questions/39874850
复制相似问题