Listing 3: C# • Inside the WebPart Config File

SharePoint uses this file to identify the WebPart; it contains information about the assembly, the "installation fault" message shown in the event of an error, and the title and description of the WebPart. Note the use of place holders (between the dollar characters) to set the name of the VS project dynamically. The Public Key Token needs to be added manually.

<?xml version="1.0" encoding="utf-8"?>
<webParts>
	<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
	<metaData>
		<type name="$safeprojectname$.$safeprojectname$, 
			$safeprojectname$, Version=1.0.0.0, 
			Culture=neutral, PublicKeyToken
			=YourPublicKeyToken" />
	<importErrorMessage>Error Importing 
		WebPart</importErrorMessage>
	</metaData>
	<data>
		<properties>
		<property name="Title" 
			type="string">$safeprojectname$</property>
		<property name="Description" 
			type="string">$safeprojectname$</property>
		</properties>
	</data>
	</webPart>
</webParts>

	<ProjectItem ReplaceParameters=
		"true" TargetFileName=
		"WebPart1.webpart">WebPart1.webpart</ProjectItem>

// In the file WebPart.csproj you need to add:
// <None Include="WebPart1.webpart" />
// under the row where the Temporary.snk file is added 
// ("<None // Include="Properties\Temporary.snk" />").

// The minimal syntax required for WebPart1.webpart 
// file is:

<?xml version="1.0" encoding="utf-8"?>
<webParts>
	<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
		<metaData>
		<type name="$safeprojectname$.$safeprojectname$, 
			$safeprojectname$, Version=1.0.0.0, Culture=neutral, 
			PublicKeyToken=YourPublicKeyToken" /> 
		<importErrorMessage>Error Importing 
			WebPart</importErrorMessage>
		</metaData>
		<data>
			<properties>
				<property name="Title" 
					type="string">$safeprojectname$</property>
				<property name="Description" 
					type="string">$safeprojectname$</property>
			</properties>
		</data>
	</webPart>
</webParts>
comments powered by Disqus

Featured

Subscribe on YouTube