I have a custom site definition, in an ONET.XML file. Can I get the URL and/or the Site name of the site that is being created and use it as a parameter/moniker in the onet.xml file?
Something like this:
<Modules>
<Module Name="Default" Url="" Path="">
<File Url="default.aspx" NavBarHome="True">
<AllUsersWebPart WebPartZoneID="Right" WebPartOrder="1">
<![CDATA[
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" xmlns:iwp="http://schemas.microsoft.com/WebPart/v2/Image">
<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ImageWebPart</TypeName>
<FrameType>None</FrameType>
<Title>[NAME OF MY SITE] or [URL]</Title>
Not to the best of my knowledge. I have used a solution where I add the webparts programmatically via the WebPartManager and then to set properties on that WebPart I use reflection.
An example to add the WP to a page:
public static void AddWebPart<T>(string webPartZone, SPFile page)
{
Type wpType = typeof(T);
AspNet.WebPart webPart =
(AspNet.WebPart)wpType.GetConstructor(new Type[0]).Invoke(new object[0]);
try
{
page.CheckOut();
SPLimitedWebPartManager wpManager =
page.GetLimitedWebPartManager(AspNet.PersonalizationScope.Shared);
wpManager.AddWebPart(webPart, "WP Zone Name", 0);
page.CheckIn("Added web part", SPCheckinType.MajorCheckIn);
and here is how to set proprties on webparts:
public static void SetWebPartProperties<T>(Dictionary<string, string> properties,
SPFile page)
{
Type wpType = typeof(T);
SPLimitedWebPartManager wpManager =
page.GetLimitedWebPartManager(AspNet.PersonalizationScope.Shared);
foreach (AspNet.WebPart wp in wpManager.WebParts)
{
if (wp.GetType() == wpType)
{
foreach (KeyValuePair<string, string> kvp in properties)
{
System.Reflection.PropertyInfo pi = wpType.GetProperty(kvp.Key);
if (pi.PropertyType == typeof(int))
pi.SetValue(wp, int.Parse(kvp.Value, CultureInfo.InvariantCulture), null);
else if (pi.PropertyType == typeof(bool))
pi.SetValue(wp, bool.Parse(kvp.Value), null);
pi.SetValue(wp, kvp.Value, null);
}
wpManager.SaveChanges(wp);
}
}
page.CheckIn("Changed properties of webpart", SPCheckinType.MajorCheckIn);
}