有一个有趣的sharepoint日历视图过滤问题。 该代码工作正常:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteCollection = new SPSite(SPContext.Current.Web.Site.ID))
{
using (SPWeb site = siteCollection.OpenWeb())
{
site.AllowUnsafeUpdates = true;
SPView view = site.Lists["My Calendar"].Views["Calendar"];
view.Query = @"<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>ololo</Value></Eq></Where>";
view.Update();
site.AllowUnsafeUpdates = false;
}
}
});
但是当我将查询更改为
时SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteCollection = new SPSite(SPContext.Current.Web.Site.ID))
{
using (SPWeb site = siteCollection.OpenWeb())
{
site.AllowUnsafeUpdates = true;
SPView view = site.Lists["My Calendar"].Views["Calendar"];
view.Query = @"<Where><Or><Eq><FieldRef Name='Title'/><Value Type='Text'>ololo</Value></Eq><Eq><FieldRef Name='Title'/><Value Type='Text'>trololo</Value></Eq></Or></Where>";
view.Update();
site.AllowUnsafeUpdates = false;
}
}
});
我得到例外:
输入字符串的格式不正确。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.FormatException:输入字符串的格式不正确。
来源错误:
在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。
堆栈追踪:
[FormatException:输入字符串的格式不正确。]
System.Number.StringToNumber(String str,NumberStyles options,NumberBuffer&amp; number,NumberFormatInfo info,Boolean parseDecimal)+10161091
System.Number.ParseInt32(String s,NumberStyles style,NumberFormatInfo info)+207
System.Convert.ToInt32(String value,IFormatProvider provider)+55
Microsoft.SharePoint.Utilities.SPUtility.CreateSystemDateTimeFromXmlDataDateTimeFormat(String strDT,Boolean fPreserveMilliseconds)+174
Microsoft.SharePoint.ApplicationPages.Calendar.SafeFieldAccessor.GetDateTimeFieldValue(SPItem item,String fieldName)+227
Microsoft.SharePoint.ApplicationPages.Calendar.CalendarItemRetriever.b_ 0(SPItem项目)+24
System.Linq.WhereListIterator 1.MoveNext() +288
System.Linq.<ExceptIterator>d__92
1.MoveNext()+ 322
System.Linq.Buffer 1..ctor(IEnumerable
1来源)+548
System.Linq.d _0.MoveNext()+ 164
Microsoft.SharePoint.ApplicationPages.Calendar.CalendarItemRetriever.ConvertItemType(IEnumerable 1 items) +578
Microsoft.SharePoint.ApplicationPages.Calendar.DefaultCalendarListAccessor.Retrieve(String selectedDate, String scope, Dictionary
2 entityInfo)+18
Microsoft.SharePoint.ApplicationPages.Calendar.CalendarService.CreateStartupResponse(ICalendarAccessor accessor,Dictionary`2 parameters,String viewType,String selectedDate)+249
Microsoft.SharePoint.ApplicationPages.WebControls.AjaxCalendarView.CreateStartupData(String viewType,String selectedDate)+462
Microsoft.SharePoint.ApplicationPages.WebControls.AjaxCalendarView.CreateBodyOnLoadScript(SPWeb web)+306
Microsoft.SharePoint.ApplicationPages.WebControls.AjaxCalendarView.OnPreRender(EventArgs e)+425
System.Web.UI.Control.PreRenderRecursiveInternal()+108
System.Web.UI.Control.PreRenderRecursiveInternal()+ 224
System.Web.UI.Control.PreRenderRecursiveInternal()+ 224
System.Web.UI.Control.PreRenderRecursiveInternal()+ 224
System.Web.UI.Control.PreRenderRecursiveInternal()+ 224
System.Web.UI.Control.PreRenderRecursiveInternal()+ 224
System.Web.UI.Control.PreRenderRecursiveInternal()+ 224
System.Web.UI.Control.PreRenderRecursiveInternal()+ 224
System.Web.UI.Control.PreRenderRecursiveInternal()+ 224
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+3394
有人知道如何解决这个问题吗?
答案 0 :(得分:1)
问题解决了。应将“DateRangesOverlap”添加到日历查询中。
view.Query = @"<Where><And><DateRangesOverlap>
<FieldRef Name='EventDate' />
<FieldRef Name='EndDate' />
<FieldRef Name='RecurrenceID' />
<Value Type='DateTime'><Month /></Value>
</DateRangesOverlap>
<Or><Eq><FieldRef Name='Title' />
<Value Type='Text'>orlolo</Value></Eq>
<Eq><FieldRef Name='Title' />
<Value Type='Text'>trololo</Value></Eq>
</Or></And></Where>";
答案 1 :(得分:0)
你确定带有标题“trololo”的项目不是“拖钓”你的页面并打破它(可能是因为数据无效)?
看看你是否可以在用户界面中手动创建该视图,然后编写一个控制台应用程序,然后打印出为查询生成的内容。我刚刚做了,查询在语法上与你的例子相同。