<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Webparts Archives - Blog IT</title>
	<atom:link href="https://blogit.create.pt/tag/webparts/feed/" rel="self" type="application/rss+xml" />
	<link>https://blogit.create.pt/tag/webparts/</link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Thu, 10 Jan 2019 12:46:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>Auto Hide WebPart &#8211; How to</title>
		<link>https://blogit.create.pt/antoniobrisson/2015/01/08/auto-hide-webpart-how-to/</link>
					<comments>https://blogit.create.pt/antoniobrisson/2015/01/08/auto-hide-webpart-how-to/#respond</comments>
		
		<dc:creator><![CDATA[António Brisson]]></dc:creator>
		<pubDate>Thu, 08 Jan 2015 16:08:14 +0000</pubDate>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Hide]]></category>
		<category><![CDATA[LimitedWebPartManager]]></category>
		<category><![CDATA[WebPart]]></category>
		<category><![CDATA[Webparts]]></category>
		<guid isPermaLink="false">http://blogit.create.pt/antoniobrisson/?p=411</guid>

					<description><![CDATA[<p>Next time I want my webpart to hide itself I won&#8217;t use: this.hidden = true; because that will result in: System.InvalidOperationException: The Visible property cannot be set on Web Part XXXXXXX Instead, I will do the following: SPFile myPage= SPContext.Current.File; SPLimitedWebPartManager limitedWebPartManager; //Get the page's limited webpart manager using (limitedWebPartManager = myPage.GetLimitedWebPartManager(PersonalizationScope.Shared)) { System.Collections.Generic.List configuratorWebParts [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/antoniobrisson/2015/01/08/auto-hide-webpart-how-to/">Auto Hide WebPart &#8211; How to</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Next time I want my webpart to hide itself I won&#8217;t use:</p>
<pre>this.hidden = true;
</pre>
<p>because that will result in:</p>
<pre>
System.InvalidOperationException: The Visible property cannot be set on Web Part XXXXXXX
</pre>
<p>Instead, I will do the following:</p>
<pre>
SPFile myPage= SPContext.Current.File;
SPLimitedWebPartManager limitedWebPartManager;


   //Get the page's limited webpart manager
   using (limitedWebPartManager = myPage.GetLimitedWebPartManager(PersonalizationScope.Shared))
   {
      System.Collections.Generic.List configuratorWebParts = limitedWebPartManager.WebParts.Cast().Where(webpart =&gt; webpart.Title == "TITLE OF MY WEBPART").ToList();

     if (configuratorWebParts.Count &gt; 0)
     {
       foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in configuratorWebParts)
       {
           webPart.Hidden = true;
           limitedWebPartManager.SaveChanges(webPart);
       }

      }
    }
</pre>
<p>and voila!</p>
<p>The post <a href="https://blogit.create.pt/antoniobrisson/2015/01/08/auto-hide-webpart-how-to/">Auto Hide WebPart &#8211; How to</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/antoniobrisson/2015/01/08/auto-hide-webpart-how-to/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Configure a native webpart  using another webpart</title>
		<link>https://blogit.create.pt/antoniobrisson/2014/12/23/configure-a-webpart-using-another-webpart/</link>
					<comments>https://blogit.create.pt/antoniobrisson/2014/12/23/configure-a-webpart-using-another-webpart/#respond</comments>
		
		<dc:creator><![CDATA[António Brisson]]></dc:creator>
		<pubDate>Tue, 23 Dec 2014 10:36:50 +0000</pubDate>
				<category><![CDATA[SharePoint 2013]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[ContentSearchWebPart]]></category>
		<category><![CDATA[LimitedWebPartManager]]></category>
		<category><![CDATA[Webparts]]></category>
		<guid isPermaLink="false">http://blogit.create.pt/antoniobrisson/?p=251</guid>

					<description><![CDATA[<p>Have you ever found a scenario where you would like to edit the configurations of native webpart but don&#8217;t want to mess it by creating a custom one? In this case you should consider the use of second webpart to do all the messy configurations. The following example shows how you you can create a custom [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/antoniobrisson/2014/12/23/configure-a-webpart-using-another-webpart/">Configure a native webpart  using another webpart</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Have you ever found a scenario where you would like to edit the configurations of native webpart but don&#8217;t want to mess it by creating a custom one? In this case you should consider the use of second webpart to do all the messy configurations.</p>
<p>The following example shows how you you can create a custom webpart that modifies the search query string of a content search web part that exists in the same page.</p>
<p><strong>Setup: Add a visual web part to your SharePoint project and add the Newton-King Json.NET reference to your project</strong></p>
<ol>
<li>On Visual Studio, open your project solution, right click your project folder and select &#8220;Add Item &#8220;</li>
<li>In the Add New Item menu select &#8220;Office/SharePoint&#8221; -&gt;  VisualWebPart, give a name ex: &#8220;WebPartConfigurator&#8221;</li>
<li>Add James Newton-King Json.NET .dll to your project.  This will make it extremely easy to edit the search query once you get it from the target webpart. (you can find it here: <a title="http://james.newtonking.com/json" href="http://james.newtonking.com/json">http://james.newtonking.com/json</a>)</li>
</ol>
<p><strong>Code: Follow 3 steps -&gt; Get the the LimitedWebPartManager, get the target content search  webpart, configure the  query string in the target content search webpart</strong>.</p>
<p>1. Add the following to your class header:</p>
<pre>using System.Linq; //For accessing the web part
using Newtonsoft.Json.Linq; // For editing the webparts search query (Json). Don't forget to add a reference to this lib on your project.</pre>
<p>2. Uncomment PageLoad method and add the following code:</p>
<pre>//Get the page
SPFile membersPage = SPContext.Current.File;
SPLimitedWebPartManager limitedWebpartManager;

//Get the page's Limited Web Part Manager using (limitedWebPartManager = membersPage.GetLimitedWebPartManager(PersonalizationScope.Shared)) {                     ////Gets all the the webpart with <strong>"YOUR_WEB_PART_NAME_HERE"</strong> name if they exist                     System.Collections.Generic.List&lt;System.Web.UI.WebControls.WebParts.WebPart&gt; searchWebParts = limitedWebPartManager.WebParts.Cast&lt;System.Web.UI.WebControls.WebParts.WebPart&gt;().Where(webpart =&gt; webpart.Title == <strong>"YOUR_WEB_PART_NAME"</strong>).ToList();                      ////If any web part is found runs the configuration method "ConfigureWebpart" on it                     if (membersWebParts.Count &gt; 0)                     {                         foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in membersWebParts)                         {                             ////Run the configuration method on your target webpart ConfigureWebPart(webPart); ////Save all the changes made to your target webpart!!!!!!!                             limitedWebPartManager.SaveChanges(webPart);                         }                                                  } } ////Updates all the changes made to the page elements membersPage.Update();</pre>
<p>3. Add your ConfigureWebPart method. In this case we will change the query string using Newtons-King Json.net lib.</p>
<pre>private void ConfigureMembersWebPart(System.Web.UI.WebControls.WebParts.WebPart webPart)
{
            ////Cast the webpart to a ContentSearchWebPart (ResultScriptWebPart in .Net)
            ResultScriptWebPart membersWebPart = (ResultScriptWebPart)webPart;
            
            ////Get the query object
            JObject query = JObject.Parse(membersWebPart.DataProviderJSON);
 
            ////Edit the query object
            query.Property("QueryTemplate").Value = <strong>"YOUR_QUERY_HERE"</strong>;
 
            ////Set the webpart's query object to the newly edited object.
            membersWebPart.DataProviderJSON = query.ToString();
}</pre>
<p><strong>Finishing: Add the custom web part to the page of the target webpart.</strong></p>
<p>The post <a href="https://blogit.create.pt/antoniobrisson/2014/12/23/configure-a-webpart-using-another-webpart/">Configure a native webpart  using another webpart</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/antoniobrisson/2014/12/23/configure-a-webpart-using-another-webpart/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
