Wednesday, December 22, 2010

Simple way to allow Anonymous SharePoint Site runs well with "My Tasks" view of a SPList

(2010.12.22) -Sai Gon- You know there is a exception or issue of "My Tasks" view of any SPList with WSS3.0 MOSS 2007, SharePoint Foundation 2010 or SharePoint Server 2010. Please look what are the issue or exception

1. Issue with WSS3.0 or MOSS2007
After choose "My Task" view of a SPList
The log-on dialog box display
2. Exception with SharePoint Foundation and SharePoint Server 2010
When select a "My Tasks" view of a SPList we see exception
A exception when I run a webpart on a anonymous site with data getting from "My Tasks" view
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) 


 So, Here are two way to solve the issue or exception when getting data from "My Tasks" view with your WebPart, Site Page or Application Page

A. Prevent Log-On issue with WSS3.0 or MOSS 2007
No way until now

B. Solve exception when getting data from "My Tasks" view with SharePoint Foundation 2010 or SharePoint Server 2010
Here is a normal way to get data from a view
SPListItemCollection itemCollection = null;
itemCollection = spList.GetItems(spQuery is a query data from a selected view);

Incase selected view is a "My Tasks" view on a anonymous site so SharePoint 2010 generate exception whenever we access to properties: Count, ListItemCollectionPosition, NumberOfFields, QueryFieldNames, Xml, XmlDataSchema
We know that, so must use try ... catch for getting data codes from a "My Tasks" view. If our purpose is get data with data structure from SPListItems so at catch statement we can use code spList.Items.GetDataTable().Clone(); to get a empty data table with DataTable structure only.

God bless us!
Thomas Trung Vo

No comments:

Post a Comment