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

I am saving some masterpages to the file systems in some build scripts to automate the process of building deployment packages. This is what I am using to save the masterpages and layouts:

 using (var site = new SPSite("http://mysharepoint:2081"))
                SPList masterPageGallery = site.GetCatalog(SPListTemplateType.MasterPageCatalog);
                foreach (SPListItem li in masterPageGallery.Items)
                    if (EnumExtensions.ContainsDescription(typeof (MasterPageNames), li.File.Name) ||
                        EnumExtensions.ContainsDescription(typeof (PageLayoutNames), li.File.Name))
                        Console.WriteLine("Fetching - " + li.File.Name);
                        byte[] file = li.File.OpenBinary();
                        var fileStream = new FileStream(DeploymentLayoutsLocation + "\\" + li.File.Name,
                                                        FileMode.Truncate, FileAccess.Write);
                        fileStream.Write(file, 0, file.Length);

Everyhting is exported correctly instead of my webpart information so for instance:


<WebPartPages:WebPartZone id="WebPartZone_2" runat="server" title="Zone1" AllowLayoutChange="True" AllowCustomization="True"><ZoneTemplate>
    <WebUI:BrowserFormWebPart runat="server" AllowEdit="True" AllowConnect="True" SubmitBehavior="KeepOpen" ConnectionID="00000000-0000-0000-0000-000000000000" Title="Online Form" ></WebUI:BrowserFormWebPart>

Comes out as:

<WebPartPages:WebPartZone id="WebPartZone_2" runat="server" title="Zone1" AllowLayoutChange="True" AllowCustomization="True"><ZoneTemplate></ZoneTemplate>

Any Idea?

share|improve this question
Working as designed. WebPart instance data is not stored as part of the masterpage. – Paul Schaeflein Jul 9 '12 at 13:11
Sure, but how can i Extract the full data. It must be possible because sharepoint designer does it... – Luis Jul 10 '12 at 0:26

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.