<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Inconvenient provisioning of Content Query Web Part instances</title>
	<atom:link href="http://blog.mastykarz.nl/inconvenient-provisioning-content-query-web-part-instances/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mastykarz.nl/inconvenient-provisioning-content-query-web-part-instances/</link>
	<description>Innovation Matters &#124; SharePoint Server MVP &#124; ISSN 2210-9390</description>
	<lastBuildDate>Thu, 09 Feb 2012 05:22:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Simon</title>
		<link>http://blog.mastykarz.nl/inconvenient-provisioning-content-query-web-part-instances/comment-page-1/#comment-111690</link>
		<dc:creator>Simon</dc:creator>
		<pubDate>Wed, 21 Dec 2011 09:29:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mastykarz.nl/inconvenient-provisioning-content-query-web-part-instances/#comment-111690</guid>
		<description>It appears that in some circumstances this is also necessary when programatically adding a customised content query webpart from the webparts gallery using code like this:

SPListItemCollection webParts = webPartGallery.GetItems(query);
if (webParts == null &#124;&#124; webParts.Count == 0)
{
    throw new ArgumentOutOfRangeException(&quot;webPartName&quot;, &quot;Webpart not found in gallery&quot;);
}

SPListItem item = webParts[0];

string error;
XmlTextReader reader  = new XmlTextReader(item.File.OpenBinaryStream());
WebPart webPart = manager.ImportWebPart(reader, out error);

if (string.IsNullOrEmpty(error))
{
    manager.AddWebPart(webPart, &quot;ZoneId&quot;, zoneIndex);
}</description>
		<content:encoded><![CDATA[<p>It appears that in some circumstances this is also necessary when programatically adding a customised content query webpart from the webparts gallery using code like this:</p>
<p>SPListItemCollection webParts = webPartGallery.GetItems(query);<br />
if (webParts == null || webParts.Count == 0)<br />
{<br />
    throw new ArgumentOutOfRangeException(&#034;webPartName&#034;, &#034;Webpart not found in gallery&#034;);<br />
}</p>
<p>SPListItem item = webParts[0];</p>
<p>string error;<br />
XmlTextReader reader  = new XmlTextReader(item.File.OpenBinaryStream());<br />
WebPart webPart = manager.ImportWebPart(reader, out error);</p>
<p>if (string.IsNullOrEmpty(error))<br />
{<br />
    manager.AddWebPart(webPart, &#034;ZoneId&#034;, zoneIndex);<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

