SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

First time here and I'm hoping someone can help me. I've searched all over and can't find anything...

We have an application running in Central Administration that generates ASPX files to specified document libraries on web front ends within SP 2010. So far the code works fine on multiple client and test environments, with one exception. For some reason, on this site SharePoint is removing the web part code from the generated code after it's added to the document library.

Here is the code that generates the file. Please note that page.Definition is a string property of the page object and folder is an SPFolder object pointing to the correct document library:

byte[ ] byteArray = Encoding.ASCII.GetBytes( page.Definition );
Hashtable properties = new Hashtable( );
properties.Add( "FileID", page.ID );
SPFile newFile = folder.Files.Add( String.Format( "{0}/{1}", folder, pageName ), byteArray, properties, true );

The code this is generating looks something like this (shortened for brevity):

<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderMain" runat="server">
    <WebPartPages:WebPartZone runat="server" Title="Filters" ID="Zone0">
                WebPart="true" >

I added some code to my publishing code that checks to make sure the file exists, and if so, to write out the contents to a log file. This is done immediately after the publishing, so it should obviously be identical, but it's not. Here's what it has:

<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderMain" runat="server">
    <WebPartPages:WebPartZone runat="server" Title="Filters" ID="Zone0">

It's stripping out my web part, as well as some WebPartPages:SPWebPartConnection objects I create at the top of the file. So basically any web part or web part connections are being removed immediately after the file (it's an ASPX file) is created within the document library.

My web parts are showing up in the site gallery and I can add them to a page in the site, set properties on them, load them, etc., so the web parts themselves are working fine. It's just that something is removing the code for them from my generated pages.

Any ideas? I appreciate it.

share|improve this question

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.