Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7525787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:38:57+00:00 2026-05-30T03:38:57+00:00

I have a publishing website build with MOSS 2007 and I need to get

  • 0

I have a publishing website build with MOSS 2007 and I need to get the page content programmatically. I know that I can use WebClient to sent a request to the page and then parse the response text. But I want to do it in SharePoint model since the scale is quiet large.

The web parta I want to render are DataFormWebPart and they display fine if viewed in a browser. But I’m getting exceptions when trying to render them programmatically.

The code:

var partMgr = siteCollection.RootWeb.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared);

var sr = new StreamWriter(@"d:\temp\test.txt", false);
var htr = new HtmlTextWriter(sr);

foreach (WebPart part in partMgr.WebParts)
{
    if (part.GetType() == new DataFormWebPart().GetType())
    {
        try
        {
            htr.WriteLine("");
            part.RenderBeginTag(htr);
            htr.WriteLine("");
            part.RenderControl(htr);
            htr.WriteLine("");
            part.RenderEndTag(htr);
            htr.WriteLine("");
        }
        catch (Exception exc)
        {
            htr.WriteLine("Message: " + exc.Message);
            htr.WriteLine("StackTrace: " + exc.StackTrace);
            htr.WriteLine("InnerException: " + (exc.InnerException == null).ToString());
        }
    }
}
sr.Close();
htr.Close();

The output:

<div id="g_1722aa69_d0d7_4804_83fa_c8f4a250080a">
    Message: Value cannot be null. Parameter name: page
    StackTrace:    at System.Web.UI.WebControls.WebParts.WebPartManager.GetCurrentWebPartManager(Page page)
   at Microsoft.SharePoint.WebPartPages.WebPart.Render(HtmlTextWriter writer)
   at ExtractPageData.Program.Main(String[] args) in D:\DNR-Playground\ExtractPageData\ExtractPageData\Program.cs:line 49
    InnerException: False

    <div id="g_1115045e_b0d7_41ce_ad19_15aab0f3871d">
        Message: Value cannot be null. Parameter name: page
        StackTrace:    at System.Web.UI.WebControls.WebParts.WebPartManager.GetCurrentWebPartManager(Page page)
   at Microsoft.SharePoint.WebPartPages.WebPart.Render(HtmlTextWriter writer)
   at ExtractPageData.Program.Main(String[] args) in D:\DNR-Playground\ExtractPageData\ExtractPageData\Program.cs:line 49
        InnerException: False

As you can see in the output, the begin tag is rendered but the control can’t be rendered due to part.Page is null and it it’s a readonly attribute.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:38:59+00:00Added an answer on May 30, 2026 at 3:38 am

    This just won’t work. Web parts require proper SPContext which is setup during HTTP request handling in the ASP.NET pipeline. There’s no easy answer how to overcome it. You would essentially have to simulate an HTTP request to the page that you need to render in-memory.


    Also, this expression part.GetType() == new DataFormWebPart().GetType() is far from ideal. Rather use part.GetType() == typeof(DataFormWebPart) to prevent instantiation and possible unwanted side effects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a classifieds website, where anyone (no need for login currently) can post
I have a Publishing Portal site and I need to add some announcements to
I have a MOSS publishing site and a document library with it's own unique
We have an existing moss publishing site. When we enable the css control adapters
I have a problem while publishing on the Market. My application does not use
I have a JBoss server (Server A) that is publishing messages on a topic.
I have created a feature, a publishing site, in Visual Studio to MOSS -
I have an application (C#, .Net4) which I'm publishing with ClickOnce. I need to
We use Nant and devenv.com to build all our assemblies including the website project.
I have 2 master pages inside one ASP.Net website. It work fine without publishing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.