Add webpart to default WSS page via feature - sharepoint

I've developed a custom web part. I would like to create a feature that when activated via STSADM adds the web part to the default page of a WSS Site. Hopefully this can be done without writing code.
This webpart is meant to de deployed to the web application's bin directory and featurereceiver must be installed to the GAC. The AllUsersWebPart element looks promising, but I can't figure out how to get it to work.
TIA,
jt

The AllUsersWebPart tag allow us to insert one webpart and place it where we want using WebPartOrder and WebPartZone attributes. The content of the tag is the dwp (or webpart) of your webpart. For example, for a dwp:
<AllUsersWebPart WebPartZoneID="MiddleLeftZone" WebPartOrder="0">
<![CDATA[
<WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
<FrameType>None</FrameType>
<AllowMinimize>true</AllowMinimize>
<IsVisible>true</IsVisible>
<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
<ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
<Value><iframe src="$Resources:Summary_Url;" frameborder="0" scrolling="no" width="100%" height="100%"></iframe></Value>
</Content>
<PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>
]]>
</AllUsersWebPart>
For a webpart:
<AllUsersWebPart WebPartZoneID="MiddleLeftZone" WebPartOrder="1">
<![CDATA[
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="MyClass, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f3b9d1137704f880" />
<importErrorMessage>No se puede importar este elemento Web.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="AllowClose" type="bool">False</property>
<property name="AllowMinimize" type="bool">False</property>
<property name="AllowConnect" type="bool">True</property>
<property name="ChromeType" type="chrometype">None</property>
<property name="Hidden" type="bool">False</property>
<property name="AllowEdit" type="bool">False</property>
<property name="AllowZoneChange" type="bool">False</property>
<property name="MissingAssembly" type="string">No se puede importar este elemento Web.</property>
<property name="ChromeState" type="chromestate">Normal</property>
</properties>
</data>
</webPart>
</webParts>
]]>
</AllUsersWebPart>
I haven't tried before but I think it can be done once the web has been created. Try it and tell us.

Related

wix installer / Create web-site and assign the new or exisiting web app pool

i try create a new web-site using wix installation. it's ok there is no problem but i cannot assign a new or existing web app pool to new web-site. iis:website tag does not contains WebAppPool attribute. How can i assign web app pool to web-site. You can see my code bellow.
thanks for helping.
<Component Id="WEB_SITE_CONFIGURE_COMPONENT" Guid="{35087032-D049-48C8-BCAD-1FEFD0C06A25}" NeverOverwrite="yes" Shared="yes" Permanent="yes" Transitive="yes">
<Condition><![CDATA[WEBSITE_INSTALLTYPE<>2]]></Condition>
<CreateFolder Directory="WEBSITE_FOLDER"/>
<iis:WebSite Id="WEB_SITE" Description="[WEBSITE_NAME]" SiteId="*" Directory="WEBSITE_FOLDER" ConfigureIfExists="yes" AutoStart="yes" StartOnInstall="yes">
<iis:WebAddress Id="AllUnassigned" Port="[WEBSITE_PORT]" />
</iis:WebSite>
<RegistryValue Root="HKLM" Key="$(var.DefaultRegistryKey)" Name="ConfigSite" Value="1" Type="string"></RegistryValue>
</Component>
<Component Id="WEBAPP_POOL_CONFIGURE_COMPONENT" Guid="{316738A6-26A2-4C14-9AB9-B2066E3FA288}" KeyPath="yes" Permanent="yes" Transitive="yes">
<Condition><![CDATA[(WEBSITE_INSTALLTYPE=0) OR (USE_CUSTOM_WEBSITE_FOLDER=1)]]></Condition>
<iis:WebAppPool Id="APP_POOL" Name="[WEBAPP_POOL_NAME]" ManagedPipelineMode="Classic" ManagedRuntimeVersion="v4.0"/>
<RegistryValue Root="HKLM" Key="$(var.DefaultRegistryKey)" Name="ConfigPool" Value="1" Type="string"></RegistryValue>
</Component>
<Component Id="WEPAPP_CONFIGURE_COMPONENT" Guid="{F95B024E-B6B6-4E6C-AC35-9B1086FC3521}" Transitive="yes">
<Condition><![CDATA[(WEBSITE_INSTALLTYPE<>2) AND ((WEBSITE_INSTALLTYPE=0) OR (USE_CUSTOM_WEBSITE_FOLDER=1))]]></Condition>
<iis:WebVirtualDir Id="VIRTUAL_DIR" Alias="[WEB_APP_NAME]" Directory="WWW_FOLDER" WebSite="WEB_SITE">
<iis:WebApplication Id="WEB_APP" Name="[WEB_APP_NAME]" WebAppPool="APP_POOL"/>
</iis:WebVirtualDir>
<RegistryValue Root="HKLM" Key="$(var.DefaultRegistryKey)" Name="ConfigVirtualDir" Value="1" Type="string"></RegistryValue>
</Component>
With the help of the following articles I have come up with a working installer in which a new AppPool can be created or an existing AppPool can be selected.
Creating a Web Application Installer with WIX 3.5 and Visual Studio 2010–Part 1
Web Application Installer in WiX
WiX and DTF: Using a Custom Action to list available web sites on IIS
Installing a Web Application to an Existing IIS Website using Wix3
In short:
Create a Website element in your Product element:
<Product>
<iis:WebSite Id="SelectedWebSite" Description="[WEBSITE_DESCRIPTION]" Directory="INSTALLFOLDER" SiteId="[WEBSITE_ID]">
<iis:WebAddress Id="AllUnassigned" Port="80" />
</iis:WebSite>
</Product>
Create an Include WebSites.wxi with the following content:
<?xml version="1.0" encoding="utf-8"?>
<Include>
<Property Id="WEBSITE_DESCRIPTION">
<RegistrySearch Id="WebSiteDescription" Name="WebSiteDescription" Root="HKLM" Key="SOFTWARE\!(loc.CompanyName)\[ProductName]\Install" Type="raw" />
</Property>
<Property Id="WEBSITE_ID">
<RegistrySearch Id="WebSiteID" Name="WebSiteID" Root="HKLM" Key="SOFTWARE\!(loc.CompanyName)\[ProductName]\Install" Type="raw" />
</Property>
<Property Id="WEBSITE_PATH">
<RegistrySearch Id="WebSitePath" Name="WebSitePath" Root="HKLM" Key="SOFTWARE\!(loc.CompanyName)\[ProductName]\Install" Type="raw" />
</Property>
<Property Id="WEBSITE_VD">
<RegistrySearch Id="WebSiteVD" Name="WebSiteVD" Root="HKLM" Key="SOFTWARE\!(loc.CompanyName)\[ProductName]\Install" Type="raw" />
</Property>
<CustomTable Id="AvailableWebSites">
<Column Id="WebSiteID" Category="Identifier" PrimaryKey="yes" Type="int" Width="4"/>
<Column Id="WebSiteDescription" Category="Text" Type="string" PrimaryKey="no"/>
<Column Id="WebSitePath" Category="Text" Type="string" PrimaryKey="no" Nullable="yes"/>
<Row>
<Data Column="WebSiteID">0</Data>
<Data Column="WebSiteDescription">Dummy</Data>
<Data Column="WebSitePath"></Data>
</Row>
</CustomTable>
</Include>
Create the CustomAction described here.
Create a wxs file with your AppPool:
<?xml version="1.0" encoding="UTF-8"?>
<Wix
xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension">
<Fragment>
<Component Id="WebVirtualDirComponent" Guid="PUT-GUID-HERE" Directory="INSTALLFOLDER" KeyPath="yes">
<iis:WebAppPool
Id="YourAppPoolName"
Name="[VD][WEBSITE_ID]"
ManagedRuntimeVersion="v4.0"
IdleTimeout="0"
RecycleMinutes="0"
ManagedPipelineMode="integrated"/>
<iis:WebVirtualDir Id="VDir" Alias="[VD]" Directory="INSTALLFOLDER" WebSite="SelectedWebSite">
<iis:WebApplication Id="NotizBrowserWebApp" WebAppPool="YourAppPoolName" Name="[VD][WEBSITE_ID]" />
<iis:WebDirProperties Id="NotizBrowserProps" AnonymousAccess="no" WindowsAuthentication="yes" DefaultDocuments="-" Execute="yes" Script="yes" Read="yes"/>
</iis:WebVirtualDir>
</Component>
</Fragment>
</Wix>
Late answer, but hopefully someone will be benefited with this.
You don't need a CustomAction to make this work.
It is simple like this:
<Component Id="WebSite" Guid="PUT-YOUR-GUID-HERE">
<CreateFolder/>
<iis:WebSite Id="WebSite" Directory="WebSiteRoot" Description="[WEBSITEDESCRIPTION]" >
<iis:WebApplication Id="WebSiteApplication" Name="[WEBSITEDESCRIPTION]" WebAppPool="MyAppPool" />
</iis:WebSite>
<iis:WebAppPool Id="MyAppPool" Name="[APPPOOLNAME]" ManagedRuntimeVersion="v4.0"/>
</Component>
You need to update the "Internal" WebApplication of the WebSite.
You don't need to have the "WebSite Description" and "WebApplication Name" equal, but that will help you to understand what is going on.

Giving Persistence Database setting on first deploy of JSF application

I have developed a JSF application with JPA using Netbeans and GlassFish. It is working fine within the Netbeans environment. Now I want to deploy it a remote GlassFish server with different database settings. Is there any method I can give the database settings when it is deployed in the server for the first time and save the settings afterwords?
I have a persistence.xml file, but the database settings are there in glassfish-resources.xml file.
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="HOPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>dsHiLap2</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
glassfish-resources.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-resource enabled="true" jndi-name="jdbc/ho" object-type="user" pool-name="connectionPoolHo">
<description/>
</jdbc-resource>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="connectionPoolHo" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="URL" value="jdbc:derby://localhost:1527/healthofice"/>
<property name="serverName" value="localhost"/>
<property name="PortNumber" value="1527"/>
<property name="DatabaseName" value="healthofice"/>
<property name="User" value="healthoffice"/>
<property name="Password" value="health"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="dsDec2012" object-type="user" pool-name="connectionPoolHo"/>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="derby_net_ho_hoPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
<property name="portNumber" value="1527"/>
<property name="databaseName" value="ho"/>
<property name="User" value="ho"/>
<property name="Password" value="ho"/>
<property name="URL" value="jdbc:derby://localhost:1527/ho"/>
<property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="dsHo" object-type="user" pool-name="derby_net_ho_hoPool"/>
<jdbc-resource enabled="true" jndi-name="ds2013Feb" object-type="user" pool-name="connectionPoolHo"/>
<jdbc-resource enabled="true" jndi-name="drHoBuddhikaDesktop1" object-type="user" pool-name="derby_net_ho_hoPool"/>
<jdbc-resource enabled="true" jndi-name="drHoBuddhikaLaptop1" object-type="user" pool-name="connectionPoolHo"/>
<jdbc-resource enabled="true" jndi-name="dsHiLap" object-type="user" pool-name="derby_net_ho_hoPool"/>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="derby_net_ho1_ho1Pool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
<property name="portNumber" value="1527"/>
<property name="databaseName" value="ho1"/>
<property name="User" value="ho1"/>
<property name="Password" value="ho1"/>
<property name="URL" value="jdbc:derby://localhost:1527/ho1"/>
<property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="dsHiLap2" object-type="user" pool-name="derby_net_ho1_ho1Pool"/>
</resources>
You need to use GlassFish deployment plan to configure different connection pool settings for your remote GlassFish server, since glassfish-resources.xml defined application-scoped resources. The application-scoped connection pool is only created during the application deployment. Please see To Deploy an Application or Module by Using a Deployment Plan. Basically your supply a remote server version of glassfish-resources.xml (following module-name.gf-dd-name naming convention) in the deploymentplan.jar.
Another option is not to use the application-scoped resource. You can define the connection pool/data source through the GlassFish Admin console.

Add webparts to sitedefinition

I created a custom sitedefinition. In my sitedefition i want to activate a custom feature (i add the guid into my onet.xml).
My custom feature for adding the webpart to the page is creating an error. The error is default.aspx is not found. I thought a page in a sitedefition is created first. After that feature will be activate. Why i receive an error?
SPLimitedWebPartManager collWebParts = web.GetLimitedWebPartManager("default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
collWebParts.AddWebPart(CustomWebPart, "MainLeft", 1);
collWebParts.SaveChanges(CustomWebPart);
collWebParts.Web.Dispose();
You'd better add you webparts in modules in onet.xml. Just add the tag and use the tag to provision your particular webparts.
A simple sample:
<Modules>
<Module Name="DefaultBlank" Url="" Path="">
<File Url="default.aspx" Path="default.aspx">
<AllUsersWebPart WebPartOrder="0" WebPartZoneID="Right" ID="g_bdef0b56_c2f4_4c5a_bc39_2908a0f61410">
<![CDATA[<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="***.LatestDiscussionsWebPart.LatestDiscussionsWebPart, ***, Version=1.0.0.0, Culture=neutral, PublicKeyToken=20cca094e7d0240a" />
<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">Latest Discussions WebPart</property>
<property name="AllowHide" type="bool">True</property>
<property name="AllowMinimize" type="bool">True</property>
<property name="Title" type="string">Latest Discussions </property>
<property name="ChromeType" type="chrometype">Default</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>
</Module>
Good luck.

Provisioning a default.aspx page to use a custom page layout

I have a custom site definition I created that deploys a couple of custom page layouts. Does anyone know what needs to be done so that when a user uses my site definition to create a site, their default.aspx page is created using my custom page layout?
Below is the module section of my site definition:
<Modules>
<Module Name="DefaultHome" Url="$Resources:osrvcore,List_Pages_UrlName;" Path="">
<File Url="default.aspx" Type="GhostableInLibrary" >
<Property Name="Title" Value="Test Home Page" />
<Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/MyCustomPageLayout.aspx, My Custom PageLayout" />
<Property Name="ContentType" Value="$Resources:cmscore,contenttype_welcomepage_name;" />
<Property Name="PublishingPageContent" Value="Welcome to the My Test Publishing Site" />
</File>
</Module>
</Modules>
In your onet.xml file you need to set the DefaultPageLayout property like below
<!-- Publishing Feature -->
<Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">
<Properties xmlns="http://schemas.microsoft.com/sharepoint/">
<Property Key="WelcomePageUrl" Value="$Resources:osrvcore,List_Pages_UrlName;/Default.aspx" />
<Property Key="ChromeMasterUrl" Value="~SiteCollection/_catalogs/masterpage/MyMasterPage.master"/>
<Property Key="SimplePublishing" Value="True" />
<Property Key="VersioningOnPages" Value="Major" />
<Property Key="RequireCheckoutOnPages" Value="False" />
<Property Key="AvailablePageLayouts" Value="~SiteCollection/_catalogs/masterpage/MyPageLayout.aspx:~SiteCollection/_catalogs/masterpage/MyPageLayout.aspx"/>
<Property Key="DefaultPageLayout" Value="~SiteCollection/_catalogs/masterpage/MyPageLayout.aspx"/>
<Property Key="AvailableWebTemplates" Value="ENTERWIKIRBKC#2;"/>
<Property Key="AllowSpacesInNewPageName" Value="false"/>
</Properties>
</Feature>
The default.aspx page in SiteDefinition created by VS inherits from webpart page. Make sure that you delete all the code and add the below. This has worked for me.
<%# Page Inherits="Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%# Reference VirtualPath="~TemplatePageUrl" %>
<%# Reference VirtualPath="~masterurl/custom.master" %>

MOSS 2007 - Custom Aspx Pages Created With Feature

(I have also asked this question on SharePoint Overflow.)
I have a SharePoint feature I'm using to add some custom aspx files to the Pages Library.
When I activate the feature, I can visit the pages in-browser and they are visible in SPDesigner, but when I "View All Site Content" they are not there.
Why is this the case?
The Feature's Elements File:
<?xml version="1.0" encoding="utf-8"?>
<Elements Id="9e85eb79-6d8d-4ff3-b0d4-64d55c3bb577" xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="Pages" Url="Pages">
<File Path="Example.aspx" Url="Example.aspx" IgnoreIfAlreadyExists="False">
<Property Name="Title" Value="The Example" />
<Property Name="ContentType" Value="Page" />
</File>
</Module>
</Elements>
The Aspx File:
<%# Page language="C#" Inherits="System.Web.UI.Page,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" MasterPageFile="~masterurl/default.master"%>
<%-- deliberately left empty -->
(yup, it's empty!)
Addendum
When I "visit the pages in-browser" I mean navigate to their URLs manually: http://myserver:PORT/subsite/Pages/Example.aspx
When I "View All Site Content" I am looking at the contents of the "Pages" list: http://myserver:PORT/subsite/Pages/Forms/AllItems.aspx
I got an answer on SharePoint Overflow:
The File Node should have Type="GhostableInLibrary", because "Pages" is a document library. When ever you provision a file in a document library you need to have ghostableinlibrary set.
eg:
<?xml version="1.0" encoding="utf-8"?>
<Elements Id="9e85eb79-6d8d-4ff3-b0d4-64d55c3bb577" xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="Pages" Url="Pages">
<File Path="Example.aspx" Url="Example.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="False">
<Property Name="Title" Value="The Example" />
<Property Name="ContentType" Value="Page" />
</File>
</Module>
</Elements>
So in the end the XML I'm using is...
<?xml version="1.0" encoding="utf-8"?>
<Elements Id="9e85eb79-6d8d-4ff3-b0d4-64d55c3bb577" xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="Pages" Url="Pages">
<File Path="Example.aspx" Url="Example.aspx" IgnoreIfAlreadyExists="False" Type="GhostableInLibrary">
<Property Name="Title" Value="The Example" />
</File>
</Module>
</Elements>

Resources