tag:blogger.com,1999:blog-4877115129244072062024-03-12T17:28:30.085-07:00My World of SharePointAnonymoushttp://www.blogger.com/profile/02696059366179418604noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-487711512924407206.post-63591564697438533142014-06-13T13:41:00.001-07:002014-06-13T13:41:40.172-07:00SharePoint 2013 App: Handling App Install, Un-Install retry mechanism<span xmlns=''><p>Building SharePoint provider hosted apps we often come across scenario which require to provision SharePoint artefacts to host web and clean up once app is un-installed, obvious choice is to go with App events. I'm not going to bore your with how to create it there are tons of documentation available out there. Before we talk about "<span style='text-decoration:underline'><strong>retry mechanism</strong></span>" let's do a quick re-cap so that we all are on same page.<br /></p><p>App Event Receivers are implemented as WCF service deployed to remote web-application (ASP.NET MVC/Forms) which are called by SharePoint when app is installed/un-installed/upgraded. Imagine you have to provision quite a lot of artefacts perform certain validations this is quite a bit of task, and remember we are communicating back to SharePoint Host Web using Managed Client Object Model which is again a <span style='text-decoration:underline'><em>REST call</em></span> under the hood, so all operations are happening asynchronously.<br /></p><p>You implement all the logic and configure required permissions for App to create artefacts on Host Web while debugging App Installation you notice that App Install event is <span style='text-decoration:underline'><strong>called repeatedly</strong></span> and it again attempts to create the same artefact you already created, don't think that you forgot to configure you app properly or your app install event is behaving in weird fashion, <span style='text-decoration:underline'><strong>its actually by design </strong></span>(read: <a href='http://msdn.microsoft.com/en-us/library/office/fp179933(v=office.15).aspx'>Installing apps for SharePoint : Notes Section</a>) <br /></p><div><table border='0' style='border-collapse:collapse'><colgroup><col style='width:1663px'/></colgroup><tbody valign='top'><tr style='background: #ededed'><td style='padding-top: 10px; padding-left: 11px; padding-bottom: 5px; padding-right: 11px; border-top: none; border-left: none; border-bottom: none; border-right: none' vAlign='middle'><p style='margin-left: 7pt'><span style='color:#636363; font-family:Segoe UI; font-size:10pt'><strong>Note</strong></span></p></td></tr><tr><td style='padding-top: 10px; padding-left: 8px; padding-bottom: 10px; padding-right: 8px; border-top: none; border-left: none; border-bottom: solid #dbdbdb 0.25pt; border-right: none'><p style='margin-left: 7pt'><span style='color:#454545; font-family:Segoe UI; font-size:10pt'>Sometimes a temporary loss of a network connection can block installation. If installation fails for any reason, the installation infrastructure will <span style='background-color:yellow'><strong>retry three times</strong></span>. If it does not succeed, an indication of the failure appears in the UI. Users can retry the installation later.</span></p></td></tr></tbody></table></div><p><br /> </p><p>Cool, now that you know the reason behind "retry" let's discuss the probable solutions to handle this. The obvious way would be to keep a track of installation/un-install progress is to make use of persisted store and check the next time the "<em>Installation Infrastructure retries". </em>Let's explore the options for persisted store.<br /></p><ol><li>App Web Property Bag<br /></li><li>List<br /></li><li>Cache<br /></li><li>SQL Store<br /></li><li>File System<br /></li></ol><p>App Web property bag is a decent store, since during install event you have access to App Web Property bag (note: you cannot make changes to host web property bag (Tried With SiteCollection Manged rights)), this is still decent but not optimal as you have to make additional REST call to App Web which to perform CRUD operation on Web Property bag. This technique works fine when you work with Install Event, but as you apply the same technique to Un-Install event your code will <span style='text-decoration:underline'><strong>*break*</strong></span> because by design when the app is removed it deletes the associated App Web and hence you don't have the App Web Property Bag to store the un-install progress information.<br /></p><p>So what next, SharePoint List is again a decent option but it has to be on Host Web and will not be fast and high performing.<br /></p><p>As we talk about performance "Caching" comes to our mind, but before you start using your favourite search engine, please read (<a href='http://msdn.microsoft.com/en-us/library/ee230443(v=vs.110).aspx'>Caching Support for WCF Web HTTP Services</a>). I attempted to configure the Basic Web Http Service Caching and I was not able to deploy my App. So I had to rule out this option and had to fall back on App Web Property Bag, but was a partial implementation.<br /></p><p>Later I thought of configuring external Caching and utilize <span style='text-decoration:underline'><strong>Azure Managed Cache Service</strong></span> this gives a flexibility to come around the situation to Configure my WCF service for Caching and utilize external store. By this mechanism I was able to properly keep track progress of Install/Un-Install events.<br /></p><p>Azure Managed Cache Service is great, but I wanted something really simple coz I don't need a full blown distributed caching service just to keep progress!!!! <br /></p><p>This is great but my quest for making it lighter and configuration free made me to look out for another optimized cache store, and finally my search ended at "<a href='http://msdn.microsoft.com/en-us/library/vstudio/system.runtime.caching.objectcache'>ObjectCache</a> and <a href='http://msdn.microsoft.com/library/system.runtime.caching.memorycache.aspx'>MemoryCache</a>" these master pieces resides in "System.Runtime.Caching.dll" a quick note below (taken from links)<br /></p><p><br /> </p><div><table border='0' style='border-collapse:collapse'><colgroup><col style='width:1653px'/></colgroup><tbody valign='top'><tr style='background: #ededed'><td style='padding-top: 10px; padding-left: 11px; padding-bottom: 5px; padding-right: 11px; border-top: solid #bbbbbb 0.75pt; border-left: solid #bbbbbb 0.75pt; border-bottom: solid #bbbbbb 0.75pt; border-right: solid #bbbbbb 0.75pt' vAlign='middle'><p style='margin-left: 7pt'><span style='color:#636363; font-family:Segoe UI; font-size:10pt'><strong>Note</strong></span></p></td></tr><tr><td style='padding-top: 10px; padding-left: 8px; padding-bottom: 10px; padding-right: 8px; border-top: none; border-left: solid #bbbbbb 0.75pt; border-bottom: solid #bbbbbb 0.75pt; border-right: solid #bbbbbb 0.75pt'><p style='margin-left: 7pt'><span style='color:#2a2a2a; font-family:Segoe UI; font-size:10pt'>The MemoryCache class is similar to the ASP.NET <a href='http://msdn.microsoft.com/en-US/library/system.web.caching.cache.aspx'><span style='color:#03697a'>Cache</span></a> class. The MemoryCache class has many properties and methods for accessing the cache that will be familiar to you if you have used the ASP.NET <a href='http://msdn.microsoft.com/en-US/library/system.web.caching.cache.aspx'><span style='color:#03697a'>Cache</span></a> class. The main differences between the <a href='http://msdn.microsoft.com/en-US/library/system.web.caching.cache.aspx'><span style='color:#03697a'>Cache</span></a> and MemoryCache classes are that <span style='background-color:yellow'><strong>the MemoryCache class has been changed to make it usable by .NET Framework applications that are not ASP.NET applications</strong></span>. For example, the MemoryCacheclass has no dependencies on the <strong>System.Web</strong> assembly. Another difference is that you can create multiple instances of the MemoryCache class for use in the same application and in the same <a href='http://msdn.microsoft.com/en-US/library/system.appdomain.aspx'><span style='color:#03697a'>AppDomain</span></a> instance.</span></p></td></tr></tbody></table></div><p><br /> </p><p>System.Runtime.Caching.dll allows you to cache across all .Net apps, not just the IIS worker process.The highlighted point gave me a hint and I thought of trying it out and guess what it worked flawlessly it was eureka moment for me trust me.I did bit more study as I didn't new much about it and found it is quite performing (StackOverflow: <a href='http://stackoverflow.com/questions/11729023/memory-cache-net-4-0-performance-test-astonishing-result'>here</a>, <a href='http://stackoverflow.com/questions/3157340/performance-of-system-runtime-caching'>here</a>).<br /></p><p>So the ultimate winner is "<span style='background-color:yellow; text-decoration:underline'><strong>MemoryCache</strong></span>".<br /></p><p>Stay tuned, I'll shortly post the link to a sample code, but its cake walk just use your favourite search engine and you should be good to go.<br /></p><p>A quick one: <a href='http://www.allinsight.de/caching-objects-in-net-with-memorycache/'>http://www.allinsight.de/caching-objects-in-net-with-memorycache/</a><br /> </p><p>I didn't get any post talking about the retry mechanism so thought of putting it up. This is one of the problem to solve during SharePoint App Development.<br /></p><p>Thanks for being so patience as it was quite a theoretical article.<br /></p><p>If you have any comment, reach me at @AkhileshN<br /></p><p>Thanks<br /></p><p>/a/<br /></p><p> <br /> </p></span>Anonymoushttp://www.blogger.com/profile/02696059366179418604noreply@blogger.com3tag:blogger.com,1999:blog-487711512924407206.post-48172406621350707492014-04-24T04:29:00.001-07:002014-04-24T04:54:23.184-07:00SharePoint 2013: Require JS + SharePoint Hosted Apps<div dir="ltr" style="text-align: left;" trbidi="on">
<span xmlns=""></span><br />
<span xmlns="">During my early days I was bit scared writing JavaScript applications since I was so use to C# that I always try to find similar feature or offerings in JavaScript, I must say it took me sometime to really grasp the concepts because there are different ways to do a single task e.g. creating an object. I wanted to apply the basic principles of SOLID and found myself nowhere near to adhering to it. </span><br />
<h1>
<span xmlns="">SOLID: </span></h1>
<h2>
<span xmlns="">Single responsibility (SRP)<span style="font-size: 16pt;"><br /> </span></span></h2>
<h2>
<span xmlns="">Open Close (OCP)<span style="font-size: 16pt;"><br /> </span></span></h2>
<h2>
<span xmlns="">Liskov substitution principle (LSP)<span style="font-size: 16pt;"><br /> </span></span></h2>
<h2>
<span xmlns="">Interface segregation principle (ISP)</span></h2>
<h2>
<span xmlns="">Dependency inversion principle (DIP)</span></h2>
<span xmlns=""><br /> </span><br />
<span xmlns="">Well I'm too young in JavaScript still to apply all the principles but have at-least I now able to partially apply SRP, DIP up to a certain extent.</span><br />
<span xmlns="">Mostly I've seen in SharePoint Hosted apps developers writing a big fat JavaScript file which contains all the business logic and it becomes hard to read and debug (really I mean it). </span><br />
<span xmlns="">Modular programming helps a lot here but to achieve one must need to understand modules (class) and how they can be defined in JavaScript, splitting your logic in modules certainly helps you to achieve SRP but that still doesn't solves the root problem as you are still loading the entire module at once which doesn't gives you much benefit in terms of performance. Well loading individual modules can be loaded but you need a solution, and the answer to that is <span style="background-color: yellow;"><strong>Require.JS</strong></span>, it's an AMD (Asynchronous Module Definition implementation)</span><br />
<span xmlns="">Well if you are SharePoint developer then you'll argue that why we need another framework for loading individual module which is already provided by SharePoint via SP.SOD (<span style="text-decoration: underline;"><strong>Script on Demand</strong></span>).</span><br />
<span xmlns="">A quick comparison between both approaches </span><br />
<div>
<table border="0" style="border-collapse: collapse;"><colgroup><col style="width: 312px;"></col><col style="width: 312px;"></col></colgroup><tbody valign="top">
<tr style="background: #5b9bd5;"><td style="border-bottom: solid #5b9bd5 0.5pt; border-left: solid #5b9bd5 0.5pt; border-right: none; border-top: solid #5b9bd5 0.5pt; padding-left: 7px; padding-right: 7px;"><span style="color: white;"><strong>Require JS</strong></span></td><td style="border-bottom: solid #5b9bd5 0.5pt; border-left: none; border-right: solid #5b9bd5 0.5pt; border-top: solid #5b9bd5 0.5pt; padding-left: 7px; padding-right: 7px;"><span style="color: white;"><strong>SOD (Script On Demand)</strong></span></td></tr>
<tr style="background: #deeaf6;"><td style="border-bottom: solid #9cc2e5 0.5pt; border-left: solid #9cc2e5 0.5pt; border-right: solid #9cc2e5 0.5pt; border-top: none; padding-left: 7px; padding-right: 7px;"></td><td style="border-bottom: solid #9cc2e5 0.5pt; border-left: none; border-right: solid #9cc2e5 0.5pt; border-top: none; padding-left: 7px; padding-right: 7px;"></td></tr>
<tr><td style="border-bottom: solid #9cc2e5 0.5pt; border-left: solid #9cc2e5 0.5pt; border-right: solid #9cc2e5 0.5pt; border-top: none; padding-left: 7px; padding-right: 7px;"><strong>Highly Configurable</strong></td><td style="border-bottom: solid #9cc2e5 0.5pt; border-left: none; border-right: solid #9cc2e5 0.5pt; border-top: none; padding-left: 7px; padding-right: 7px;">No Configurations</td></tr>
<tr style="background: #deeaf6;"><td style="border-bottom: solid #9cc2e5 0.5pt; border-left: solid #9cc2e5 0.5pt; border-right: solid #9cc2e5 0.5pt; border-top: none; padding-left: 7px; padding-right: 7px;"><strong>Support to External Libraries</strong></td><td style="border-bottom: solid #9cc2e5 0.5pt; border-left: none; border-right: solid #9cc2e5 0.5pt; border-top: none; padding-left: 7px; padding-right: 7px;">No Exports for External Libraries</td></tr>
<tr><td style="border-bottom: solid #9cc2e5 0.5pt; border-left: solid #9cc2e5 0.5pt; border-right: solid #9cc2e5 0.5pt; border-top: none; padding-left: 7px; padding-right: 7px;"><strong>Inject, Exports, Shim</strong></td><td style="border-bottom: solid #9cc2e5 0.5pt; border-left: none; border-right: solid #9cc2e5 0.5pt; border-top: none; padding-left: 7px; padding-right: 7px;">No exports or injection support (natively loads the plugin)</td></tr>
<tr style="background: #deeaf6;"><td style="border-bottom: solid #9cc2e5 0.5pt; border-left: solid #9cc2e5 0.5pt; border-right: solid #9cc2e5 0.5pt; border-top: none; padding-left: 7px; padding-right: 7px;"><strong>Cleaner Dependency construct and resolution</strong></td><td style="border-bottom: solid #9cc2e5 0.5pt; border-left: none; border-right: solid #9cc2e5 0.5pt; border-top: none; padding-left: 7px; padding-right: 7px;">Complex construct to write dependencies within external libraries</td></tr>
</tbody></table>
</div>
<span xmlns=""><br /> </span><br />
<span xmlns="">I won't go in detail of how to setup require.js the documentation is itself self-explanatory trust me It took me a while to get this up but now it's a piece of cake !!!</span><br />
<span xmlns="">I'll talk about some important part of the configuration which is required so that a SharePoint developer can leverage functionality and get benefitted from best of both worlds </span><br />
<span xmlns="">The key aspect in require.js is configuration which is very powerful important attribute</span><br />
<span xmlns=""><br /> </span><br />
<span style="color: blue; font-family: Consolas;"><span style="background-color: white;"> <script src="https://gist.github.com/akhileshnirapure/11251451.js"></script> </span></span><br />
<span xmlns=""><br /> </span><br />
<span xmlns="">Above is my simple configuration for require.js </span><br />
<br />
<span style="color: red;">Please focus on deps and paths property</span><br />
<br />
<span xmlns=""><span style="background-color: cyan;">#1</span> Paths : The SharePoint JSOM runtime and main js to be loaded.</span><br />
<span xmlns=""><span style="background-color: lime;">#2</span> Deps : Deps setting causes the runtime and sp.js file to be loaded before any module is loaded, thus making required core and necessary classes available for developer to program.</span><br />
<span xmlns=""><br /> </span><br />
<h2>
<span xmlns="">The Module</span></h2>
<span xmlns="">I've created two module which fetches the current user display name from web and user profile</span><br />
<h2>
<span xmlns="">// Module for Web </span></h2>
<span style="color: blue; font-family: Consolas;"><span style="background-color: white;"><script src="https://gist.github.com/akhileshnirapure/11251482.js"></script></span></span><br />
<span xmlns=""><br /> </span><br />
<span xmlns=""><br /> </span><br />
<h2>
<span xmlns="">// Module for User Profile</span></h2>
<div>
<span style="color: #351c75;">User Profile Code : http://www.vrdmn.com/2013/02/sharepoint-2013-working-with-user.html <a class="ProfileHeaderCard-screennameLink u-linkComplex js-nav" href="https://twitter.com/vrdmn" style="background-color: #f5f8fa; font-family: Arial, sans-serif; line-height: 14px; text-decoration: none !important;">@<span class="u-linkComplex-target">vrdmn</span></a></span></div>
<span xmlns=""><br /> </span><br />
<span style="color: blue; font-family: Consolas;"><span style="background-color: white;"><script src="https://gist.github.com/akhileshnirapure/11251496.js"></script></span></span><br />
<span xmlns=""><br /> </span><br />
<span xmlns=""><br /> </span><br />
<h2>
<span xmlns="">The Start-up Module</span></h2>
<span xmlns=""><script src="https://gist.github.com/akhileshnirapure/11251510.js"></script></span><br />
<br />
<br />
<span style="background-color: lime; font-family: Consolas; font-size: 16px;">SP.SOD.loadMultiple([</span><span style="color: #a31515; font-family: Consolas; font-size: 16px;">'sp.js'<span style="color: black;">, <span style="color: #a31515;">'userprofile'<span style="color: black;">], ShowUserName);</span></span></span></span><br />
<br />
<span style="background-color: lime;">#1</span> The responsibility of ensuring that sp.js and sp.userprofile.js has been loaded is delegated to native SharePoint SOD module, the trick is to use SP.SOD.loadMultiple() which loads multiple modules and triggers the final function to be loaded.<br />
<span style="background-color: yellow;"><em>Note:</em></span> Here you can see the difference in the way require.js works and SOD works, require.js injects the dependencies as a parameters and SOD doesn't which gives more clear understanding of what to expect.<br />
<br />
<br />
I've already published the sample at github: <a href="https://github.com/akhileshnirapure/sp_hosted_app_requirejs">https://github.com/akhileshnirapure/sp_hosted_app_requirejs</a><br />
<br />
Feel free to fork and if you have any question the reach me at Twitter: @AkhileshN <br />
<h6>
Thanks</h6>
<h6>
Akhilesh Nirapure</h6>
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/02696059366179418604noreply@blogger.com0tag:blogger.com,1999:blog-487711512924407206.post-64785377383965327882014-02-01T00:05:00.000-08:002014-02-01T00:19:07.479-08:00SharePoint 2013 Client Side People Picker + SharePoint Hosted Apps + Knockout<p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 36pt" align="justify"><font size="3">It’s been quite a while playing with knockout, and trust me a great learning, every framework especially JavaScript has a stiff learning curve so as with knockout. Working on SharePoint Hosted App came across a valid use case of having a <u>people picker</u> to be part of application, integrating it using jQuery and as per Microsoft’s guideline it’s a cake walk (</font><a href="http://msdn.microsoft.com/en-us/library/jj713593(v=office.15).aspx"><font size="3">here</font></a><font size="3">). Well as I mentioned using with knockout was a bit of challenge, dealing with some really simple requirement can be scary sometime. So let’s look at it.</font></p> <p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 36pt" align="justify"><font size="3"><b style="mso-bidi-font-weight: normal">Requirement: </b>User should be able to lookup <b style="mso-bidi-font-weight: normal">user</b> and also the control should be pre-populated initially if data exists.</font></p> <p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3">Well I’m not going to go in details every bits of the code, I assume you already have some idea about how knockout works if not then a good starting point </font><a href="https://d.docs.live.net/1f816d036f021d89/Blog/knockoutjs.com"><font size="3">knockoutjs.com</font></a><font size="3">.</font></p> <p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3">Okay enough talk, in a nut shell what you need is a <u>custom binding handler</u> to work with.</font></p> <p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3">Before we get started, just a quick note, there is no one-size which fits all so the code which I’m going to show you will not suffice all the requirement, so my suggestion get inspiration and tweak as you need <span style="mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin; mso-char-type: symbol; mso-symbol-font-family: wingdings"><span style="mso-char-type: symbol; mso-symbol-font-family: wingdings">J</span></span></font></p><pre class="csharpcode">ko.bindingHandlers.kopeoplepicker = {<br /> init: <span class="kwrd">function</span> (element, valueAccessor, allBindingsAccessor) {<br /> <br /> <span class="kwrd">var</span> schema = {};<br /> schema[<span class="str">'PrincipalAccountType'</span>] = <span class="str">'User'</span>;<br /> schema[<span class="str">'SearchPrincipalSource'</span>] = 15;<br /> schema[<span class="str">'ShowUserPresence'</span>] = <span class="kwrd">true</span>;<br /> schema[<span class="str">'ResolvePrincipalSource'</span>] = 15;<br /> schema[<span class="str">'AllowEmailAddresses'</span>] = <span class="kwrd">true</span>;<br /> schema[<span class="str">'AllowMultipleValues'</span>] = <span class="kwrd">false</span>;<br /> schema[<span class="str">'MaximumEntitySuggestions'</span>] = 50;<br /> schema[<span class="str">'Width'</span>] = <span class="str">'280px'</span>;<br /><font style="background-color: #ffc000"> schema[<span class="str">"OnUserResolvedClientScript"</span>] = <span class="kwrd">function</span> (elemId, userKeys) {<br /> <span class="rem">// get reference of People Picker Control</span><br /> <span class="kwrd">var</span> pickerElement = SPClientPeoplePicker.SPClientPeoplePickerDict[elemId];<br /> <span class="kwrd">var</span> observable = valueAccessor();<br /> observable(pickerElement.GetControlValueAsJSObject()[0]);<br /> console.log(JSON.stringify(pickerElement.GetControlValueAsJSObject()[0]));<br /> };</font><br /> <br /> <span class="rem">// TODO: You can provide schema settings as options</span><br /> <span class="kwrd">var</span> mergedOptions = allBindingsAccessor().options || schema;<br /> <br /> <span class="rem">// Initialize the Control, MS enforces to pass the Element ID hence we need to provide </span><br /> <span class="rem">// ID to our element, no other options</span><br /> <font style="background-color: #ffff00"> <span class="kwrd">this</span>.SPClientPeoplePicker_InitStandaloneControlWrapper(element.id, <span class="kwrd">null</span>, mergedOptions);</font><br /> <br /> <span class="rem">// Force to Ensure User</span><br /> <font style="background-color: #9bbb59"> <span class="kwrd">var</span> userValue = ko.utils.unwrapObservable(valueAccessor());<br /> <span class="kwrd">var</span> pickerControl = SPClientPeoplePicker.SPClientPeoplePickerDict[element.id + <span class="str">"_TopSpan"</span>];<br /> <span class="kwrd">var</span> editId = <span class="str">"#"</span> + pickerControl.EditorElementId;<br /> jQuery(editId).val(userValue);<br /> <br /> <span class="rem">// Resolve the User</span><br /> pickerControl.AddUnresolvedUserFromEditor(<span class="kwrd">true</span>);</font><br /> <br /> }<br /> };<br /></pre><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><br /><p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3">Microsoft’s Client Side People picker relies heavily on <b style="mso-bidi-font-weight: normal">ID</b> of element for the implementation of its controls (editor, hidden fields, etc.) so we have to work with it in our custom binding handler I wanted to highlight this point because most of the examples you see with KO is able to work with the element property itself)</font></p><br /><p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%; mso-highlight: lime"><font style="background-color: #ffff00">#1</font></span> here we are initializing the People Picker Control.</font></p><br /><p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3"></font> </p><br /><p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%; mso-highlight: olive"><font style="background-color: #9bbb59">#2</font></span> here we are looking for People Picker control using a special suffix which helps us in grabbing the control and then finding out the Editor element id (which actually has the value) and then making use of <b style="mso-bidi-font-weight: normal">AddUnresolvedUserFromEditor</b>(true) to resolve the user passed in a value. E.g. </font><a href="mailto:akhilesh.nirapure@zevenseas.com"><font size="3">akhilesh.nirapure@zevenseas.com</font></a><font size="3">.</font></p><br /><p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3"></font> </p><br /><p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3"><span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%; mso-highlight: yellow"><font style="background-color: #ffc000">#3</font></span> here I’m providing my own implementation of what to do when we have a resolved user (from server) by using <b style="mso-bidi-font-weight: normal">“OnUserResolvedClientScript” </b>event. Again we here need to make use of People Picker control (we have to again find out by its id) and make use of <span style="background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%; line-height: 21pt; mso-bidi-font-size: 14.0pt; mso-highlight: yellow">GetControlValueAsJSObject()</span><span style="line-height: 21pt; mso-bidi-font-size: 14.0pt"> </span>method which gets us the result as JSON. </font></p><br /><p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3"> </font></p><br /><p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3">Well the above implementation is not full blown code with exceptional handling it can be used as a reference point of how we can work with various event.</font></p><br /><p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3"> </font></p><br /><p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3">I’ve uploaded my sample code on GitHub (</font><a href="https://github.com/akhileshnirapure/sp13peoplepickerko"><font size="3">https://github.com/akhileshnirapure/sp13peoplepickerko</font></a><font size="3">) please feel free to fork it and extend it as you want.</font></p><br /><p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3"> </font></p><br /><p class="MsoNormal" style="margin: 0cm 0cm 6pt; line-height: 21pt; text-indent: 0cm" align="justify"><font size="3">Akhilesh Nirapure (@AkhileshN)</font></p> Anonymoushttp://www.blogger.com/profile/02696059366179418604noreply@blogger.com0tag:blogger.com,1999:blog-487711512924407206.post-89049500338982546592013-12-13T11:26:00.000-08:002013-12-13T11:37:53.224-08:00Specification Pattern & Client Object Model in SharePoint 2013<font size="4"> <p><font size="4"></font> </p> <p>Hi, well if you guys are really wondering what does this mean and what problem it solves, let checkout the Google’s definition of it what it says</p> <p><a href="http://lh6.ggpht.com/-lYkJYPTaOCo/UqtiBAUK2VI/AAAAAAAACTc/Q-xPH04v88M/s1600-h/image%25255B4%25255D.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://lh4.ggpht.com/-qoh6nBT_r40/UqtiCvquDZI/AAAAAAAACTk/FV8UaxElosk/image_thumb%25255B2%25255D.png?imgmax=800" width="525" height="275"></a></p> <p><font size="4"></font> </p></font> <p><font size="4">But still you must be thinking as to where does this fits in our day to day work? </font></p> <p><font size="4">All business problem comes with a detailed specification, but when we have to translate that into code, we often don’t do a good job in crafting them, we tend to ignore a <strong><u>repetitive pattern</u></strong> which can solve handling such specification in much nicer and cleaner way.</font></p> <p><font size="4">Let’s take a simple example,</font></p> <p><font size="4">We have a requirement where we need to verify if a List has following property set Title, Description</font></p> <p><font size="4">A</font><font size="4">t simplest we would write a simple query</font></p> <p><font size="4"></font> </p> <p><font size="4">…..</font></p> <p><font size="4">Context _context = new Context(“Your_SharePoint_Site_Url”)</font></p> <p><font size="4">var result = _context.LoadQuery(_context.Web.Lists.Where(p=>p.Title == “SomeTitle”);</font></p> <p><font size="4">_context.ExecuteQuery();</font></p> <p><font size="4"></font> </p> <p><font size="4">well next day the requirement changes and you’ve been asked to write the similar condition for another module in project, what would u do, go and write a utility class copying over the above code and what !!! job done <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Smile" src="http://lh3.ggpht.com/-L3FXX43epUM/UqtiDZnWapI/AAAAAAAACTo/crnny0nGRYo/wlEmoticon-smile%25255B2%25255D.png?imgmax=800">.</font></p> <p><font size="4">and now you again get a requirement to validate Description property of the List, what would you do, simple copy over the function written in utility class change the where clause and you are done. Smart right? Well yes it really depends on the demand of situation how clean you really want the code.</font></p> <p><font size="4">According to me you are violating following principle from <a href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)" target="_blank">SOLID</a>, like Single responsibility principle, Open Close Principle.</font></p> <p><font size="4">So how can we write the above specification so that we don’t violate SRP and OCP. Well the answer is <a href="http://en.wikipedia.org/wiki/Specification_pattern" target="_blank">Specification Pattern</a></font></p> <p><font size="4">Enough talk let get to code</font></p> <p><font size="4">We define abstract specification class with an abstract method </font></p><pre class="csharpcode"> <span class="kwrd">public</span> <span class="kwrd">abstract</span> <span class="kwrd">class</span> SpecificationBase<TEntity><br /> {<br /> <span class="kwrd">public</span> <span class="kwrd">abstract</span> Expression<Func<TEntity, <span class="kwrd">bool</span>>> Predicate { get; } <br /> }</pre><br /><p><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /></p><br /><p><font size="4">Next we define concrete implementation of specification to which has single responsibility of defining the condition of one business problem.</font></p><pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> ByListTitle : SpecificationBase<List><br />{<br /> <span class="kwrd">private</span> <span class="kwrd">readonly</span> <span class="kwrd">string</span> _title;<br /><br /> <span class="kwrd">public</span> ByListTitle(<span class="kwrd">string</span> title)<br /> {<br /> _title = title;<br /> }<br /><br /> <span class="kwrd">public</span> <span class="kwrd">override</span> <font style="background-color: #ffff00">Expression<Func<List, <span class="kwrd">bool</span>>></font> Predicate<br /> {<br /> get<br /> {<br /> <font style="background-color: #ffff00"><span class="kwrd">return</span> p => p.Title == _title;</font><br /> }<br /> }<br />}</pre><br /><p><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><font size="4">Thus now we have a single class which know how to handle a where condition to find title. </font></p><br /><p><font size="4">Note this is very simple example, think of situation where your business requirement demands to get its data from various sources, so this class can explicitly request that dependencies for the condition to be formulated.</font></p><br /><p><font size="4">Lets go back and change our initial code to work with the specification pattern.</font></p><br /><p><font size="4"></font> </p><pre class="csharpcode">var titleSpecification = <span class="kwrd">new</span> ByListTitle();<br /><br />var result = _context.LoadQuery(_context.Web.Lists.Where(<span class="kwrd">new</span> ByListTitle(<span class="str">"Class"</span>).Predicate));<br /><br />_context.ExecuteQuery();<br /></pre><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><br /><p> </p><br /><p><font size="4">Note the above highlighted lines this is what usually your Where Clause takes a predicate.</font></p><br /><p><font size="4"></font> </p><br /><p><font size="4">Cool, well we haven’t done anything fancy here <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Smile" src="http://lh3.ggpht.com/-L3FXX43epUM/UqtiDZnWapI/AAAAAAAACTo/crnny0nGRYo/wlEmoticon-smile%25255B2%25255D.png?imgmax=800"> finding a title by explicitly writing additional classes makes no sense, but i just want to remind you this is just a very simplistic example, but the concept can be equally applied with similar codebase to any such business validation component.</font></p><br /><p><font size="4"></font> </p><br /><p><font size="4">Let say now we again got requirement to build a complex logic (calling a web-service and some additional regular expression classes) to validate the Description of the List <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Smile" src="http://lh3.ggpht.com/-L3FXX43epUM/UqtiDZnWapI/AAAAAAAACTo/crnny0nGRYo/wlEmoticon-smile%25255B2%25255D.png?imgmax=800"> and at the same time we would need to validate the Title. So what’s your take now, will you still say this is easy? i don’t think so, i think you’ll end up cluttering your code with all the logic required to make web-service call and calling the Regx utility.</font></p><br /><p><font size="4">Indeed, we must strive to stick to SRP and OCP and would not again want to violate such principle. So what would we do, create another specification class <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Smile" src="http://lh3.ggpht.com/-L3FXX43epUM/UqtiDZnWapI/AAAAAAAACTo/crnny0nGRYo/wlEmoticon-smile%25255B2%25255D.png?imgmax=800"> this now adheres to SRP and OCP.</font></p><pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> ByListDescription : SpecificationBase<List><br /> {<br /> <span class="kwrd">private</span> <span class="kwrd">readonly</span> <span class="kwrd">string</span> _description;<br /><br /> <span class="kwrd">public</span> ByListDescription(<span class="kwrd">string</span> description)<br /> {<br /> _description = description;<br /> }<br /><br /> <span class="kwrd">public</span> <span class="kwrd">override</span> Expression<Func<List, <span class="kwrd">bool</span>>> Predicate<br /> {<br /> get<br /> {<br /> <span class="rem">// Code to Call WebService </span><br /> <span class="rem">// Code to call RegX Utility</span><br /> <span class="kwrd">return</span> p => p.Description == _description;<br /> }<br /> }<br /> }</pre><pre class="csharpcode"><font size="4" face="Verdana">Now its so easy to add the code logic of calling web-service call and regx utility without cluttering up the code.</font></pre><pre class="csharpcode"><font size="4" face="Verdana">But wait we haven’t finished its just one part of requirement covered, we also wanted to combine both the specifications so that </font></pre><pre class="csharpcode"><font size="4" face="Verdana">we can validate both Title and Description at the same time.</font></pre><pre class="csharpcode"><font size="4" face="Verdana">Which essentially means we need to supply some kind of “And” logic here. Not to worry you don’t have to write additional code to set it up.</font></pre><pre class="csharpcode"><font size="4" face="Verdana">there is already a <a href="http://www.albahari.com/nutshell/predicatebuilder.aspx" target="_blank">Predicate Builder</a> present which can simplify and make your life easier <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Smile" src="http://lh3.ggpht.com/-L3FXX43epUM/UqtiDZnWapI/AAAAAAAACTo/crnny0nGRYo/wlEmoticon-smile%25255B2%25255D.png?imgmax=800"></font></pre><pre class="csharpcode"><font size="4" face="Verdana"></font> </pre><br /><p><font size="4">So how does our code now look like</font></p><pre class="csharpcode">var predicates = PredicateBuilder.True<List>();<br />predicates = predicates.And(<span class="kwrd">new</span> ByListTitle(<span class="str">"SomeTitle"</span>).Predicate)<br /> .And(<span class="kwrd">new</span> ByListDescription(<span class="str">"Some Des"</span>).Predicate);<br /><br />_context.LoadQuery(_context.Web.Lists.Where(predicates));</pre><pre class="csharpcode">_context.ExecuteQuery();</pre><br /><p><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /></p><br /><p><font size="4">Let me take some time to explain the above code using PredicateBuilder</font></p><br /><p><font size="4">with predicate builder, if you want to build “And” condition then you would need to specify the object, with True extension which in our case “List”. and then wire-up the predicates (i.e. specifications) with “And” extension. which builds a predicate chain.</font></p><br /><p><font size="4">That’s it, now you have written a clean code adhering to SOLID principle and testable, extensible and maintainable code.</font></p><br /><p><font size="4">Any new specification can be easily handled just by adding a new class and you are good to go.</font></p><br /><p><font size="4"></font> </p><br /><p><font size="4">One more additional helper method if you would like to build such numerous predicates then you can make use of a simple method which can allow you to aggregate all the specifications.</font></p><pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">bool</span> Validate(<span class="kwrd">params</span> SpecificationBase<T>[] specificationsBase)<br />{<br /> var pred = PredicateBuilder.True<T>();<br /> pred = specificationsBase.Aggregate(pred, (current, specificationBase) => current.And(specificationBase.Predicate));<br /> var result = _context.LoadQuery(_objectCollection.Where(pred));<br /> _context.ExecuteQuery();<br /> <span class="kwrd">return</span> result != null && result.Count() == 1;<br />}</pre><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><br /><p><font size="4">Thanks</font></p><br /><p><font size="4">Akhilesh Nirapure</font></p><br /><p><font size="4"></font></p> Anonymoushttp://www.blogger.com/profile/02696059366179418604noreply@blogger.com2tag:blogger.com,1999:blog-487711512924407206.post-73478758229816733292013-05-22T03:31:00.000-07:002013-05-22T03:53:23.235-07:00SharePoint 2013: SharePoint:AspMenu Styling (Quick Guide)<p><font size="3" face="Calibri Light">Quick note on how would you provide custom css to your Global Navigation in SharePoint 2013</font></p> <p><font size="3" face="Calibri Light"></font></p> <p><font size="3" face="Calibri Light">You need to set following properties to provide custom CSS to Menu Item otherwise they won’t be picked up by SharePoint ASP Menu Control</font></p> <p><font size="3" face="Calibri Light">1. UseSimpleRendering = False</font></p> <p><font size="3" face="Calibri Light">2. RenderingMode = List</font></p> <p><font size="3" face="Calibri Light"></font></p> <p><font size="3" face="Calibri Light">and then for your SharePoint AspMenu should look something like this</font></p><pre class="csharpcode"><font face="Calibri Light"><font size="3"><span class="kwrd"><</span><span class="html">SharePoint:AspMenu</span> <br /> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">UseSeparateCss</span><span class="kwrd">="false"</span> <br /> <span class="attr">AdjustForShowStartingNode</span><span class="kwrd">="False"</span> <span class="attr">StaticDisplayLevels</span><span class="kwrd">="2"</span> <br /> <span class="attr">AccessKey</span><span class="kwrd">="1"</span> <span class="attr">SkipLinkText</span><span class="kwrd">=""</span> <span class="attr">EnableViewState</span><span class="kwrd">="False"</span> <br /> <span class="attr">MaximumDynamicDisplayLevels</span><span class="kwrd">="0"</span> <br /> <span class="attr">DataSourceID</span><span class="kwrd">="topSiteMap"</span> <span class="attr">Orientation</span><span class="kwrd">="Horizontal"</span> <br /> </font></font><font face="Calibri Light"><font size="3"><strong><font style="background-color: #ffffff"><font style="background-color: #ffff00"><span class="attr">RenderingMode</span><span class="kwrd">="List"</span></font> <br /> </font><font style="background-color: #ffff00"><span class="attr">UseSimpleRendering</span><span class="kwrd">="False"</span></font></strong><br /> <span class="attr">ID</span><span class="kwrd">="TopNavigationMenu"</span><span class="kwrd">></span><br /><br /><font style="background-color: #cccccc"><span class="kwrd"><font style="background-color: #ffffff"> </font><</span><span class="html">StaticMenuItemStyle</span> <span class="attr">CssClass</span><span class="kwrd">="custom_class_1"</span> <span class="kwrd">/></span><br /><span class="kwrd"><font style="background-color: #ffffff"> </font><</span><span class="html">StaticSelectedStyle</span> <span class="attr">CssClass</span><span class="kwrd">="custom_class_2"</span> <span class="kwrd">/></span><br /></font></font></font></pre><pre class="csharpcode"><font face="Calibri Light"><font size="3"><br /><span class="kwrd"></</span><span class="html">SharePoint:AspMenu</span><span class="kwrd">></span></font></font></pre><pre class="csharpcode"><span class="kwrd"><font size="3" face="Calibri Light"></font></span></pre><pre class="csharpcode"><span class="kwrd"><font color="#000000" size="3" face="Calibri Light">Also if you want more control over how your Global Navigation should render then make use use of </font></span></pre><br /><p><font size="3" face="Calibri Light">1. <DynamicItemTemplate></DynamicItemTemplate><br>2. <StaticItemTemplate></StaticItemTemplate></font></p><br /><p><font size="3" face="Calibri Light"></font> </p><br /><p><font size="3" face="Calibri Light">Example</font></p><pre class="csharpcode"><font size="3" face="Calibri Light"> <span class="kwrd"><</span><span class="html">SharePoint:AspMenu</span> <br /> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">UseSeparateCss</span><span class="kwrd">="false"</span> <br /> <span class="attr">AdjustForShowStartingNode</span><span class="kwrd">="False"</span> <span class="attr">StaticDisplayLevels</span><span class="kwrd">="2"</span> <br /> <span class="attr">AccessKey</span><span class="kwrd">="1"</span> <span class="attr">SkipLinkText</span><span class="kwrd">=""</span> <span class="attr">EnableViewState</span><span class="kwrd">="False"</span> <br /> <span class="attr">MaximumDynamicDisplayLevels</span><span class="kwrd">="0"</span> <br /> <span class="attr">DataSourceID</span><span class="kwrd">="topSiteMap"</span> <span class="attr">Orientation</span><span class="kwrd">="Horizontal"</span> <br /> <span class="attr">RenderingMode</span><span class="kwrd">="List"</span> <br /> <span class="attr">UseSimpleRendering</span><span class="kwrd">="False"</span><br /> <span class="attr">ID</span><span class="kwrd">="TopNavigationMenu"</span><span class="kwrd">></span><br /> <br /> <span class="kwrd"><</span><span class="html">StaticItemTemplate</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">li</span> <span class="attr">class</span><span class="kwrd">="someclass"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">asp:HyperLink</span> <span class="attr">runat</span><span class="kwrd">="Server"</span> <span class="attr">CssClass</span><span class="kwrd">="SomeClass"</span> <span class="attr">ID</span><span class="kwrd">="c_menuitem"</span> <span class="attr">NavigateUrl</span><span class="kwrd">='<%# Eval("DataPath")%>'</span> <span class="attr">Text</span><span class="kwrd">='<%# Eval("Text")%>'</span> <span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">li</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">StaticItemTemplate</span><span class="kwrd">></span><br /> <br /> <span class="kwrd"></</span><span class="html">SharePoint:AspMenu</span><span class="kwrd">></span><br /><br /></font></pre><br /><p><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /></p><br /><p> </p><br /><p><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><font size="3" face="Calibri Light">Again if this doesn’t suits your requirement then get your navigation built using repeater control, Bhavin has an excellent example</font></p><br /><p><font size="3" face="Calibri Light"></font> </p><br /><p><a href="http://sharepoint2010customnavigation.blogspot.in/">http://sharepoint2010customnavigation.blogspot.in/</a></p><br /><p>With repeaters you will need to enable code blocks for master-page, here is how you do it</p><br /><p> </p><br /><p><a href="http://blog.shutupandcode.net/?p=646">http://blog.shutupandcode.net/?p=646</a></p><br /><p><a href="http://blog.technock.net/2013/03/code-blocks-are-not-allowed-in-this.html">http://blog.technock.net/2013/03/code-blocks-are-not-allowed-in-this.html</a></p><br /><p><font size="3" face="Calibri Light"></font> </p><pre class="csharpcode"><span class="kwrd"><font color="#000000" size="3" face="Calibri Light"></font></span> </pre><pre class="csharpcode"><span class="kwrd"><font size="3" face="Calibri Light">Hope this Helps !!!</font></span></pre><pre class="csharpcode"><span class="kwrd"><font size="3" face="Calibri Light"></font></span> </pre><pre class="csharpcode"><span class="kwrd"><font size="3" face="Calibri Light">Akhilesh Nirapure</font></span></pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><p><font size="2"></font></p><br /><p><font size="2"> </font></p> Anonymoushttp://www.blogger.com/profile/02696059366179418604noreply@blogger.com0tag:blogger.com,1999:blog-487711512924407206.post-1288882005620450922013-05-10T03:45:00.001-07:002013-05-10T03:46:03.203-07:00SharePoint 2013 : Service Account & Permissions required for Search Service Application<p> </p> <p><font size="3">Following Least Privilege Principle, i always wanted to nail down on permissions required to setup, manage and administer SharePoint, recently working quite a lot on ensuring how important it is working with a close environment which mimics Production environment which makes you sleep as you code won’t fail in such environment as you already tested and built code to very similar environment.</font></p> <p><font size="3">There has been good documentation on setting up SharePoint environment with detail account permission on Servers and SQL Server</font></p> <h3><a href="http://technet.microsoft.com/en-in/library/cc678863.aspx" target="_blank">Account permissions and security settings in SharePoint 2013</a></h3> <p><font size="3">I found it really hard to nail down for Search Service Application, People have done quite a lot work to get the PowerShell scripts to deploy different search topology but i couldn’t find one where they are talking about very specific permissions required.</font></p> <p><font size="3"></font></p> <p><font size="3">So i just wanted to document what I've experienced and got the search service application working without issues.</font></p> <p><font size="3"></font></p> <p><font size="3">I already have my SharePoint Farm Build with best Practice and followed Least Privilege Principle.</font></p> <p><font size="3">Note: As per Microsoft documentation the Farm Account doesn’t need to be a local administrator, but it is required when you need to perform User Profile Synchronization. With such exception I’ve tried to get very similar workaround working for search. I’m going to setup default search topology as this is my development environment but still wanted to keep it inline with Least Privilege Principle.</font></p> <p><font size="3"></font></p> <h4>Current environment</h4> <p><font size="3">DC Server : Windows 2012, Hosting Active Directory Domain Service, DNS</font></p> <p><font size="3">APP Server : Windows 2012, SharePoint 2013, SQL Server 2012, all the service Applications.</font></p> <p><font size="3"></font></p> <p><font size="3">For search Service Application, i created following Accounts and <strong><em><u>added them as Managed account.</u></em></strong></font></p> <p><font size="3"></font></p> <table cellspacing="0" cellpadding="0" width="722" border="1"> <tbody> <tr> <td valign="top" width="170"> <p><b>ACCOUNT</b></p></td> <td valign="top" width="550"> <p><b>Comments</b></p></td></tr> <tr> <td valign="top" width="170"> <p><b>WS_SEARCH_CRAWL</b></p></td> <td valign="top" width="550"> <p>Windows Service <b>OSearch15</b> / SharePoint Server Search 15</p></td></tr> <tr> <td valign="top" width="170"> <p><b>WS_SEARCH_HC</b></p></td> <td valign="top" width="550"> <p>Windows Service <b>SPSearchHostController</b> / SharePoint Search Host Controller</p></td></tr> <tr> <td valign="top" width="170"> <p><b>AP_SEARCH_QSS</b></p></td> <td valign="top" width="550"> <p>App pool for Query Site and Settings Web Service</p></td></tr> <tr> <td valign="top" width="170"> <p><b>AP_SEARCH_AWS</b></p></td> <td valign="top" width="550"> <p>App pool for Search Admin Web Service</p></td></tr> <tr> <td valign="top" width="170"> <p><b>SP_SEARCH_DC</b></p></td> <td valign="top" width="550"> <p>Service Account for Default Content Access </p></td></tr></tbody></table> <p><font size="3"></font></p> <p><font size="3">I like prefixing the accounts for what they are used for <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="http://lh6.ggpht.com/-oaEIgkuZ0fk/UYzPru1_NFI/AAAAAAAAB7c/0K8rWmnGljw/wlEmoticon-smile%25255B2%25255D.png?imgmax=800"></font></p> <p><font size="3"></font></p> <p><font size="3">Following is the step i performed for setting up Search Service Application.</font></p> <p><font size="3">1. <strong><u>Logged in as Farm account</u></strong>, note: my farm account is added to local admin group as it is needed for profile synchronization.</font></p> <p><font size="3">2. Assigned </font></p> <p><font size="3">WS_SEARCH_HC to <strong>Windows Service - Search Host Controller Service</strong></font></p> <p><font size="3">WS_SEARCH_CRAWL to <strong>Windows Service - SharePoint Server Search</strong></font></p> <p><strong><font size="3">CA—> Security –> Configure Managed Accounts.</font></strong></p> <p><font size="3">3. <strong><u>Started</u></strong> following services from </font></p> <p><font size="3"><strong>CA –> System Settings –> Mange Services on Server</strong></font></p> <blockquote> <p>Search Host Controller Service </p> <p>Search Query and Site Settings Service</p> <p>SharePoint Server Search </p></blockquote> <p><font size="3">4. Created Search Service Application and assigned respective service accounts (domain accounts) as below.</font></p> <p><font size="3"></font></p> <p>Search Service Account<font size="3"> : WS_SEARCH_CRAWL</font></p> <p>Application Pool for Search Admin Web Service<font size="3"> : AP_SEARCH_AWS</font></p> <p>Application Pool for Search Query and Site Settings Web Service<font size="3"> : AP_SEARCH_QSS</font></p> <p><font size="3">5. Restarted my App Server.</font></p> <p><font size="3">6. Started getting error in log as access denied for Search Host controller not able to access Search_Service_Application_DB_<em>{guid} </em>so explicitly added the login rights for <strong>WS_SEARCH_HC –</strong>> Search_Service_Application_DB_<em>{guid} </em>and also gave <strong>SPSearchDBAdmin </strong>role</font></p> <p><font size="3">7. Restarted the server again to ensure things are smooth, again got errors, and it happened to be <strong>WS_SEARCH_CRAWL </strong>account doesn’t have <strong>SPSearchDBAdmin </strong>role on all the four search database, so gave/added the role.</font></p> <p><font size="3">8. Again started getting error in ULS log which was not quire really sure why but was related to gatherer and this was only solved by giving <strong>WS_SEARCH_CRAWL </strong>Account giving Local Admin access. Note once you give local admin rights to any account you need to restart/log-in/log-off once to take it into affect, so i again i restarted.</font></p> <p><font size="3">9. Well till now i was not getting any error in my ULS log, so i thought of changing my default content access account to <strong>SP_SEARCH_DC <em>from </em>WS_SEARCH_CRAWL</strong> which has higher rights now.</font></p> <p><font size="3">10. slowly after sometime i started getting error in ULS where the WS_SEARCH_HC service was not able to login on <strong>Search_Service_Application_DB_<em>{GUID} </em></strong><em>which </em>i gave along with <strong>SPSearchDBAdmin</strong></font> <font size="3">role.</font></p> <p><font size="3"></font></p> <p><font size="3">11. I also need to give <strong>WS_SEARCH_HC </strong>permission on <strong>Search_Service_Application_LinksStore_<em>{guid} </em></strong>with <strong>SPSearchDBAdmin role.</strong></font></p> <p><strong><font size="3"></font></strong></p> <p><font size="3">12. Again i restarted, and did a full crawl i don’t see a single error in my event log and search is working absolutely fine.</font></p> <p><font size="3"></font></p> <p><font size="3">Hope to get more granular permission details from MS Documentations with proper justification soon so that should fix this workaround.</font></p> <p><font size="3"></font></p> <p><font size="3"></font></p> <p><font size="3">Thanks</font></p> <p><font size="3">Akhilesh</font></p> <p><font size="3"></font></p> <p><strong><font size="3"> </font></strong></p> Anonymoushttp://www.blogger.com/profile/02696059366179418604noreply@blogger.com4tag:blogger.com,1999:blog-487711512924407206.post-45237049952432485212013-04-01T11:22:00.000-07:002013-04-01T12:36:46.177-07:00SharePoint Hosted App, App Part, Document Library Upload.aspx / EditForm.aspx and “X-Frame-Options”<p> </p> <p>Before we drill and talk further would like to take sometime to explain different pieces in the topic. Lets first look at X-Frame-Options.</p> <p><strong><u>X-Frame-Options</u></strong> : In a simplest way this is a response header which tells browser (client) that the Website doesn’t want its page (which is currently being accessed) to be shown in a IFrame so as to prevent Clickjacking (Wikipedia : <a href="http://en.wikipedia.org/wiki/Clickjacking">http://en.wikipedia.org/wiki/Clickjacking</a>).</p> <p>So how do X-Frame-Options related to SharePoint App’s. Well every app developer in SharePoint 2013 is now familiar with the App Model Concept, it has its own App Web and isolated domain which is different then Hosting Web. </p> <p>To enhance security in SharePoint 2013 by default the “X-Frame-Options” header is sent back with response If you open up <strong>SPRequestModule</strong> in your fav decompiler you’ll find below statement written in PreSendRequestHeaders method, which gets added to every response if the AllowFraming Flag is not found in the current context items collection. </p> <div class="csharpcode"><pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">if</span> (!httpContext.Items.Contains(SPRequestModule.AllowFramingFlag) && SPRequestModule.ContextCompatibilityLevel != 14)</pre><pre><span class="lnum"> 2: </span> </pre><pre class="alt"><span class="lnum"> 3: </span> {</pre><pre><span class="lnum"> 4: </span> </pre><pre class="alt"><span class="lnum"> 5: </span> httpContext.Response.AddHeader(<span class="str">"X-FRAME-OPTIONS"</span>, <span class="str">"SAMEORIGIN"</span>);</pre><pre><span class="lnum"> 6: </span> </pre><pre class="alt"><span class="lnum"> 7: </span> }</pre></div><br /><p>Wait a minute what does that mean, so can we override this and make these line skip for those pages which explicitly marks and request for exception? yes this can be done simply by adding <em><u>AllowFraming WebPart</u></em> on to the page which you want to be able to be accessed from within IFrame. </p><br /><p><strong><u>"AllowFraming” Webpart</u></strong> does nothing but adds a simple statement in on load.</p><br /><div class="csharpcode"><pre class="alt"><span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnLoad(EventArgs e)</pre><pre>{</pre><pre class="alt"> <span class="kwrd">base</span>.OnLoad(e);</pre><pre> <span class="kwrd">if</span> (<span class="kwrd">this</span>.Context != <span class="kwrd">null</span> && !<span class="kwrd">this</span>.Context.Items.Contains(SPRequestModule.AllowFramingFlag))</pre><pre class="alt"> {</pre><pre> <span class="kwrd">this</span>.Context.Items.Add(SPRequestModule.AllowFramingFlag, <span class="str">"1"</span>);</pre><pre class="alt"> }</pre><pre> <span class="kwrd">if</span> (<span class="kwrd">this</span>.Visible)</pre><pre class="alt"> {</pre><pre> <span class="kwrd">this</span>.Visible = <span class="kwrd">false</span>;</pre><pre class="alt"> }</pre><pre>}</pre></div><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><br /><p>Consider a requirement, you have to upload a document to Document library which is in App, and this App is hosted in an App Part on some page, sound pretty simple. </p><br /><p>Just as expected you’ll just point to upload.aspx page of App Document Library which will look something like <a href="http://your-fancy-appurl/SomeApp/Lists/Documents/Forms/Upload.aspx">http://your-fancy-appurl/SomeApp/Lists/Documents/Forms/Upload.aspx</a> and using <strong><u>SP.UI.ModalDialog.showModalDialog</u></strong> you can open the page Upload page in SharePoint dialog box, but you’ll be presented with annoying error message that you cannot do that it’s because of X-Frame-Options header instructed the browser to do so.</p><br /><p><font style="background-color: #ffff00">Load denied by X-Frame-Options: </font><a href="http://your-fancy-app-url/_layouts/15/Upload.aspx?List={guid}&IsDlg=1"><font style="background-color: #ffff00">http://your-fancy-app-url/_layouts/15/Upload.aspx?List={guid}&IsDlg=1</font></a><font style="background-color: #ffff00"> does not permit cross-origin framing.</font></p><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><br /><p>Take a pause and you’ll be thinking is where did that _layout/15/Upload.aspx page came in picture (this I’ll explain in later post) and what it has to do with X-Frame-Options. </p><br /><p>Investigating further, I opened Upload.aspx under layouts folder and had a look if it has got <strong>AllowFraming </strong>webpart added to it or not, and i couldn’t locate so i added that entry manually and again gave a try and voila it worked !!!! because now the SPRequestModule –> X-Frame-Options won’t get executed. Next moving further after uploading document i was redirected to EditForm.aspx and i was again shown the same error (highlighted above) but this time instead of Upload.aspx it was EditForm.aspx, so where do you find this now, its actually stored in DataBase and not in layouts which you can just go and make an entry and make it work. </p><br /><p>Hold you horses dude, get back to basics, how does this EditForm.aspx gets created? If you look at the schema.xml file of document library the below section where it is all written</p><br /><div class="csharpcode"><pre class="alt"><span class="kwrd"><</span><span class="html">Forms</span><span class="kwrd">></span></pre><pre> <span class="kwrd"><</span><span class="html">Form</span> <span class="attr">Type</span><span class="kwrd">="DisplayForm"</span> <span class="attr">SetupPath</span><span class="kwrd">="pages\form.aspx"</span> <span class="attr">Url</span><span class="kwrd">="Forms/DispForm.aspx"</span> <span class="attr">WebPartZoneID</span><span class="kwrd">="Main"</span> <span class="kwrd">/></span></pre><pre class="alt"> <span class="kwrd"><</span><span class="html">Form</span> <span class="attr">Type</span><span class="kwrd">="EditForm"</span> <span class="attr">SetupPath</span><span class="kwrd">="pages\form.aspx"</span> <span class="attr">Url</span><span class="kwrd">="Forms/EditForm.aspx"</span> <span class="attr">WebPartZoneID</span><span class="kwrd">="Main"</span> <span class="kwrd">/></span></pre><pre> <span class="kwrd"><</span><span class="html">Form</span> <span class="attr">Type</span><span class="kwrd">="NewForm"</span> <span class="attr">Url</span><span class="kwrd">="Forms/Upload.aspx"</span> <span class="attr">WebPartZoneID</span><span class="kwrd">="Main"</span> <span class="kwrd">/></span></pre><pre><span class="kwrd"></</span><span class="html">Forms</span><span class="kwrd">></span></pre></div><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><br /><p>These forms are generated based on forms.aspx a template page which is in pages folder under 15/Template. Well now i again had a look to form.aspx and i again couldn’t locate the <strong>AllowFraming </strong>webpart, so i added one there again. So in order to regenerate my EditForm.aspx from the same form.aspx i need to re-deploy my app and now everything worked in my App in an App Part.</p><br /><p>But is it a good practice <strong>No !!! <img class="wlEmoticon wlEmoticon-ninja" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Ninja" src="http://lh6.ggpht.com/-PCkaA_vW7-c/UVnhx_J95LI/AAAAAAAAB4c/DUvr6_4aL40/wlEmoticon-ninja%25255B2%25255D.png?imgmax=800"></strong>you shouldn’t be modifying <img class="wlEmoticon wlEmoticon-baringteethsmile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Baring teeth smile" src="http://lh5.ggpht.com/-XKIDLStkquc/UVnhyChz4SI/AAAAAAAAB4k/uTtqmpTbceM/wlEmoticon-baringteethsmile%25255B2%25255D.png?imgmax=800">these pages to make these solution work, so what’s next</p><br /><p>A more elegant approach would be to use HttpModule and trap BeginRequest Event and make it work.</p><br /><div class="csharpcode"><pre class="alt"><span class="lnum"> 1: </span> <span class="kwrd">public</span> <span class="kwrd">class</span> ZSFramingModule : IHttpModule</pre><pre><span class="lnum"> 2: </span> {</pre><pre class="alt"><span class="lnum"> 3: </span> <span class="kwrd">public</span> <span class="kwrd">void</span> Dispose()</pre><pre><span class="lnum"> 4: </span> {</pre><pre class="alt"><span class="lnum"> 5: </span> }</pre><pre><span class="lnum"> 6: </span> </pre><pre class="alt"><span class="lnum"> 7: </span> <span class="kwrd">public</span> <span class="kwrd">void</span> Init(HttpApplication context)</pre><pre><span class="lnum"> 8: </span> {</pre><pre class="alt"><span class="lnum"> 9: </span> context.BeginRequest += OnBeginRequest;</pre><pre><span class="lnum"> 10: </span> </pre><pre class="alt"><span class="lnum"> 11: </span> }</pre><pre><span class="lnum"> 12: </span> </pre><pre class="alt"><span class="lnum"> 13: </span> <span class="kwrd">private</span> <span class="kwrd">void</span> OnBeginRequest(<span class="kwrd">object</span> sender, EventArgs e)</pre><pre><span class="lnum"> 14: </span> {</pre><pre class="alt"><span class="lnum"> 15: </span> HttpApplication l_application = (HttpApplication)sender;</pre><pre><span class="lnum"> 16: </span> </pre><pre class="alt"><span class="lnum"> 17: </span> <span class="kwrd">if</span> (l_application.Request.Url.ToString().ToLower().Contains(<span class="str">@"/_layouts/15/upload.aspx"</span>)</pre><pre><span class="lnum"> 18: </span> ||</pre><pre class="alt"><span class="lnum"> 19: </span> l_application.Request.Url.ToString().ToLower().Contains(<span class="str">@"editform.aspx"</span>))</pre><pre><span class="lnum"> 20: </span> {</pre><pre class="alt"><span class="lnum"> 21: </span> HttpContext.Current.Items.Add(<span class="str">"AllowFraming"</span>, <span class="str">"1"</span>);</pre><pre><span class="lnum"> 22: </span> }</pre><pre class="alt"><span class="lnum"> 23: </span> </pre><pre><span class="lnum"> 24: </span> }</pre><pre class="alt"><span class="lnum"> 25: </span> }</pre></div><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><br /><p>Hope this helps someone <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="http://lh4.ggpht.com/-d9joNLqtSwQ/UVnhy2YPRPI/AAAAAAAAB4s/IzpRnc-jdNc/wlEmoticon-smile%25255B2%25255D.png?imgmax=800"> </p><br /><p> </p><br /><p>Happy SharePointing !!!</p> Anonymoushttp://www.blogger.com/profile/02696059366179418604noreply@blogger.com3tag:blogger.com,1999:blog-487711512924407206.post-58607293854659637652012-11-21T07:01:00.001-08:002012-11-21T07:01:42.535-08:00 Side by Side – Virtual Box + Hyper-V (Windows 8 Pro) – Solve with Different Boot Configuration<div dir="ltr" style="text-align: left;" trbidi="on">
<w:sdt contentlocked="t" id="89512093" sdtgroup="t">
</w:sdt><br />
<div style="background: #F0F0F0; border-bottom: #E1E1E1; border-left: #F0F0F0; border-right: #F0F0F0; border-style: solid; border-top: #E1E1E1; border-width: 1.0pt; mso-element: para-border-div; padding: 1.0pt 2.0pt 1.0pt 2.0pt;">
<div class="PublishStatus" style="background-position: initial initial; background-repeat: initial initial;">
<br /></div>
</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Side by Side – Virtual Box + Hyper-V (Windows 8 Pro) – Solve with Different Boot Configuration</div>
<div class="MsoNormal">
As excited as you, I recently started working on Windows 8, wanted
to run my old Virtual Box VMs instead of converting/importing them in Hyper-V.
Without a hitch I installed Virtual Box on my fresh Windows 8 Pro, being very
curious and greedy I also wanted to use Hyper-V, but due to project work
couldn’t really get all my VM’s completely imported in Hyper-V, but for the
sake of future use, I added the feature of Hyper-V in Windows 8 Pro, assuming
that the Hyper-V technology from Virtual Box will run seamless as use to run on
earlier Windows 7 64bit, I started my VMs in Virtual Box and what a mess I was stopped
with an Error,<o:p></o:p></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://community.zevenseas.com/Blogs/Akhilesh/Lists/Photos/112112_1445_SidebySide2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://community.zevenseas.com/Blogs/Akhilesh/Lists/Photos/112112_1445_SidebySide2.png" /></a></div>
<div>
<br /></div>
<br />
<div class="MsoNormal">
What is this? Why can’t I run my old Virtual Box enabled
VM’s with Virtual Box any more. Well that’s something not a new story, to cut
the story short, it because both the technology won’t work side-by-side because
they rely on the same feature <b>Hypervision</b>,
and only one can use it at a time, so how do we solve the problem, this could
be easily solved by creating a different boot configuration with <b>hypervisorlaunchtype </b>status <b>OFF</b>, this shuts off Windows Hyper-V
technology and thus enables 3<sup>rd</sup> party like Virtual Box to use the
Hypervision.<o:p></o:p></div>
<h2>
Disabling “hypervisorlaunchtype” status<o:p></o:p></h2>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]-->1.<span style="font-size: 7pt;">
</span><!--[endif]-->Open the command prompt with (Run as Administrator)<o:p></o:p></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]-->2.<span style="font-size: 7pt;">
</span><!--[endif]-->Copy the current boot configuration and name it
something very relative <b>“Windows 8 (No
Hyper-V)”</b><o:p></o:p></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://community.zevenseas.com/Blogs/Akhilesh/Lists/Photos/112112_1445_SidebySide3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://community.zevenseas.com/Blogs/Akhilesh/Lists/Photos/112112_1445_SidebySide3.png" /></a></div>
<div>
<br /></div>
<br />
<div class="MsoNormal" style="margin-left: 36.0pt;">
Some points to note, <b>{current}</b> token resembles your current
boot configuration. FYI I had my Hyper-V enabled before following these steps,
so I assume you also will have hyper-v enabled on your Windows 8.<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 36.0pt;">
Once you copy, it will give back
you a Guid, which will be a unique identifier for your boot-configuration.<o:p></o:p></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]-->3.<span style="font-size: 7pt;">
</span><!--[endif]-->Now keep a note of the Guid (this will differ on
your machine) and perform further step, to disable the Hypervision <o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="background: yellow; mso-highlight: yellow;">C:\Windows\system32>bcdedit /set {<b>use-your-guid</b>} hypervisorlaunchtype OFF</span><o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<br />
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpLast">
The above step will disable the Hyper-v for
the copied boot configuration.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]-->4.<span style="font-size: 7pt;">
</span><!--[endif]-->Re-start your machine and this will ask you to choose
which operating system to load<o:p></o:p></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://community.zevenseas.com/Blogs/Akhilesh/Lists/Photos/112112_1445_SidebySide4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://community.zevenseas.com/Blogs/Akhilesh/Lists/Photos/112112_1445_SidebySide4.jpg" /></a></div>
<div>
<br /></div>
<br />
<div class="MsoNormal">
Choosing
the “Windows 8 (No Hyper-V) will again re-start your PC, to ensure that your
Windows 8 is booted up with Hyper-V disabled, and this will happen every time
you select this option. <o:p></o:p></div>
<div class="MsoNormal">
You can
switch to Windows 8 (which is Hyper-V enabled) by select the option on another
reboot, by doing this on contrary this won’t restart the PC again as in case of
Windows 8 (No Hyper-V) <o:p></o:p></div>
<div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]-->5.<span style="font-size: 7pt;">
</span><!--[endif]-->After restart it will as normal as using Windows
8 (with No Hyper-V).<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><u>Disclaimer: This
is not supported and not a best way to work, indeed an un-supported workaround
to enable both Virtual-Box and Hyper-V run side by side. Configure this at your
own risk, you are responsible for your actions.<o:p></o:p></u></b></div>
<div class="MsoNormal">
Hope this helps <span style="font-family: Wingdings; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-char-type: symbol; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-symbol-font-family: Wingdings;">J</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/02696059366179418604noreply@blogger.com0