Caml查询仅返回文本

时间:2013-08-19 08:54:04

标签: c# sharepoint caml

我需要我的caml查询才能返回文字,例如现在它正在给我这个

<div class=ExternalClass104BBsdfEEDCEdddsf48C68C18AsdfB056FBsdfAB805>Real Content.....</div>

当我只想要Real Content.....时。我正在使用的代码是,

using System;
using System.Data;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;

namespace SPSandeep.ConsoleApplication
{
    class Program
    {
        public static DataTable dt = null;

        static void Main (string[] args)
        {
            using (SPSite site = new SPSite("http://ws2003/credit"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList mainList = web.Lists["Team Discussion"];

                    foreach (SPListItem folder in mainList.Folders)
                    {
                        Console.WriteLine("Folder Name: " + folder.Name);
                        Console.WriteLine("Folder ID: " + folder.ID);

                        // Read body of attachment  
                        Console.WriteLine("Body: " + folder.Fields["Body"].GetFieldValueAsText(folder["Body"]));
                        Console.WriteLine("Threading: " + folder.Fields["Threading"].GetFieldValueAsText(folder["Threading"]).Length);
                        Console.WriteLine("=============================");

                        RenderAllReponses(mainList, folder.ID);

                        Console.WriteLine("=============================");
                    }
                }
            }

            Console.ReadKey();
        }

        public static void RenderAllReponses (SPList mainList, int parentID)
        {
            SPQuery query = new SPQuery();
            query.Query = string.Format("<Where><Eq><FieldRef Name='ParentFolderId' /><Value Type='Number'>{0}</Value></Eq></Where>", parentID.ToString());
            query.ViewFields = @"<FieldRef Name='ows_ParentFolderId' /><FieldRef Name='Threading' /><FieldRef Name='Title' /><FieldRef Name='ID' /><FieldRef Name='Body' />";
            query.ViewAttributes = "Scope='RecursiveAll'";
            dt = mainList.GetItems(query).GetDataTable();

            if (null != dt)
            {
                foreach (DataRow listItem in dt.Rows)
                {
                    if (listItem["Threading"].ToString().Length == 56)
                    {
                        RenderResponse(listItem, 56);
                    }
                }
            }
        }

        public static void RenderResponse (DataRow listItem1, int length)
        {
            DataRow[] listItems = dt.Select(string.Format("Threading Like '{0}*' AND LEN(Threading)={1}", listItem1["Threading"], length));

            foreach (DataRow item in listItems)
            {
                Console.WriteLine("Item DisplayName: " + item["Title"]); // Returns Title of Discussion   
                Console.WriteLine("List ID: " + item["ID"] );
                //Console.WriteLine("List Folder ID: " + listItem["ParentFolderId"] + "<BR>"); // Returns ID of Parent Discussion   
                Console.WriteLine("Body: " + item["Body"]);
                Console.WriteLine("Threading: " + item["Threading"].ToString().Length );
                int newLength = length + 10;
                RenderResponse(item, newLength);
            }
        }
    }  
}

0 个答案:

没有答案