Search This Blog

Wednesday, May 9, 2012

Steps to move Pages and Webpart to a Production server using coding



STEP 1:
Steps to Create a Sharepoint Project

File ->New->Project->EmptySharepointProject







STEP 2:

Deploy the site has Farm solution






STEP 3:

Right click the project àAdd->New Item ->Sharepoint 2010 ->Module









STEP 4:

Rename sample.txt to Samplepage.aspx .Copy and paste the
below code without any changes in samplepage.aspx.if u want to change you can
rename the webpartzoneid and u can add multiple zones.

<%@ Assembly
Name="$SharePoint.Project.AssemblyFullName$"
%>

<%@ Register
Tagprefix="SharePoint"
Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint,
Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"

%>


<%@ Register
Tagprefix="WebPartPages"
Namespace="Microsoft.SharePoint.WebPartPages"
Assembly="Microsoft.SharePoint,
Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"


%>

<%@ Register
Tagprefix="PublishingWebControls"
Namespace="Microsoft.SharePoint.Publishing.WebControls"

Assembly="Microsoft.SharePoint.Publishing,
Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"

%>
<%@ Register
Tagprefix="PublishingNavigation"

Namespace="Microsoft.SharePoint.Publishing.Navigation"
Assembly="Microsoft.SharePoint.Publishing,
Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"

%>

<%@ Page

language="C#"
Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c"
%>

<asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">



<SharePoint:ScriptLink name="<% $SPUrl:~SiteCollection/_layouts/jQuery/js/jquery-1.6.2.min.js%>" runat="server"/>

<SharePoint:ScriptLink name="<% $SPUrl:~SiteCollection/_layouts/jQuery/js/jquery-ui-1.8.16.custom.min.js%>" runat="server"/>


<SharePoint:CssRegistration name="<% $SPUrl:~SiteCollection/_layouts/SUPortal/Layout.css%>" runat="server"/>


<SharePoint:CssRegistration name="<% $SPUrl:~SiteCollection/_layouts/SUPortal/Theme.css%>" runat="server"/>

<SharePoint:CssRegistration name="<% $SPUrl:~SiteCollection/_layouts/jQuery/css/Aristo/jquery-ui-1.8.7.custom.css%>" runat="server"/>


</asp:Content>

<asp:Content ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">

<SharePoint:FieldValue ID="PageTitle"
FieldName="Title"
runat="server"

/>

</asp:Content>

<asp:Content ContentPlaceHolderId="PlaceHolderLeftActions" runat="server"></asp:Content>

<asp:Content ContentPlaceHolderId="PlaceHolderPageDescription" runat="server">

<SharePoint:ProjectProperty Property="Description"
runat="server"/>


</asp:Content>


<asp:Content ContentPlaceHolderId="PlaceHolderBodyRightMargin" runat="server">


<div height="100%"
class="ms-pagemargin"><img src="/_layouts/images/blank.gif" width="10" height="1" alt="" /></div>

</asp:Content>

<asp:Content ContentPlaceHolderId="PlaceHolderPageImage" runat="server"></asp:Content>


<asp:Content ContentPlaceHolderId="PlaceHolderNavSpacer" runat="server"></asp:Content>


<asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server"></asp:Content>

<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">


<div id="main">

<div id="colLeft">

<div id="zone1" class="topRow">

<WebPartPages:WebPartZone runat="server"
FrameType="TitleBarOnly"
ID="Zone1"

Title="Zone
1">


<ZoneTemplate>


</ZoneTemplate>

</WebPartPages:WebPartZone>

</div>

<div id="zone4">

<WebPartPages:WebPartZone runat="server"
FrameType="TitleBarOnly"
ID="Zone4"

Title="Zone
4">

<ZoneTemplate></ZoneTemplate>

</WebPartPages:WebPartZone>



</div>

</div>

<div id="colRight">

<div id="zone3" class="topRow">

<WebPartPages:WebPartZone runat="server"
FrameType="TitleBarOnly"
ID="Zone3"
Title="Zone
3">

<ZoneTemplate></ZoneTemplate>

</WebPartPages:WebPartZone>

</div>

<div id="zone6">

<WebPartPages:WebPartZone runat="server"
FrameType="TitleBarOnly"
ID="Zone6"

Title="Zone
6">


<ZoneTemplate></ZoneTemplate>

</WebPartPages:WebPartZone>

</div>

</div>

<div id="colMiddle">


<div id="colMiddleContainer">

<div id="zone2" class="topRow">


<WebPartPages:WebPartZone runat="server"
FrameType="TitleBarOnly"
ID="Zone2"

Title="Zone
2">

<ZoneTemplate></ZoneTemplate>

</WebPartPages:WebPartZone>

</div>

<div id="zone5">

<WebPartPages:WebPartZone runat="server"

FrameType="TitleBarOnly"
ID="Zone5"
Title="Zone
5">


<ZoneTemplate></ZoneTemplate>


</WebPartPages:WebPartZone>

</div>

</div>

</div>

</div>

<script type="text/javascript" language="javascript">if(typeof(MSOLayout_MakeInvisibleIfEmpty)
== "function") {MSOLayout_MakeInvisibleIfEmpty();}</script>

</asp:Content>

STEP 5:
Copy and paste the below code in elements.xml.
<?xml version="1.0"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<Module Url="$Resources:cmscore,List_Pages_UrlName;" List="101" Name="PageModule">


<
File Url="SamplePage.aspx" Type="GhostableInLibrary" Path="PageModule\SamplePage.aspx">


<
Property Name="Title" Value="My Custom Page"/> <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;"/>


<
Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview
Images/CustomPageLayout.png,
~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview
Images/CustomPageLayout.png
"/>

<Property Name="PublishingAssociatedContentType" Value=";#$Resources:cmscore,contenttype_articlepage_name;;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D;#"/>

<AllUsersWebPart WebPartOrder="1" WebPartZoneID="Zone1">

<![CDATA[

//
Put the exported webpart coding which is shown in Step 10

]]


</
AllUsersWebPart>

</File>

</Module>

</Elements>

STEP 6:
Open the page in site you needed to take back up of
the webpart




STEP 7:
Choose Edit webpart



STEP 7:

Choose Export all data in
Export Mode in Advanced category




STEP 8:

When Export is choosen the file will be saved has Wepartname.webpart.Open
the file in notepad copy the webpart code and paste in elements .xml .Check
Zone 1 id and webpartzoneid in samplepage.aspx is same.



STEP 9:

If single webpart exist in a page means copy and paste the
Open the
Elements.xml and paste the below coding

<AllUsersWebPart WebPartOrder="1" WebPartZoneID="Zone1">

<![CDATA[

<webParts>

<webPart
xmlns="http://schemas.microsoft.com/WebPart/v3">

<metaData>


<type name="VCSB.INTRANET.NewsInnerWebpart.NewsInnerWebpart,
VCSB.INTRANET, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=5c6b1aa174bc8565"
/>
<importErrorMessage>Cannot import this Web
Part.</importErrorMessage>

</metaData><data>
<properties>
<property name="AllowZoneChange"
type="bool">True</property>
<property name="ExportMode"
type="exportmode">All</property>

<property name="HelpUrl" type="string" />

<property name="Hidden" type="bool">False</property>

<property name="TitleUrl" type="string" />

<property name="Description" type="string">My
Visual WebPart</property>

<property name="AllowHide"
type="bool">True</property>

<property name="AllowMinimize" type="bool">True</property>

<property name="Title"
type="string">NewsInnerWebpart</property>

<property name="ChromeType"
type="chrometype">None</property>

<property name="AllowConnect"
type="bool">True</property>

<property name="Width" type="unit" />

<property name="Height" type="unit" />

<property name="HelpMode"
type="helpmode">Navigate</property>

<property name="CatalogIconImageUrl"
type="string" />

<property name="AllowEdit" type="bool">True</property>

<property name="TitleIconImageUrl" type="string"
/>

<property name="Direction"
type="direction">NotSet</property>

<property name="AllowClose"
type="bool">True</property>

<property name="ChromeState" type="chromestate">Normal</property>

</properties>

</data>

</webPart>
</webParts>

]]>


</
AllUsersWebPart>


STEP 10:
Repeat the process for multiple webparts and paste the below
coding in Elements.xml inside <File> tag, if multiple
webparts exist in same page ,rename zone1 to zone2.
<AllUsersWebPart WebPartOrder="1" WebPartZoneID="Zone2">


<![CDATA[
<webParts>
<webPart
xmlns="http://schemas.microsoft.com/WebPart/v3">

<metaData>

<type name="VCSB.INTRANET.NewsInnerWebpart.NewsInnerWebpart,
VCSB.INTRANET, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=5c6b1aa174bc8565"
/>
<importErrorMessage>Cannot import this Web
Part.</importErrorMessage>

</metaData>
<data>

<properties>

<property name="AllowZoneChange"
type="bool">True</property>


<property name="ExportMode"
type="exportmode">All</property>

<property name="HelpUrl" type="string" />

<property name="Hidden" type="bool">False</property>

<property name="TitleUrl" type="string" />

<property name="Description" type="string">My
Visual WebPart</property>
<property name="AllowHide"
type="bool">True</property>

<property name="AllowMinimize" type="bool">True</property>
<property name="Title"
type="string">NewsInnerWebpart</property>

<property name="ChromeType"
type="chrometype">None</property>

<property name="AllowConnect"
type="bool">True</property>

<property name="Width" type="unit" />

<property name="Height" type="unit" />


<property name="HelpMode"
type="helpmode">Navigate</property>

<property name="CatalogIconImageUrl"
type="string" />

<property name="AllowEdit" type="bool">True</property>


<property name="TitleIconImageUrl" type="string"
/>

<property name="Direction"
type="direction">NotSet</property>

<property name="AllowClose"
type="bool">True</property>

<property name="ChromeState" type="chromestate">Normal</property>

</properties>

</data>

</webPart>

</webParts>

]]>

</
AllUsersWebPart>


STEP 11:
Copy the below code in Elements.xml and rename
the url,path etc.
<File Url="SamplePage.aspx" Type="GhostableInLibrary" Path="PageModule\SamplePage.aspx">
<Property Name="Title" Value="My Custom Page"/> <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;"/>

<
Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview
Images/CustomPageLayout.png,
~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview
Images/CustomPageLayout.png
"/>

<
Property Name="PublishingAssociatedContentType" Value=";#$Resources:cmscore,contenttype_articlepage_name;;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D;#"/>

<
AllUsersWebPart WebPartOrder="1" WebPartZoneID="Zone1">

<![CDATA[
<webParts>
<webPart
xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="VCSB.INTRANET.NewsInnerWebpart.NewsInnerWebpart,
VCSB.INTRANET, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=5c6b1aa174bc8565"
/>
<importErrorMessage>Cannot import this Web
Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="AllowZoneChange"
type="bool">True</property>
<property name="ExportMode"
type="exportmode">All</property>
<property name="HelpUrl" type="string" />
<property name="Hidden"
type="bool">False</property>

<property name="TitleUrl" type="string" />

<property name="Description" type="string">My
Visual WebPart</property>

<property name="AllowHide"
type="bool">True</property>

<property name="AllowMinimize"
type="bool">True</property>
<property name="Title"
type="string">NewsInnerWebpart</property>

<property name="ChromeType" type="chrometype">None</property>

<property name="AllowConnect"
type="bool">True</property>

<property name="Width" type="unit" />

<property name="Height" type="unit" />

<property name="HelpMode"
type="helpmode">Navigate</property>

<property name="CatalogIconImageUrl"
type="string" />

<property name="AllowEdit"
type="bool">True</property>
<property name="TitleIconImageUrl" type="string"
/>

<property name="Direction"
type="direction">NotSet</property>
<property name="AllowClose"
type="bool">True</property>

<property name="ChromeState"
type="chromestate">Normal</property>
</properties>

</data>
</webPart>

</webParts>
]]>

</AllUsersWebPart>

</
File>


STEP 13:
Deploy the project to the particular site.Now the page and
webpart will be created automatically in the site.Go to Siteactions->View all site
content->Pages .Check the page and webpart exists in the site.

No comments:

Post a Comment