Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am tring to render Blog Posts list using RenderAsHTML() method but it returns empty string. The same method works for other lists.

Here is the code, tried in console app:

string url = "http://abc.com/blogs/Lists/Posts/AllPosts.aspx";
             url = url.ToLower();
             if (string.IsNullOrEmpty(url))
             int listsStart = url.IndexOf("lists");
             string sitePath = url.Substring(0, listsStart);
             string listPath = url.Substring(listsStart);                
            using (SPSite site = new SPSite(sitePath))
             using (SPWeb web = site.OpenWeb())
                 string serverRelativeUrl = web.ServerRelativeUrl;
                 if (serverRelativeUrl == "/")
                     serverRelativeUrl = "";
                     serverRelativeUrl += "/";

                SPList list;
                 list = web.GetList(serverRelativeUrl + listPath);
                 String _view = null;
                 _view = "All Posts";
                 if (_view == null)
                     _view = "All Items";
                 SPView selectedView;
                 SPQuery query;
                 Guid viewguid = list.Views[_view].ID;
                 selectedView = list.GetView(viewguid);
                 selectedView.Scope = SPViewScope.Default;
                 query = new SPQuery(selectedView);
                 String str = list.RenderAsHtml(query);

Please note String str will always be empty if list is posts list

share|improve this question
Why this code works in SP 2007 not in SP 2010? Anyone is having answer, What is the chage in object model or Posts list defination, I don't clue :( –  PRS Jul 13 '13 at 5:48
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.