Showing posts with label Moss 2007. Show all posts
Showing posts with label Moss 2007. Show all posts

Thursday, October 23, 2014

Programmatically Get List items inside the folders of SPList





How to search items inside the folders of list using caml query
many times while validating against multiple entries we have to query check , here we go to fetch all the  items inside the list including folders

you should use  spquery.ViewAttributes = "Scope=\"Recursive\"";  so that query searches in recursive way .
                             


full code
 SPList list = web.Lists["ListName"];


                                var querytext = "<View Scope='Recursive'><Where><Eq><FieldRef Name='UserName' /><Value Type='Text'>" + currentLogginUser.LoginName + "</Value></Eq></Where>";
                             
                                SPQuery spquery = new SPQuery();
                                spquery.Query = querytext;
                                spquery.ViewAttributes = "Scope=\"Recursive\""; 
                                var items = list.GetItems(spquery);


Thursday, September 18, 2014

Get Field value as text

I have seen many developers struggling to fetch text value from Multi line/ Choice column of sharepoint list or library , below is easiest way to achieve this

            SPSite site = SPContext.Current.Site;
            SPWeb web = site.OpenWeb();
            SPList declarationList = web.Lists["DeclarationContent"];
            SPListItem item = declarationList.Items[0];
            string content = item.Fields["declaration"].GetFieldValueAsText(item["declaration"]);


if u observe the above code item.Fields["declaration"] contains method GetFieldValueAsText
which accepts the value of column and it will convert the html or drop down /choice content into text value.

Happy Coding !!