1

I am trying to get Description value from each SPWeb's SPWebInfo object:

DataTable _websinfo = new DataTable("WebsInfo");
_websinfo.Columns.Add("Title");
_websinfo.Columns.Add("Url");
_websinfo.Columns.Add("Description");

using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
    using (SPWeb web = site.OpenWeb())
    {
        foreach (SPWebInfo webInfo in web.Webs.WebsInfo)
        {
            _websinfo.Rows.Add(webInfo.Title, webInfo.ServerRelativeUrl, webInfo.Description);
        }
    }
}

I can get correct Title and ServerRelativeUrl with no problem but the Description is always null!

I've checked the webs with SharePoint Manager 2010 and they definitely have the Description value set.

What am I doing wrong? Is this a SharePoint bug?

1

I also checked, the description comes as null. I second your thought. This may be a bug. You can however use following variant of code to get the description of subwebs:

using (SPWeb web = site.OpenWeb())
{                   
    foreach (SPWeb subWeb in web.Webs)
    {
        using (subWeb)
        {
            string desc = subWeb.Description;
            string url = subWeb.ServerRelativeUrl;
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.