It does seem strange. I get the same error irrespective of the view I select. 
What field could it be? There are no custom field types. How could I check this?
I also tried passing the viewName to the GetItems method but get a much uglier 
exception.
events = web.Lists[listName].GetItems(query, viewName);
8<--------

Cannot complete this action. Please try again. --->
System.Runtime.InteropServices.COMException (0x80004005): Cannot complete this 
action. Please try again.

at 
Microsoft.SharePoint.Library.SPRequestInternalClass.GetListItemDataWithCallback(String
 bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, 
SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, 
ISPDataCallback pPagingCallback, ISPDataCallback pSchemaCallback)
at Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback(String 
bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, 
SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, 
ISPDataCallback pPagingCallback, ISPDataCallback pSchemaCallback)
--- End of inner exception stack trace ---
at Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback(String 
bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, 
SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, 
ISPDataCallback pPagingCallback, ISPDataCallback pSchemaCallback)
at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData()
at Microsoft.SharePoint.SPListItemCollection.Undirty()
at 
Microsoft.SharePoint.SPBaseCollection.System.Collections.IEnumerable.GetEnumerator()
at System.Linq.Enumerable.d__aa`1.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
at CalendarWebpart.CalendarWebpart.cal_DayRender(Object sender, 
DayRenderEventArgs e)

Microsoft.SharePoint.SPException: Cannot complete this action. Please try again.


From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Ishai Sagi
Sent: Friday, 3 February 2012 11:19 AM
To: ozMOSS
Subject: RE: SPQuery - Filtering results by view title

It looks like the problem is not with the view, but with a field (maybe 
specified in the view?)


[cid:image003.jpg@01CCE267.CB265E60]Ishai Sagi | Solutions Architect
0488 789 786 | is...@exd.com.au<mailto:is...@exd.com.au> | 
www.sharepoint-tips.com<http://www.sharepoint-tips.com/> | 
@ishaisagi<http://twitter.com/ishaisagi>

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Paul Noone
Sent: Friday, 3 February 2012 10:58 AM
To: ozMOSS (ozmoss@ozmoss.com)
Subject: SPQuery - Filtering results by view title

Hi all,
I have a Calendar wp that I have modified to allow result filtering via a Views 
dropdown. I'm trying to pass the selected View's title to the SPQuery in order 
to pre-filter the results. But she ain't working.
This is my query.
void cal_DataBinding(object sender, EventArgs e)
{
    if (!string.IsNullOrEmpty(WebId) && !string.IsNullOrEmpty(listName))
    {
        using (SPWeb web = SPContext.Current.Site.OpenWeb(new Guid(WebId)))
        {
            // Check/Get supplied list view
            SPView view = web.Lists[listName].Views[viewName];
            // Pass list view to the query
            SPQuery query = new SPQuery(view);
            query.CalendarDate = cal.VisibleDate;
            query.ExpandRecurrence = true;
            query.Query = "<Where>" +
                "<DateRangesOverlap>" +
                "<FieldRef Name=\"" + dateField + "\"></FieldRef>" +
                "<FieldRef Name=\"" + endDateField + "\"></FieldRef>" +
                "<FieldRef Name=\"RecurrenceID\"></FieldRef>" +
                "<Value Type=\"DateTime\"><Month/></Value>" +
                "</DateRangesOverlap></Where>";
            events = web.Lists[listName].GetItems(query);
        }
    }
}
I'm receiving the following exception, irrespective of which view is selected.
System.ArgumentException: Value does not fall within the expected range.
at Microsoft.SharePoint.SPFieldMap.GetColumnNumber(String strFieldName)
at Microsoft.SharePoint.SPListItemCollection.GetRawValue(String fieldname, 
Int32 iIndex)
at Microsoft.SharePoint.SPListItem.GetValue(SPField fld, Int32 columnNumber, 
Boolean bRaw)
at Microsoft.SharePoint.SPListItem.get_Item(Guid fieldId)
at CalendarWebpart.CalendarWebpart.cal_DayRender(Object sender, 
DayRenderEventArgs e)

The viewName is a string which gets its value from the following dropdown:

cboView.Items.Add(new ListItem(view.Title, view.Title));

If I remove the view from the SPQuery everything works fine.

          SPQuery query = new SPQuery(view);

Regards,

Paul

--
Online Developer/SharePoint Administrator,
ICT Infrastructure Team
CEO Sydney


<<inline: image001.jpg>>

<<inline: image003.jpg>>

_______________________________________________
ozmoss mailing list
ozmoss@ozmoss.com
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss

Reply via email to