private string GetListvalue()
{
string strVal=string.Empty;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
Uri uri = new Uri(SPContext.Current.Web.Url.ToString());
SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://" + uri.Host));
if (webApp != null && webApp.Sites != null && webApp.Sites.Count > 0)
{
using (SPWeb web = SPContext.Current.Site.RootWeb)
{
foreach (SPSite site in webApp.Sites)
{
foreach (SPWeb web in site.AllWebs)
{
if (IfListExists(web, "List Name"))
{
SPList lstStore;
SPListItemCollection items;
lstStore = web.GetList(list path);
SPQuery query = new SPQuery();
query.Query = "CAML query";
items = lstStore.GetItems(query);
strVal = items[0]["Column name"].ToString();
}
}
}
}
}
}
});
return strVal;
}
Here I am accessing a sigle column from the first row that will be returned by the query.
The IfListExists() method will use Linq to check whether the list exists or not. Sharepoint don't have any method or properties to check the existance of the list. Another alternative is to use the Extension Methods. Below is the definition of the IfListExists() method-
private static bool IfListExists(SPWeb web, string listName)
{
return web.Lists.Cast
}
Thats it.
Hopes it will help. :)

Any idea of how to retreive items of the current logged in user from various doc libraris of different web applications. Also we need in normal list view format i.e. with context menu. Any product available for such requirement.
ReplyDeleteAwaiting for your reply...
hey
ReplyDeleteu can use out of the box list view webpart and filter them by current logged-in user.
there is a column 'created by' in each list/library. u can match the same with current loggedin user for the filtering.
Thanks of your reply..
ReplyDeleteI am asking about retreive items of the current logged in user from various doc libraris of different web applications or virtual server.
to access multiple doc library u will have to use SPSitedataQuery class instead of SPQuery. This also have some limitation. check out my below blog-
ReplyDeletehttp://deewaker-blogs.blogspot.com/2009/07/accessing-multiple-lists-across.html
To check whether the item is created by current logged in user or not, u need to check whether web.CurrentUser is same as the 'CreatedBy' column name for a particular row.
Thanks for your reply..
ReplyDeleteWe have instance where we need retreive document library items from multiple site collections which lies under multiple web application.
Is this possible by SP Object model?
Kindly advice how we can acheive this?