Part 1 - Part 2 - Part 3 - Part 4 - Part 5 - Part 6 - Part 7 - Part 8
As promised I've uploaded the 3rd webcast to show how Chapter 3 is implemented. I've also posted the sample code below for you guys to pick and chose as you please. Click here to watch the webcast (NEW 32MB swf - 40mins) .
The .zip of the solution can be downloaded here.
Site Collection Feature.xml
<?xml version="1.0" encoding="utf-8"?>
<!--Created by STSDEV at 4/06/2008 8:39:34 PM-->
<Feature
Id="AE49F2FB-1B45-483A-A8C4-DFD698780ACA"
Title="A sample feature: jeremythake.tvshowschedule"
Description="This SharePoint solution was created by the STSDEV utility (http://codeplex.com/stsdev)"
Version="1.0.0.0"
Scope="Site"
Hidden="false"
ImageUrl="jeremythake.tvshowschedule\AfricanPith32.gif"
ReceiverAssembly="jeremythake.tvshowschedule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8eb9a930004f2f1a"
ReceiverClass="jeremythake.tvshowschedule.FeatureReceiver" xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest
Location="elements.xml" />
<ElementManifest
Location="schedule\listdefinition.xml" />
<ElementFile Location="schedule\allitems.aspx"/>
<ElementFile Location="schedule\dispform.aspx"/>
<ElementFile Location="schedule\editform.aspx"/>
<ElementFile Location="schedule\ListDefinition.xml"/>
<ElementFile Location="schedule\newform.aspx"/>
<ElementFile Location="schedule\schema.xml"/>
</ElementManifests>
</Feature>
Things to note:
- I manually added the <ElementFile>'s for the ListTemplate generated by Solution generator.
- I also added the <ElementManifest> for the ListTemplate also
Site Collection Elements.xml
<?xml version="1.0" encoding="utf-8"?>
<!--Created by STSDEV at 4/06/2008 8:39:34 PM-->
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field Type="Number" DisplayName="Season Number" Required="FALSE" Group="jeremythake" ID="{3ae02cdc-b29e-43f4-99e6-96fa1eca9c3f}" SourceID="{7d46c011-b7e1-406f-873e-24af7b2f4fbb}" StaticName="Season_x0020_Number" Name="Season Number" xmlns="http://schemas.microsoft.com/sharepoint/">
</Field>
<Field Type="Number" DisplayName="Episode Number" Required="FALSE" Group="jeremythake" ID="{70b38d61-0241-4d45-af60-df23d458567c}" SourceID="{7d46c011-b7e1-406f-873e-24af7b2f4fbb}" StaticName="Episode_x0020_Number" Name="Episode Number" xmlns="http://schemas.microsoft.com/sharepoint/">
</Field>
<Field Type="DateTime" DisplayName="Air Date" Required="FALSE" Format="DateOnly" Group="jeremythake" ID="{e48d08af-a1ce-4647-be18-3360f3a2ce17}" SourceID="{7d46c011-b7e1-406f-873e-24af7b2f4fbb}" StaticName="Air_x0020_Date" Name="Air Date" xmlns="http://schemas.microsoft.com/sharepoint/">
</Field>
<ContentType ID="0x0100608C182017B2664787866C9B81660001" Name="Schedule" Group="jeremythake" Version="3" xmlns="http://schemas.microsoft.com/sharepoint/" Hidden="False" ReadOnly="False" ResourceFolder="Schedule" Sealed="False">
<Folder TargetName="_cts/Schedule" />
<FieldRefs>
<FieldRef ID="{c042a256-787d-4a6f-8a8a-cf6ab767f12d}" Name="ContentType" />
<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Required="TRUE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" />
<FieldRef ID="{3ae02cdc-b29e-43f4-99e6-96fa1eca9c3f}" Name="Season_x0020_Number" />
<FieldRef ID="{70b38d61-0241-4d45-af60-df23d458567c}" Name="Episode_x0020_Number" />
<FieldRef ID="{e48d08af-a1ce-4647-be18-3360f3a2ce17}" Name="Air_x0020_Date" />
</FieldRefs>
</ContentType>
</Elements>
Things to note:
- This was a simple case of adding the <Field>'s and <ContentType> generated from the Feature Generator application
Site Collection ListDefinition.xml
<?xml version="1.0" encoding="utf-8"?>
<Elements Id="ebc1f1f6-5f70-4771-ab22-608c6e0ae005" xmlns="http://schemas.microsoft.com/sharepoint/">
<ListTemplate Name="Schedule" DisplayName="Schedule" Description="" BaseType="0" Type="100" OnQuickLaunch="TRUE" SecurityBits="11" Sequence="410" Image="/_layouts/images/itgen.gif" />
</Elements>
Things to note:
- This was a auto generated by the Solution Generator tool (with VSeWSS)
Site Collection Schema.xml
<?xml version="1.0" encoding="utf-8"?>
<List Name="Schedule" Title="Schedule" Description="" Direction="0" BaseType="0" Url="Lists/Schedule" FolderCreation="FALSE" EnableContentTypes="TRUE" Type="100" Id="ebc1f1f6-5f70-4771-ab22-608c6e0ae005" xmlns="http://schemas.microsoft.com/sharepoint/">
<MetaData>
<Views>
...
</Views>
</Fields>
...
</Fields>
<ContentTypes>
<ContentTypeRef ID="0x0100608C182017B2664787866C9B81660001" />
<ContentTypeRef ID="0x0120" />
</ContentTypes>
<Forms>
<Form Type="DisplayForm" Url="DispForm.aspx" WebPartZoneID="Main" />
<Form Type="EditForm" Url="EditForm.aspx" WebPartZoneID="Main" />
<Form Type="NewForm" Url="NewForm.aspx" WebPartZoneID="Main" />
</Forms>
</MetaData>
</List>
Things to note:
- This was a auto generated by the Solution Generator tool (with VSeWSS)
- Had to delete <ContentType> and add <ContentTypeRef>
Web Feature.xml
<?xml version="1.0" encoding="utf-8"?>
<!--Created by STSDEV at 4/06/2008 8:39:34 PM-->
<Feature
Id="5FF56A65-A901-4C4B-AFA8-BA721C98712B"
Title="A sample feature: jeremythake.tvshowscheduleweb"
Description="This SharePoint solution was created by the STSDEV utility (http://codeplex.com/stsdev)"
Version="1.0.0.0"
Scope="Web"
Hidden="false"
ImageUrl="jeremythake.tvshowschedule\AfricanPith32.gif"
ReceiverAssembly="jeremythake.tvshowschedule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8eb9a930004f2f1a"
ReceiverClass="jeremythake.tvshowschedule.WebFeatureReceiver" xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest
Location="elements.xml" />
</ElementManifests>
</Feature>
Web Elements.xml
<?xml version="1.0" encoding="utf-8"?>
<!--Created by STSDEV at 4/06/2008 8:39:34 PM-->
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance
Title="Schedule"
FeatureId="AE49F2FB-1B45-483A-A8C4-DFD698780ACA"
OnQuickLaunch="TRUE"
TemplateType="100"
Url="Schedule" />
</Elements>
Things to note:
- This was manually written and they're all pretty similar. The intellisense with VSeWSS will make this easier.
Web FeatureReceiver.cs
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Navigation;
using Microsoft.SharePoint.Administration;
using System.Globalization;
using Microsoft.SharePoint.Publishing.WebControls;
namespace jeremythake.tvshowschedule {
public class WebFeatureReceiver : SPFeatureReceiver {
public override void FeatureActivated(SPFeatureReceiverProperties properties) {
//Add CQWP
using (SPSite site = new SPSite("http://jt-asuslaptop/"))
{
using (SPWeb web = site.AllWebs["Test"])
{
SPFile file = web.GetFile(web.Url + "/default.aspx");
SPLimitedWebPartManager webpartsMng = file.GetLimitedWebPartManager(PersonalizationScope.User);
ContentByQueryWebPart contentByQueryWebPart = new ContentByQueryWebPart();
contentByQueryWebPart.Title = "Schedule";
contentByQueryWebPart.WebUrl = web.Url;
SPListTemplateCollection listTemplates = web.Site.RootWeb.ListTemplates;
SPListTemplate template = listTemplates["Schedule"];
contentByQueryWebPart.BaseType = string.Empty;
contentByQueryWebPart.ServerTemplate = Convert.ToString((int)template.Type, CultureInfo.InvariantCulture);
contentByQueryWebPart.CommonViewFields = "Air_x0020_Date,AirDate;Episode_x0020_Number,Episode;Season_x0020_Number,Season";
contentByQueryWebPart.ItemStyle = "ScheduleStyle";
webpartsMng.AddWebPart(contentByQueryWebPart, "Right", 0);
}
}
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) {
/* no op */
}
public override void FeatureInstalled(SPFeatureReceiverProperties properties) {
/* no op */
}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties) {
/* no op */
}
}
}
Things to note:
- This was manually written. But you can use this as a start and modify it from here. I'll be writing more complicated ones in future posts.