tag:blogger.com,1999:blog-88367539599388962872024-03-12T21:41:21.501-07:00Learn SharePoint, .NET, Silverlight, SQL here.Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.comBlogger104125tag:blogger.com,1999:blog-8836753959938896287.post-14976430281984958242013-06-21T05:36:00.002-07:002013-06-21T05:36:17.543-07:00SharePoint 2013 Interview Questions for Developers – Part 2<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="color: #333333; font-family: Lora, serif; font-size: 16px; line-height: 25px; margin-bottom: 25px; padding: 0px;">
<strong>Q41: Whats are the new Delegate Controls in SharePoint 2013?<br />Ans: </strong>In SharePoint 2013, three New Delegate Controls have been Introduced for the purpose of displaying the new Top Suite bar (with links SkyDrive, NewsFeed,Sync,follow). These Controls are -</div>
<ul style="color: #333333; font-family: Lora, serif; font-size: 16px; line-height: 25px; margin: 0px; padding: 0px 0px 25px;">
<li style="background-image: url(http://www.learningsharepoint.com/wp-content/themes/eleven40/images/list.png); background-position: 0% 0%; background-repeat: no-repeat no-repeat; list-style-type: none; margin: 0px 0px 5px 20px; padding: 0px 0px 0px 15px; word-wrap: break-word;">SuiteBarBrandingDelegate delegate Control</li>
<li style="background-image: url(http://www.learningsharepoint.com/wp-content/themes/eleven40/images/list.png); background-position: 0% 0%; background-repeat: no-repeat no-repeat; list-style-type: none; margin: 0px 0px 5px 20px; padding: 0px 0px 0px 15px; word-wrap: break-word;">SuiteLinksDelegate delegate Control</li>
<li style="background-image: url(http://www.learningsharepoint.com/wp-content/themes/eleven40/images/list.png); background-position: 0% 0%; background-repeat: no-repeat no-repeat; list-style-type: none; margin: 0px 0px 5px 20px; padding: 0px 0px 0px 15px; word-wrap: break-word;">PromotedActions Delegate Control</li>
</ul>
<div style="color: #333333; font-family: Lora, serif; font-size: 16px; line-height: 25px; margin-bottom: 25px; padding: 0px;">
<strong>Q42: What is SuiteBarBrandingDelegate delegate Control used for?<br />Ans:</strong> SuiteBarBrandingDelegate Delegate Control is responsible for displaying ‘SharePoint’ or ‘Office 365′ text on top left of the new SharePoint 2013 site (in the blue bar). This text can only be replaced by Overriding SuiteBarBrandingDelegate Delegate Control with a custom Custom Control Created using Visual Studio.</div>
<div style="color: #333333; font-family: Lora, serif; font-size: 16px; line-height: 25px; margin-bottom: 25px; padding: 0px;">
<strong>Q43: What is SuiteLinksDelegate delegate Control used for?<br />Ans:</strong> SuiteLinksDelegate Delegate Control is responsible for displaying Links “NewsFeed, SkyDrive and Sites” in top right of the new SharePoint 2013 site (in the blue bar). These Links can be replaced by Overriding SuiteLinksDelegate Delegate Control using a Custom Control Created using Visual Studio.</div>
<div style="color: #333333; font-family: Lora, serif; font-size: 16px; line-height: 25px; margin-bottom: 25px; padding: 0px;">
<strong>Q44: What is PromotedActions delegate Control used for?<br />Ans:</strong> PromotedActions Delegate Control is responsible for displaying Links “Share,Follow,SYNC,EDIT” in top right below SuiteLinksDelegate Control. These Links can be replaced by Overriding PromotedActions Delegate Control using a Custom Control Created using Visual Studio.</div>
<div style="color: #333333; font-family: Lora, serif; font-size: 16px; line-height: 25px; margin-bottom: 25px; padding: 0px;">
<strong>Q46: What are Callout Popups in SharePoint 2013.<br />Ans:</strong> Similar to Dialog framework in SharePoint 2010, Microsoft has added a new Callout Popup framework to Create Hover Popups that you know as Preview Windows as well.These Notification\Tooltip\Help (whatever you call it..) Callout Popups can be fully Customized to add Custom Text & Actions for guiding End-users.</div>
<div style="color: #333333; font-family: Lora, serif; font-size: 16px; line-height: 25px; margin-bottom: 25px; padding: 0px;">
<strong>Q47: Is Callout Popups a replacement to Dialogs in SharePoint 2013.<br />Ans:</strong> No. Dialog Framework still exists.</div>
<div style="color: #333333; font-family: Lora, serif; font-size: 16px; line-height: 25px; margin-bottom: 25px; padding: 0px;">
<strong>Q48: Can we view PDF files in Callout Popups?<br />Ans:</strong> Yes. A Custom Result type and Display template would be needed<strong>.</strong></div>
<div style="color: #333333; font-family: Lora, serif; font-size: 16px; line-height: 25px; margin-bottom: 25px; padding: 0px;">
<strong>Q49: What’s the new “SPField.JSLink” property used for?<br />Ans:</strong> New “SPField.JSLink” property has been added to help specify any external JavaScript file Containing any Rendering logic for Out-of-Box or Custom field type.With JSLink developers can now Control the Rendering (the presentation and validation) of any Field (Custom or Out-of-box) on List forms as well as in Views by simply adding a reference to an External or deployed JavaScript file.</div>
<div style="color: #333333; font-family: Lora, serif; font-size: 16px; line-height: 25px; margin-bottom: 25px; padding: 0px;">
<strong>Q50: What’s the new SPSecurityEventReceiver?<br />Ans:</strong> In SharePoint 2013, MS has added “SPSecurityEventReceiver” class to handle events for SharePoint Groups, Users, Roles and Permission Inheritance.</div>
<div style="color: #333333; font-family: Lora, serif; font-size: 16px; line-height: 25px; margin-bottom: 25px; padding: 0px;">
<strong>Q51: Can I turn off Social – Follow & Site Feed in SharePoint 2013?<br />Ans:</strong> Yes.You Can de-activiate Follow & Social by disabling “Following Content feature” and “Site Feeds feature” on the Team site(in the written Order).By default, the Site feed feature on a team site is enabled.</div>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-74218648644796399942013-06-21T05:17:00.003-07:002013-06-21T05:17:53.915-07:00Using Content Search In SharePoint 2013<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
The Content Search Web Part (CSWP) is a new feature in SharePoint 2013. It can be most accurately compared to the Content Query Web Part that we have in previous SharePoint versions. The one striking difference between Content Search and Content Query is that Content Search allows you to query and show information from any site collection. As long as your search is configured to crawl the information it can be pulled into your CSWP!</div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
This blog covers a basic scenario that will show you how easily the CSWP can be configured and ready for use.</div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<b style="border: 0px; margin: 0px; padding: 0px;">Scenario</b> – A research organization is putting together a SharePoint 2013 Community site to enable all of its top scientists to communicate. It would like to have a section on the site that shows all the organization’s scientists in a functional image slider. The problem is that the photos are spread throughout the site collection in different libraries. The one positive is that the organization uses Enterprise Keywords and all the photos have been tagged with the keyword <b style="border: 0px; margin: 0px; padding: 0px;">Scientist</b>. (At the end of this blog, I will show how to activate Enterprise Keywords on a library.)</div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
Here are the steps the organization will follow:</div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<strong style="border: 0px; margin: 0px; padding: 0px;">1</strong>- The first step is to edit my Community site and add my CSWP which can be found in the <b style="border: 0px; margin: 0px; padding: 0px;">Content Rollup</b> category.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFHm_JVZW1H8WXnWC5EDlUyVpSlBa_NxwW7ikcJdiltESUf-A0wu8RRQoKOXmCUDKwtuuip2OtuOjnmuV2POQ8AAshJYtWlT7sC0Db81fIGsXG5_feP3VTTKXrr_ETbKDk5z44IQiuVjQ/s1600/sharepoint-content.1%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFHm_JVZW1H8WXnWC5EDlUyVpSlBa_NxwW7ikcJdiltESUf-A0wu8RRQoKOXmCUDKwtuuip2OtuOjnmuV2POQ8AAshJYtWlT7sC0Db81fIGsXG5_feP3VTTKXrr_ETbKDk5z44IQiuVjQ/s1600/sharepoint-content.1%5B1%5D.png" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<strong style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin: 0px; padding: 0px;">2</strong><span style="background-color: white; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px;">- To configure the web part first click anywhere in the web part, then choose the </span><b style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin: 0px; padding: 0px;">Web Part</b><span style="background-color: white; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px;"> tab in the ribbon. From that tab click </span><b style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin: 0px; padding: 0px;">Web Part Properties</b></div>
<div class="separator" style="clear: both; text-align: left;">
<b style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin: 0px; padding: 0px;"><br /></b></div>
<div class="separator" style="clear: both; text-align: left;">
<b style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin: 0px; padding: 0px;"></b></div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<strong style="border: 0px; margin: 0px; padding: 0px;">3</strong>- We first need to setup the query. To do so click <b style="border: 0px; margin: 0px; padding: 0px;">Change query</b> from the web part properties box.</div>
<div>
<strong style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin: 0px; padding: 0px;">4</strong><span style="background-color: white; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px;">- A Build Your Query dialog box will open. There are four tabs available Basics, Refiners, Settings and Test. From the </span><b style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin: 0px; padding: 0px;">Basics</b><span style="background-color: white; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px;"> tab you should see </span><b style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin: 0px; padding: 0px;">Switch to Advanced Mode</b><span style="background-color: white; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px;"> in the upper right corner. If you see Switch to Quick Mode click it. We will start this query from the Quick mode.</span></div>
<div>
<span style="background-color: white; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5ie3g4WeWSx0OaE0yed7O7u7kPNV4UTMZdTE2roLHAfnw5QLvwsbVGrBY7u_TsL7r5NHPx-S0u63wFX7wB_RVJLxzc2PzrsF5cXaRFvds9qhyS4V6qHVSh8ASTpRwhdusVlSRFrK0AU8/s1600/sharepoint-content.2%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="298" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5ie3g4WeWSx0OaE0yed7O7u7kPNV4UTMZdTE2roLHAfnw5QLvwsbVGrBY7u_TsL7r5NHPx-S0u63wFX7wB_RVJLxzc2PzrsF5cXaRFvds9qhyS4V6qHVSh8ASTpRwhdusVlSRFrK0AU8/s320/sharepoint-content.2%5B1%5D.png" width="320" /></a></div>
<div>
<span style="background-color: white; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px;"><br /></span></div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<strong style="border: 0px; margin: 0px; padding: 0px;">5</strong>- From the <b style="border: 0px; margin: 0px; padding: 0px;">Select a query</b> menu I have several options. In this situation I could either choose <b style="border: 0px; margin: 0px; padding: 0px;">Items matching a tag (System)</b> or<b style="border: 0px; margin: 0px; padding: 0px;">Pictures (System)</b>. I also have the option of just querying documents, items matching a specific content type, popular items, etc.</div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<strong style="border: 0px; margin: 0px; padding: 0px;">6</strong>- Under Restrict by app I can decide to query the Current Site Collection, Current Site, Specific URL, or I can choose <b style="border: 0px; margin: 0px; padding: 0px;">Don’t restrict results by app</b> and query everything that I am currently crawling.</div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<strong style="border: 0px; margin: 0px; padding: 0px;">7</strong>- If you remember, in my test scenario I am looking for items that have a specific keyword of Scientist. So here I will choose <b style="border: 0px; margin: 0px; padding: 0px;">Restrict on this tag:</b> and enter Scientist.</div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<strong style="border: 0px; margin: 0px; padding: 0px;">8</strong>- You can add additional filters here or <b style="border: 0px; margin: 0px; padding: 0px;">Switch to Advanced Mode</b> for even more options. On the right hand side you can see what your query is currently returning to the web part.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQNc6xhrQZZkXQaoxr1Q2Viia-_OhK-GxAtXzqxSaWEJelH9BOsd96lB0huZ6qrTG1OSxH6g2jsTMP8sCZ31F98wvkLVUNpeHtpf6k_m5hZvYk198uwK0EDVMW_yPRaDPkYU6yROP4svU/s1600/sharepoint-content.3%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQNc6xhrQZZkXQaoxr1Q2Viia-_OhK-GxAtXzqxSaWEJelH9BOsd96lB0huZ6qrTG1OSxH6g2jsTMP8sCZ31F98wvkLVUNpeHtpf6k_m5hZvYk198uwK0EDVMW_yPRaDPkYU6yROP4svU/s1600/sharepoint-content.3%5B1%5D.png" /></a></div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<strong style="border: 0px; margin: 0px; padding: 0px;">9</strong>- The Refiners tab will allow you to filter your query even further. Currently, my query is returning any item that has been tagged with the keyword Scientist, but let’s say in my results I am finding that some documents had also been tagged with that keyword. I only want images to display so I can use this tab to add the ContentType of Picture to my refiners.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZn6hEXlm40V6peHlEs_x-VGO161cQopJiuLOWbCPHEJR-iBHV8UWjMVBr_RNxTgTRt4QwErftyIj66d4J8FxesyxS0OIzgi6p21Z_lGCh_ujneDIoHHTZrMEid0snrqTPM93oZ90rRVA/s1600/sharepoint-content.4%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZn6hEXlm40V6peHlEs_x-VGO161cQopJiuLOWbCPHEJR-iBHV8UWjMVBr_RNxTgTRt4QwErftyIj66d4J8FxesyxS0OIzgi6p21Z_lGCh_ujneDIoHHTZrMEid0snrqTPM93oZ90rRVA/s1600/sharepoint-content.4%5B1%5D.png" /></a></div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<strong style="border: 0px; margin: 0px; padding: 0px;">10</strong>- The <b style="border: 0px; margin: 0px; padding: 0px;">Settings</b> tab has a few additional options including the use of Query rules and the loading behavior of your query. For this example I will leave everything at the default.</div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<strong style="border: 0px; margin: 0px; padding: 0px;">11</strong>- The tab <b style="border: 0px; margin: 0px; padding: 0px;">Test </b>gives you your final query text for testing purposes. When finished simply click <b style="border: 0px; margin: 0px; padding: 0px;">OK</b>at the bottom of the <b style="border: 0px; margin: 0px; padding: 0px;">Build Your Query</b> dialog box.</div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<strong style="border: 0px; margin: 0px; padding: 0px;">12</strong>- The final step is to setup how results will display. From the Web Part Properties box you have the following options (the settings I choose for this solution can be seen in the image below.)</div>
<ul style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 16px; margin: 0px 0px 15px; padding: 0px 0px 7px 15px;">
<li style="border: 0px; line-height: 24px; margin: 0px; padding: 0px 0px 7px;"><b style="border: 0px; margin: 0px; padding: 0px;">Number of items to show</b></li>
<li style="border: 0px; line-height: 24px; margin: 0px; padding: 0px 0px 7px;">Under Display Templates: <b style="border: 0px; margin: 0px; padding: 0px;">Control</b> (List, List with Paging or Slideshow)</li>
<li style="border: 0px; line-height: 24px; margin: 0px; padding: 0px 0px 7px;">Under Display Templates: <b style="border: 0px; margin: 0px; padding: 0px;">Item</b> (determines how the image and text will display, if you are just listing documents “two lines” would be the best option)</li>
<li style="border: 0px; line-height: 24px; margin: 0px; padding: 0px 0px 7px;">Under Display Templates: <b style="border: 0px; margin: 0px; padding: 0px;">Don’t show anything when there are no results</b> (leave this checked to avoid blank space, especially when using the slideshow control.)</li>
</ul>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<b style="border: 0px; margin: 0px; padding: 0px;">**Note- If you want to get your hands on the code behind these display templates they can be found under Site Settings > Web Designer Galleries > Master pages > Display Templates > Content Web Parts</b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjad0ci-i-l6ti-L_AvoFBXCTpbNsNuGAbB0FdPdWGzsab7UdeFXjOrKHOJKqOpm731SFTJTFhKRm2wjBCoO1cMyZ6y9ExOL0tuyMIfNxRXRZYx6CXu7LeiHHEHEcjdxwtaJEw3r0gFIO0/s1600/sharepoint-content.5%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjad0ci-i-l6ti-L_AvoFBXCTpbNsNuGAbB0FdPdWGzsab7UdeFXjOrKHOJKqOpm731SFTJTFhKRm2wjBCoO1cMyZ6y9ExOL0tuyMIfNxRXRZYx6CXu7LeiHHEHEcjdxwtaJEw3r0gFIO0/s1600/sharepoint-content.5%5B1%5D.png" /></a></div>
<div id="contentLogoimage" style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 12px; line-height: 16px; margin: 0px; padding: 0px;">
<div class="content" style="border: 0px; margin: 0px; padding: 0px;">
<div style="border: 0px; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
When your settings are right click OK to close your web part and you’re done!</div>
</div>
</div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<b style="border: 0px; margin: 0px; padding: 0px;"><br /></b></div>
<div class="clear" style="-webkit-text-stroke-width: 0px; background-color: white; background-image: none; background-position: initial initial; background-repeat: initial initial; border: 0px; clear: both; color: #505050; display: block; float: none; font-family: arial, verdana, sans-serif; font-size: 0px; font-style: normal; font-variant: normal; font-weight: normal; height: 0px; letter-spacing: normal; line-height: 16px; list-style: none; margin: 0px; orphans: auto; overflow: hidden; padding: 0px; text-align: left; text-indent: 0px; text-transform: none; visibility: hidden; white-space: normal; widows: auto; width: 0px; word-spacing: 0px;">
</div>
<div style="background-color: white; border: 0px; color: #505050; font-family: arial, verdana, sans-serif; font-size: 14px; line-height: 23px; margin-bottom: 15px; padding: 6px 0px;">
<br /></div>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-88331538817103472032013-05-30T11:56:00.002-07:002013-05-30T11:56:46.298-07:00Deploying SharePoint 2010 Solution on SharePoint 2013<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
As you know, in SharePoint 2010 there was 14 hive where you deploy your files. And then you reference them like below:</div>
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
<br /></div>
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
Physical Path: <span style="border: 0px; font-family: 'Courier New'; font-size: 10pt; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS</span></div>
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
Virtual Path: <span style="border: 0px; font-family: 'Courier New'; font-size: 10pt; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">“/_layouts/<your folder>/<your files>”</span></div>
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
<br /></div>
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
In SharePoint 2013, there is new 15 hive</div>
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
Physical Path: <span style="border: 0px; font-family: 'Courier New'; font-size: 10pt; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS</span></div>
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
Virtual Path: <span style="border: 0px; font-family: 'Courier New'; font-size: 10pt; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">“/_layouts<strong style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">/15/</strong><your folder>/<your files>”</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVEu2x5U-eJA_F4vPtOtZRaxhjMjc0qJP2hZBa-mzuNTW8ctDbUd2YnO4OTX3ldfh_QPlqKF9RgSbf0QRGYERrgn_kR-pqgeZ8VyG6Z8YyGc8wkrHqDkblLgJEEirne-V6mWDvkc339Ik/s1600/041813_1548_deployingsh1%5B1%5D.png" imageanchor="1" style="background-color: transparent; margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="96" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVEu2x5U-eJA_F4vPtOtZRaxhjMjc0qJP2hZBa-mzuNTW8ctDbUd2YnO4OTX3ldfh_QPlqKF9RgSbf0QRGYERrgn_kR-pqgeZ8VyG6Z8YyGc8wkrHqDkblLgJEEirne-V6mWDvkc339Ik/s400/041813_1548_deployingsh1%5B1%5D.png" width="400" /></a></div>
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
<br /></div>
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
</div>
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
If you have SharePoint 2010 solution (.wsp file) and you need to deploy it on SharePoint 2013, then you have the following options:</div>
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
First, you have to add the solution to your farm using PowerShell as following:</div>
<ul style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1.5em 3em; outline: 0px; padding: 0px; vertical-align: baseline;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="border: 0px; font-family: 'Courier New'; font-size: 10pt; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Add-SPSolution C:\SP2010Project.wsp</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgm_2fK8Lx9oTtAOADw1SFN19Q_lhsjNVaxxbjHvBkDvTkF9cI3k_74MU1DoXBqlGXeCv5FpUrmtfCAE0m-siAk9kD4yYZ_vcN-phXve5OMamd9yKXnbFnHZqfcqBGtMMyzGzMogmcYGsY/s1600/041813_1548_deployingsh2%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgm_2fK8Lx9oTtAOADw1SFN19Q_lhsjNVaxxbjHvBkDvTkF9cI3k_74MU1DoXBqlGXeCv5FpUrmtfCAE0m-siAk9kD4yYZ_vcN-phXve5OMamd9yKXnbFnHZqfcqBGtMMyzGzMogmcYGsY/s1600/041813_1548_deployingsh2%5B1%5D.png" /></a></div>
<div>
<span style="color: #3f3f3f; font-family: Courier New; font-size: x-small;"><span style="line-height: 27px;"><br /></span></span></div>
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
</div>
<div style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;">
Now,</div>
<ul style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1.5em 3em; outline: 0px; padding: 0px; vertical-align: baseline;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Deploy to 14 hive <span style="border: 0px; font-family: Wingdings; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">è</span><br /><span style="border: 0px; font-family: 'Courier New'; font-size: 10pt; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Install-SPSolution sp2010project.wsp</span></li>
</ul>
<ul style="background-color: white; border: 0px; color: #3f3f3f; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 27px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1.5em 3em; outline: 0px; padding: 0px; vertical-align: baseline;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Deploy to 15 hive <span style="border: 0px; font-family: Wingdings; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">è</span><span style="border: 0px; font-family: 'Courier New'; font-size: 10pt; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> Install-SPSolution sp2010project.wsp -CompatibilityLevel 15</span></li>
</ul>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-65693312781050029872013-05-10T08:36:00.000-07:002013-05-10T08:36:26.938-07:00Split CSV file based on content using PowerShell<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
You have a CSV file that contains department employees in a format like this:</div>
<div class="pre-action-link" id="premain0" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre0" lang="text" style="border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">Department,Employee
Sales,emp1
HR,emp2
Sales,emp3
Finance,emp4
Finance,emp5
Security,emp6
Security,emp7
Security,emp8
HR,emp9</pre>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
And you need to split the contents of this file to separate files based on department name. So for the above example, we should get four files, <em style="border: 0px; margin: 0px; padding: 0px;">Sales.csv</em>, <em style="border: 0px; margin: 0px; padding: 0px;">HR.csv</em>, <em style="border: 0px; margin: 0px; padding: 0px;">Finance.csv</em>, and <em style="border: 0px; margin: 0px; padding: 0px;">Security.csv</em>. Each file contains only its employees.<br />
And the solution really shows the power of PowerShell pipelining:</div>
<div class="pre-action-link" id="premain1" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre1" lang="text" style=" border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">Import-Csv file.csv | Group-Object -Property "department" |
Foreach-Object {$path=$_.name+".csv" ; $_.group |
Export-Csv -Path $path -NoTypeInformation}</pre>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Dissecting the above commands:</div>
<ul style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;"><code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">Import-Csv file.csv</code>: Parses the CSV file and returns an array of objects.</li>
<li style="border: 0px; margin: 0px; padding: 0px;"><code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">| Group-Object -Property "department"</code>: Since we need to split by department, it makes sense to group objects by the department property.</li>
<li style="border: 0px; margin: 0px; padding: 0px;"><code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">| Foreach-Object {...}</code>: We need to apply an action for each group (department). So we pipeline the resulted groups to <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">Foreach</code>-Object.</li>
<li style="border: 0px; margin: 0px; padding: 0px;"><code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">$path=$_.name+".csv"</code>: Within the <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">foreach</code>, we need to create a temporary variable (<code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">$path</code>) to be passed to the next pipeline responsible for the actual saving. Note that I use the semicolon ";" to separate this part from the next. And I used the name property of the group (which maps to department name in our case) to format the file name.</li>
<li style="border: 0px; margin: 0px; padding: 0px;"><code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">$_.group | Export-Csv -Path $path -NoTypeInformation</code>: Then for each group we have, we need to export its contents (CSV file rows) to the file path created in the past step. So we again pipeline the group property of the group item (which is an <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">ArrayList </code>of original objects) to the Export-CSV Cmdlt.</li>
</ul>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
And the result should be files like:</div>
<div class="pre-action-link" id="premain2" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre2" lang="text" style=" border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">Finance.csv:
"Department","Employee"
"Finance","emp4"
"Finance","emp5"</pre>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-9360264278840594492013-05-10T08:21:00.003-07:002013-05-10T08:22:34.293-07:00List Google Docs using PowerShell<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Are you looking for a quick and easy way to access your Google Docs from PowerShell? The <a href="http://www.rssbus.com/ado/google/" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;">Google Data Provider</a>provides an easy-to-use ADO.NET interface that you can take advantage of with your PowerShell Scripts. Simply use the included SQL like .NET objects (<code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">GoogleConnection</code>, <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">GoogleCommand</code>, <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">GoogleDataAdapter</code>, etc.) in your PowerShell scripts to connect to your Google Apps accounts and synchronize, automate, download, and more!<br />
<br /></div>
<h3 style="background-color: white; color: #666666; font-family: 'Segoe UI', Arial, sans-serif; font-size: 18px; font-weight: normal;">
Using the Google Data Provider in PowerShell to List Google Docs:</h3>
<div class="pre-action-link" id="premain0" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre0" lang="text" style="border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"># Load the Google Data Provider assembly
[Reflection.Assembly]::LoadFile("C:\Program Files\RSSBus\RSSBus
Google Data Provider\lib\System.Data.RSSBus.Google.dll")
# Connect to Google
$constr = "User=[username];Password=[password]"
$conn= New-Object System.Data.RSSBus.Google.GoogleConnection($constr)
$conn.Open()
$sql="SELECT Name, AuthorName, Type, Updated, Weblink from Documents"
$da= New-Object System.Data.RSSBus.Google.GoogleDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.updated $_.name
}</pre>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Listing is only the first step. With full CRUD support, you can use the Google Data Provider to easily upload and download documents as well. The following bit of PowerShell code downloads one of the documents listed above:<br />
<br /></div>
<h3 style="background-color: white; color: #666666; font-family: 'Segoe UI', Arial, sans-serif; font-size: 18px; font-weight: normal;">
Download a file from Google Docs:</h3>
<div class="pre-action-link" id="premain1" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre1" lang="text" style="border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">$cmd= New-Object System.Data.RSSBus.Google.GoogleCommand("DownloadDocument", $conn)
$cmd.CommandType= [System.Data.CommandType]'StoredProcedure'
$cmd.Parameters.Add( (New-Object System.Data.RSSBus.Google.GoogleParameter("@Type", "TXT")) )
$cmd.Parameters.Add( (New-Object System.Data.RSSBus.Google.GoogleParameter("@Name", "myfile")) )
$cmd.Parameters.Add( (New-Object System.Data.RSSBus.Google.GoogleParameter("@LocalFile", "d:\myfile.txt")) )
$reader = $cmd.ExecuteReader()</pre>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Likewise, calling the <em style="border: 0px; margin: 0px; padding: 0px;">UploadDocument</em> Stored Procedure allows your scripts to upload documents directly to Google Docs.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
As you can see, the <a href="http://www.rssbus.com/ado/google/" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;">Google Data Provider</a> provides a hassle-free way to access the features of Google Apps directly from PowerShell script, and eliminates the headache involved with authentication, security, etc. </div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Happy scripting!</div>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-7234921942527106062013-05-10T08:17:00.001-07:002013-05-10T08:17:54.672-07:00Partial page load issue with ASP.NET MVC and head.js<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="post-body entry-content" id="post-body-1234889521696869208" itemprop="description articleBody" style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 1.4; position: relative; width: 652px;">
I've been working with a small team over the past year or so on a large-scale web application built in ASP.NET MVC 3. We're using some of the best new client-side technologies with it as well - jQuery,<a href="http://twitter.github.com/bootstrap/" style="color: #3c9410; text-decoration: none;" target="_blank">Bootstrap</a> and <a href="http://headjs.com/" style="color: #3c9410; text-decoration: none;" target="_blank">head.js</a> to name a few. Overall, the project has gone very smoothly, with only a few minor hiccups or delays.<br />
Well, except for one lingering issue.<br />
We began experiencing intermittent partial page loads almost as soon as the first draft of the UI was released to our testing servers. The following behaviors were exhibited:<br />
<ul style="line-height: 1.4; margin: 0.5em 0px; padding: 0px 2.5em;">
<li style="margin: 0px 0px 0.25em; padding: 0px;">This issue could happen on any page in the application when it loaded.</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;">65-70% of the time a page would load correctly.</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;">Pressing F5 (refresh) would reload the page and <u>always</u> fixed the issue.</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;">Generally, either part of the main menu bar wouldn't load, or our <a href="http://flexigrid.info/" style="color: #3c9410; text-decoration: none;" target="_blank">datagrid</a> wouldn't load. Both controls could have a problem on a given page if you reloaded it multiple times.</li>
</ul>
Perplexing and frustrating to say the least. First, we thought it was a problem with the tiny VMs we had in our testing environment. Then we guessed it might be a packet delivery issue with the VPN tunnel between the testing network and the office network. Then we supposed maybe our self-hosted CDN wasn't set up correctly, and switched to using <a href="http://aws.amazon.com/s3/" style="color: #3c9410; text-decoration: none;" target="_blank">Amazon S3</a> (which we were planning on doing anyway).<br />
Each of these theories (and others) were tested and debunked. No love. There's no way it could be in our code, right??<br />
<div>
What ended up working for us was moving our "core" libraries outside of head.js and using their "execute in-order" method for the rest of our libraries. Our _Layout.cshtml page looks like this:<br /><div style="font-family: monospace; font-size: small; padding-left: 10px;">
<!doctype html><br /><html lang="en"><br /><head><br /><br /><i>(... stylesheets and other head content ...)</i><br /><br /><script type="text/javascript" src="http://cdn.company.com/JS/head.min.js" /><br /><script type="text/javascript" src="http://cdn.company.com/JS/jquery-1.7.1.min.js" /><br /><script type="text/javascript" src="http://cdn.company.com/JS/jquery-ui-1.8.18.min.js" /><br /><script type="text/javascript" src="http://cdn.company.com/JS/modernizr-2.5.3.min.js" /><br /><script type="text/javascript" src="http://cdn.company.com/JS/bootstrap-2.1.0.min.js" /><br /><script type="text/javascript" src="http://cdn.company.com/JS/flexigrid.pack.js" /><br /><br /><script type="text/javascript"><br /> head.js(<br /> "http://cdn.company.com/JS/jquery.validate.min.js",<br /> "http://cdn.company.com/JS/another.script.js",<br /> <i>(... other javascript files ...)</i>,<br /> );<br /></script><br /><br /><i>(... other code / markup ...)</i><br /><br /></html></div>
</div>
We implemented this change about a week ago, and have yet to experience the issue once since then. Couple of additional notes / comments to share about the change:<br />
<ul style="line-height: 1.4; margin: 0.5em 0px; padding: 0px 2.5em;">
<li style="margin: 0px 0px 0.25em; padding: 0px;">This seems to work because generally all of the other javascript files you'll want to load probably depend on one or more of these "core" files to work properly. Letting head.js handle this becomes even more delicate when you consider the fact that ASP.NET is trying to load multiple Partial Views per page, many of which contain controls that need the "core" in place to be built properly. Any interruption of loading a "core" file before a control needs it may break part of the page.</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;">While the head.js <a href="http://headjs.com/#usage" style="color: #3c9410; text-decoration: none;" target="_blank">usage</a> documentation lists what we have here as a correct way of using the library, this is not how their <a href="http://headjs.com/test/headjs.html" style="color: #3c9410; text-decoration: none;" target="_blank">demo</a> is built ('View Source' to check it out).</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;">The most similar issue we could find was <a href="https://github.com/headjs/headjs/issues/202" style="color: #3c9410; text-decoration: none;" target="_blank">here</a> on the head.js GitHub project site. This is where we got the idea to try an alternate implementation.</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;">Since the purpose of head.js is to improve page load times, you may be wondering if this change hurt our delivery speed. Unfortunately, because pages weren't reliably loading for a number of months, it was hard to measure where we were at before the change, so I'm unable to determine a speed difference.</li>
</ul>
<br />
I decided to document this because we weren't able to find any instances online of someone else having the problem; hoping this post will save a few other teams some time and headaches.<br />
<div style="clear: both;">
</div>
</div>
<div class="post-footer" style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; color: #666666; font-family: Arimo; font-size: 13px; line-height: 1.6; margin: 20px -2px 0px; padding: 5px 10px;">
</div>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-29559498773749729822013-05-10T08:13:00.002-07:002013-05-10T08:13:49.172-07:00Clean up old files using PowerShell<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">
Doing a quick Google search (which may be what brought you here) will show you a number of variations on PowerShell scripts for deleting files. I'm sure many of them are perfectly adequate for the task, and in some cases, have features that mine doesn't. My solution excels at code readability and control, the latter of which I feel is fairly important when deleting files in bulk.</div>
<div style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">
Not much else to say about it I guess; the purpose and uses of this script are pretty straightforward.</div>
<span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">Here's the code:</span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><hr style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" />
<div style="background-color: white; color: #191919; font-family: courier; font-size: smaller; padding-left: 10px;">
<div style="color: green;">
# |Info|<br /># Written by Bryan O'Connell, February 2013<br /># Purpose: Delete files from a folder haven't been modified for the<br /># specified number of days.<br />#<br /># Sample: DeleteOldFiles.ps1 -folder "C:\test" -days_old 7 [-only_this_type ".xls"]<br />#<br /># Params:<br /># -folder: The place to search for old files.<br />#<br /># -days_old: Age threshold. Any file that hasn't been modified for more than<br /># this number of days will be deleted.<br />#<br /># -only_this_type: This is an optional parameter. Use it to specify that you<br /># just want to delete files with a specific file extension. Be sure to<br /># include the '.' with the file extension.<br />#<br /># |Info|</div>
<br />[<b style="color: #01a9db;">CmdletBinding</b>()]<br /><b style="color: #0b0b61;">Param</b> (<br /> [<b style="color: #01a9db;">Parameter</b>(Mandatory=<b style="color: #df3a01;">$true</b>,Position=<b style="color: #2f0b3a;">0</b>)]<br /> [<b style="color: #0b4c5f;">string</b>]<b style="color: #df3a01;">$folder</b>,<br /><br /> [<b style="color: #01a9db;">Parameter</b>(Mandatory=<b style="color: #df3a01;">$true</b>,Position=<b style="color: #2f0b3a;">1</b>)]<br /> [<b style="color: #0b4c5f;">int</b>]<b style="color: #df3a01;">$days_old</b>,<br /><br /> [<b style="color: #01a9db;">Parameter</b>(Mandatory=<b style="color: #df3a01;">$false</b>,Position=<b style="color: #2f0b3a;">2</b>)]<br /> [<b style="color: #0b4c5f;">string</b>]<b style="color: #df3a01;">$only_this_type</b><br />)<br /><br /><span style="color: green;">#-----------------------------------------------------------------------------#</span><br /><br /><div style="color: green;">
# Determines whether or not it's ok to delete the specified file. If no type<br /># is specified, all files are ok to delete. If a type IS specified, only files<br /># of that type are ok to delete.</div>
<br /><b style="color: #0b0b61;">Function</b> <b style="color: #2f0b3a;">TypeOkToDelete</b>(<b style="color: #df3a01;">$FileToCheck</b>)<br />{<br /> <b style="color: #df3a01;">$OkToDelete</b> = <b style="color: #df3a01;">$False</b>;<br /><br /> <b style="color: #0b0b61;">if</b> (<b style="color: #df3a01;">$only_this_type</b> -eq <b style="color: #df3a01;">$null</b>) {<br /> <b style="color: #df3a01;">$OkToDelete</b> = <b style="color: #df3a01;">$True</b>;<br /> }<br /> <b style="color: #0b0b61;">else</b> {<br /> <b style="color: #0b0b61;">if</b> ( (<b style="color: #df3a01;">$FileToCheck</b>.Extension) -ieq <b style="color: #df3a01;">$only_this_type</b> ) {<br /> <b style="color: #df3a01;">$OkToDelete</b> = <b style="color: #df3a01;">$True</b>;<br /> }<br /> }<br /><br /> <b style="color: #0b0b61;">return</b> <b style="color: #df3a01;">$OkToDelete</b>;<br />}<br /><br /><span style="color: green;">#-----------------------------------------------------------------------------#</span><br /><br /><b style="color: #df3a01;">$FileList</b> = [<b style="color: #0b4c5f;">IO.Directory</b>]::GetFiles(<b style="color: #df3a01;">$folder</b>);<br /><b style="color: #df3a01;">$Threshold</b> = (<b style="color: #0b0b61;">Get-Date</b>).AddDays(-<b style="color: #df3a01;">$days_old</b>);<br /><br /><b style="color: #0b0b61;">foreach</b>(<b style="color: #df3a01;">$FileToDelete</b> <b style="color: #0b0b61;">in</b> <b style="color: #df3a01;">$FileList</b>)<br />{<br /> <b style="color: #df3a01;">$CurrentFile</b> = <b style="color: #0b0b61;">Get-Item</b> <b style="color: #df3a01;">$FileToDelete</b>;<br /> <b style="color: #df3a01;">$WasLastModified</b> = <b style="color: #df3a01;">$CurrentFile</b>.LastWriteTime;<br /> <b style="color: #df3a01;">$FileOkToDelete</b> = <b style="color: #0b0b61;">TypeOkToDelete</b>(<b style="color: #df3a01;">$CurrentFile</b>);<br /><br /> <b style="color: #0b0b61;">if</b> ( (<b style="color: #df3a01;">$WasLastModified</b> -lt <b style="color: #df3a01;">$Threshold</b>) -and (<b style="color: #df3a01;">$FileOkToDelete</b>) )<br /> {<br /> <b style="color: #df3a01;">$CurrentFile</b>.IsReadOnly = <b style="color: #df3a01;">$false</b>;<br /> <b style="color: #0b0b61;">Remove-Item</b> <b style="color: #df3a01;">$CurrentFile</b>;<br /> <b style="color: #0b0b61;">write-Output</b> <b style="color: #8a0808;">"Deleted $CurrentFile"</b>;<br /> }<br />}<br /><br /><b style="color: #0b0b61;">write-Output</b> <b style="color: #8a0808;">"Press any key to quit ..."</b>;<br /><b style="color: #df3a01;">$quit</b> = <b style="color: #df3a01;">$host</b>.UI.RawUI.ReadKey(<b style="color: #8a0808;">"NoEcho, IncludeKeyDown"</b>);</div>
<hr style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" />
<br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><i style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">NOTE: If you run into problems getting the script to run on your machine, there are a few troubleshooting tips in my original article.</i></div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-14650772498137806452013-05-10T08:09:00.000-07:002013-05-10T08:09:04.628-07:00Extract worksheets from Excel into separate files with PowerShell<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">I recently had need to dust off an old VB script I'd written years ago to get worksheets out of Excel files. I've also been curious about doing more with PowerShell, and besides feeling guilty about putting a VB script into use in 2012, it seemed like a really good learning opportunity.</span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">So why not just rewrite the script in .NET? Well, you can definitely do that; in fact, the code would look very similar. However, not everyone is a .NET developer. I wrote the original VB script on a team where we were building C++ DLLs for ETL processing; .NET wasn't part of our code base. I also think there are plenty of IT roles - DevOps, DBAs, Network Admininstrators to name a few - that might find a simple PowerShell tool like this a little easier to use and/or modify for their needs.</span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">So that being said, just copy & paste the code below into an empty .ps1 file, and you should be good to go. To use it, simply execute the following command (should work from command-line, batch file, or managed code):</span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #073763;">PowerShell.exe</span> -command "C:\ScriptFile.ps1" -filepath "C:\Spreadsheet.xls" -output_type "csv"</code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">I did run into one problem / issue while writing this script - getting it to run the first time! Thanks to </span><a href="http://www.hanselman.com/blog/SigningPowerShellScripts.aspx" style="background-color: white; color: #3c9410; font-family: Arimo; font-size: 15px; line-height: 21px; text-decoration: none;" target="_blank">this great article by Scott Hanselman</a><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">, I found out that there are some very tight Windows security restrictions on PowerShell scripts - particularly the ones you didn't write yourself. After reading his article, it seemed easier for me (and for anyone who wants to use my code) to just post the source code rather than a downloadable script with certificates, at least in this instance. Maybe if I write another PowerShell article I'll give the certificate thing a go.</span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">If you get the error message I got - "</span><span style="background-color: white; color: #191919; font-family: 'Courier New'; font-size: x-small;">The file C:\ScriptFile.ps1 cannot be loaded. The execution of scripts is disabled on this system. Please see "Get-Help about_signing" for more details.</span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">" - you can enable execution of PowerShell scripts </span><u style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">you've</u><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">created by running the following command 'As Administrator':</span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #073763;">PowerShell.exe</span> Set-ExecutionPolicy RemoteSigned</code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;">Anyway, here's my script:</span><br />
<hr style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" />
<br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><div style="background-color: white; color: #274e13; font-family: Arimo; font-size: 15px; line-height: 21px;">
<span style="font-size: x-small;"># Purpose: Extract all of the worksheets from an Excel file into separate files.</span></div>
<span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><br /></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code>[<span style="color: #45818e;">CmdletBinding</span>()]</code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #073763;">Param</span> ( </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> [<span style="color: #45818e;">Parameter</span>(Mandatory=<span style="color: #b45f06;">$true</span>,Position=<span style="color: #4c1130;">0</span>)] </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #45818e;">[string]</span><span style="color: #b45f06;">$filepath</span>,</code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><br /></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> [<span style="color: #45818e;">Parameter</span>(Mandatory=<span style="color: #b45f06;">$true</span>,Position=<span style="color: #4c1130;">1</span>)] </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> [<span style="color: #45818e;">ValidateSet</span>(<span style="color: #cc0000;">"csv"</span>,<span style="color: #cc0000;">"txt"</span>,<span style="color: #cc0000;">"xls"</span>,<span style="color: #cc0000;">"html"</span>)] </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #45818e;">[string]</span><span style="color: #b45f06;">$output_type</span> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code>)</code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><div style="background-color: white; color: #274e13; font-family: Arimo; font-size: 15px; line-height: 21px;">
<span style="font-size: x-small;"><code>#-----------------------------------------------------------------------------#</code></span></div>
<br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><div style="background-color: white; color: #274e13; font-family: Arimo; font-size: 15px; line-height: 21px;">
<span style="font-size: x-small;"><code># Figures out and returns the 'XlFileFormat Enumeration' ID for the specified format.</code></span></div>
<div style="background-color: white; color: #274e13; font-family: Arimo; font-size: 15px; line-height: 21px;">
<span style="font-size: x-small;"><code># http://msdn.microsoft.com/en-us/library/office/bb241279%28v=office.12%29.aspx </code></span></div>
<div style="background-color: white; color: #274e13; font-family: Arimo; font-size: 15px; line-height: 21px;">
<span style="font-size: x-small;"><code># NOTE: The code being used for 'xls' is actually a 'text' type, but it seemed</code></span></div>
<div style="background-color: white; color: #274e13; font-family: Arimo; font-size: 15px; line-height: 21px;">
<span style="font-size: x-small;"><code># to work the best for splitting the worksheets into separate Excel files.</code></span></div>
<span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><br /></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #073763;">function</span> <span style="color: #4c1130;">GetOutputFileFormatID</span> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code>{ </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #073763;">Param</span>(<span style="color: #45818e;">[string]</span><span style="color: #b45f06;">$fomat_name</span>) </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #b45f06;">$Result</span> = <span style="color: #4c1130;">0</span> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><br /></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #073763;">switch</span>(<span style="color: #b45f06;">$fomat_name</span>) </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> { </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #cc0000;">"csv"</span> {<span style="color: #b45f06;">$Result</span> = <span style="color: #4c1130;">6</span>} </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #cc0000;">"txt"</span> {<span style="color: #b45f06;">$Result</span> = <span style="color: #4c1130;">20</span>} </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #cc0000;">"xls"</span> {<span style="color: #b45f06;">$Result</span> = <span style="color: #4c1130;">21</span>} </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #cc0000;">"html"</span> {<span style="color: #b45f06;">$Result</span> = <span style="color: #4c1130;">44</span>} </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> default {<span style="color: #b45f06;">$Result</span> = <span style="color: #4c1130;">51</span>} </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> } </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #073763;">return</span> <span style="color: #b45f06;">$Result</span> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code>}</code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #274e13;">#-----------------------------------------------------------------------------#</span> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><br /></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #b45f06;">$Excel</span> = <span style="color: #073763;">New-Object</span> -ComObject <b><span style="color: #7f6000;">"Excel.Application"</span></b> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #b45f06;">$Excel</span>.Visible = <span style="color: #b45f06;">$false</span> <span style="color: #274e13;">#Runs Excel in the background.</span> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #b45f06;">$Excel</span>.DisplayAlerts = <span style="color: #b45f06;">$false</span> <span style="color: #274e13;">#Supress alert messages.</span> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><br /></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #b45f06;">$Workbook</span> = <span style="color: #b45f06;">$Excel</span>.Workbooks.open(<span style="color: #b45f06;">$filepath</span>) </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><br /></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #274e13;">#Loop through the Workbook and extract each Worksheet in the specified file type. </span></code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code>if (<span style="color: #b45f06;">$Workbook</span>.Worksheets.Count -gt <span style="color: #4c1130;">0</span>) { </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #073763;">write-Output</span> <span style="color: #cc0000;">"Now processing: $WorkbookName"</span> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #b45f06;">$FileFormat</span> = <span style="color: #073763;">GetOutputFileFormatID</span>(<span style="color: #b45f06;">$output_type</span>) </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><br /></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #274e13;">#Strip off the Excel extension.</span> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #b45f06;">$WorkbookName</span> = <span style="color: #b45f06;">$filepath</span> -replace <span style="color: #cc0000;">".xlsx"</span>, <span style="color: #cc0000;">""</span> <span style="color: #274e13;">#Post 2007 extension</span></code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #b45f06;">$WorkbookName</span> = <span style="color: #b45f06;">$WorkbookName</span> -replace <span style="color: #cc0000;">".xls"</span>, <span style="color: #cc0000;">""</span> <span style="color: #274e13;">#Pre 2007 extension</span> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><br /></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #b45f06;">$Worksheet</span> = <span style="color: #b45f06;">$Workbook</span>.Worksheets.item(<span style="color: #4c1130;">1</span>) </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><br /></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #073763;">foreach</span>(<span style="color: #b45f06;">$Worksheet</span> <span style="color: #073763;">in</span> <span style="color: #b45f06;">$Workbook</span>.Worksheets) { </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #b45f06;">$ExtractedFileName</span> = <span style="color: #b45f06;">$WorkbookName</span> + <span style="color: #cc0000;">"~~"</span> + <span style="color: #b45f06;">$Worksheet</span>.Name + <span style="color: #cc0000;">"."</span> + <span style="color: #b45f06;">$output_type </span></code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><br /></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #b45f06;">$Worksheet</span>.SaveAs(<span style="color: #b45f06;">$ExtractedFileName</span>, <span style="color: #b45f06;">$FileFormat</span>) </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><br /></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> <span style="color: #073763;">write-Output</span> <span style="color: #cc0000;">"Created file: $ExtractedFileName"</span> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code> } </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code>} </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><br /></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;"></span><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #274e13;">#Clean up & close the main Excel objects.</span> </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #b45f06;">$Workbook</span>.Close() </code></span><br style="background-color: white; color: #191919; font-family: Arimo; font-size: 15px; line-height: 21px;" /><span style="background-color: white; color: #191919; font-family: Arimo; font-size: x-small;"><code><span style="color: #b45f06;">$Excel</span>.Quit() </code></span></div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-56411665581990210432013-05-10T07:39:00.003-07:002013-05-10T07:39:49.832-07:00Deploying Workflow as WSP File<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
In this article we can learn how to:</div>
<ul style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">Create WSP using Visual Studio 2010</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Deploy WSP to another SharePoint site</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Export a Workflow as WSP</li>
</ul>
<div>
<span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<h3 style="text-align: left;">
<span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;"><span style="font-size: 14px;">WSP Extension</span></span></h3>
<div>
<span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">A file with WSP extension represents SharePoint Solution Package. It is actually a cab file. When we create a workflow and make a WSP file we can use the file to deploy the Workflow to multiple SharePoint sites.</span></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span></div>
<h3 style="text-align: left;">
<span style="background-color: white; font-size: 14px;"><span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;">Creating a WSP File inside Visual Studio</span></span></h3>
<div>
<span style="background-color: white; font-size: 14px;"><span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;"><br /></span></span></div>
<div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
We have to use the Package command for the solution to create the WSP file.</div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkPcMFs4QhsVvNF-8t7VXCFz_-za6725VnA2kSUJuvJSOPrmWokGqLrVYj2lb5j3yoy5ILRaEaXufMFJa_Aytn2GTq4MTrE3-5zfxjA1iLB58IThV3w3-SpH66N0OzH3xYs_3e6FzRwc8/s1600/image001.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkPcMFs4QhsVvNF-8t7VXCFz_-za6725VnA2kSUJuvJSOPrmWokGqLrVYj2lb5j3yoy5ILRaEaXufMFJa_Aytn2GTq4MTrE3-5zfxjA1iLB58IThV3w3-SpH66N0OzH3xYs_3e6FzRwc8/s1600/image001.jpg" /></a></div>
<div>
<br /></div>
<div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
You can get the WSP file inside the bin\Debug folder of the solution.</div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvufVymgL-JLcjJNpuJh_DgKmXIR-9Afsi0c6UMNwcd60mgtv1UYcFPR8JNFk_RHZg2dWM-v7_Uw7SRTK4mP22waaARhYAcJVRXkYMGmscrgtFuN7w1gjIByG94BtmAfxdZf0BQV7clRg/s1600/image002.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvufVymgL-JLcjJNpuJh_DgKmXIR-9Afsi0c6UMNwcd60mgtv1UYcFPR8JNFk_RHZg2dWM-v7_Uw7SRTK4mP22waaARhYAcJVRXkYMGmscrgtFuN7w1gjIByG94BtmAfxdZf0BQV7clRg/s1600/image002.jpg" /></a></div>
<div>
<br /></div>
<div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
The WSP file is actually a cabinet file. You can try opening it with Winzip/Winrar as shown below to see the contents.</div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMyQbrSAMjgcF2iqhlNd1_68IQxrjvCtDsTynJEiYsVjFfYqxbA4C7XxrfgQS2zalGISFnjF31RVXJaooPd58k8QgIlUlkJuGbXmk-HgOWVgX4y52tA0jraUNn5xbex7JoC9FVjPgJAFI/s1600/image003.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMyQbrSAMjgcF2iqhlNd1_68IQxrjvCtDsTynJEiYsVjFfYqxbA4C7XxrfgQS2zalGISFnjF31RVXJaooPd58k8QgIlUlkJuGbXmk-HgOWVgX4y52tA0jraUNn5xbex7JoC9FVjPgJAFI/s1600/image003.jpg" /></a></div>
<div>
<br /></div>
<h3 style="text-align: left;">
Deploying WSP to SharePoint</h3>
<div>
<br /></div>
<div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Now we can deploy the WSP file to SharePoint. For this do the following steps.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Open the SharePoint site and use Site Settings > View All Site Content > Site Assets.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3xJL4xx_gBPmE-8lAeCQLoan6QQxokCnqrVQwl5xcshQZwoKDvzdsMeJdFq5WTxK9meRmX7pTsAomER0XqZGRe1Pv47i_0nK6Rx9st_vMVUMVLvEimfStKFoWk_oexC3d_50xeN_HhtY/s1600/image004.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3xJL4xx_gBPmE-8lAeCQLoan6QQxokCnqrVQwl5xcshQZwoKDvzdsMeJdFq5WTxK9meRmX7pTsAomER0XqZGRe1Pv47i_0nK6Rx9st_vMVUMVLvEimfStKFoWk_oexC3d_50xeN_HhtY/s1600/image004.jpg" /></a></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white;">
</div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Click on the Add document link as highlighted above.</div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div class="separator" style="clear: both; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC2ylAvOcfv1RUx4lmNu04r5cphxcORgdaK7dELsQz78MtePyzrWuWiCiLRmZG7tHa9UDF2YyYT9tFarfaZndYMl9DmW1lmJ0ZVfUuhZJLbV8ymzv50r1JFGBRdt4rPYPwh994Fv_Z3kU/s1600/image005.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC2ylAvOcfv1RUx4lmNu04r5cphxcORgdaK7dELsQz78MtePyzrWuWiCiLRmZG7tHa9UDF2YyYT9tFarfaZndYMl9DmW1lmJ0ZVfUuhZJLbV8ymzv50r1JFGBRdt4rPYPwh994Fv_Z3kU/s1600/image005.jpg" /></a></div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
In the appearing dialog box select the WSP file we generated and click the OK button.</div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
After this step we need to activate the solution from Site Settings > Galleries > Solutions.</div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<h3 style="text-align: left;">
<span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;"><span style="font-size: 14px;">Deploying using stsadm</span></span></h3>
</div>
<div>
<span style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">We can deploy the solution using the command line tool of SharePoint. You can open the </span><strong style="border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">SharePoint 2010 Management Shell</strong><span style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"> console from the start menu. Execute the following command once in the debug folder.</span></div>
<div>
<span style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span></div>
<div>
<pre id="pre0" lang="text" style="background-color: #fbedbb; border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">Stsadm –o addsolution –filename YourSolution.WSP</pre>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKZtuevS5B_iiXxdLXRHQWyDmETwKsNGw6RjwTOVPGdAm5QXV22nEacPfdd0wYmysfkHiA8WG0IQBbBQIJp5_Auf7DRsJYxMRtD0LOkcULhhzb24W9jOJAJmQI1806JDSK8Akj_VqRZj4/s1600/image006.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKZtuevS5B_iiXxdLXRHQWyDmETwKsNGw6RjwTOVPGdAm5QXV22nEacPfdd0wYmysfkHiA8WG0IQBbBQIJp5_Auf7DRsJYxMRtD0LOkcULhhzb24W9jOJAJmQI1806JDSK8Akj_VqRZj4/s1600/image006.jpg" /></a></div>
<div>
<span style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">Once done with the above command open SharePoint Central Administration and from System Settings > Manage Farm Solutions > Select the workflow and click on Deploy Solution button as shown below.</span></div>
<div>
<span style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiSgNCYIKQoWd_3xw0AyNj4VwuwC47-1vCXT49Hhm_sz2IiG9TsbeK20pKp4XPPf6yw69qLFLGpQqB2QN-qTfNoYsz_q5I59iJVuFeitYJ_NUD-bPaR5FQpz8cAcjU7ub-CekO5qiipz0/s1600/image007.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiSgNCYIKQoWd_3xw0AyNj4VwuwC47-1vCXT49Hhm_sz2IiG9TsbeK20pKp4XPPf6yw69qLFLGpQqB2QN-qTfNoYsz_q5I59iJVuFeitYJ_NUD-bPaR5FQpz8cAcjU7ub-CekO5qiipz0/s1600/image007.jpg" /></a></div>
<div>
<span style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">Now go back to the SharePoint site and use Site Actions > Site Settings > Site collection features to activate the workflow.</span></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYyDHknNJaczCevid4fsoAvVBrNlDgOIcvN9wWH9RZKubzrI162jCaqaSEZPUfAPIQUrNeKNo-vCzXKqSYRIXklxNYK8jr9uxCDsPbg0mxpdi2KVWQ9yozOrflzgbvYH-6bJOKH7cOvKQ/s1600/image008.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYyDHknNJaczCevid4fsoAvVBrNlDgOIcvN9wWH9RZKubzrI162jCaqaSEZPUfAPIQUrNeKNo-vCzXKqSYRIXklxNYK8jr9uxCDsPbg0mxpdi2KVWQ9yozOrflzgbvYH-6bJOKH7cOvKQ/s1600/image008.jpg" /></a></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span></div>
<div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Now use the Site Actions > Site Settings > Workflow settings page to add the workflow.</div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOGbW6PS_Kz4IZfD1vcLskbcNBy-isKVTZ-zFhQDocBNQmXz1Tx1yECfacywJo_ar3ttJE2_59pfx3ckdtJEgXRQeoEjsRy_uAKRt8ZYK6ifqPQUHC3z0_hazqN8re6diSzZa3bEEzGEI/s1600/image009.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOGbW6PS_Kz4IZfD1vcLskbcNBy-isKVTZ-zFhQDocBNQmXz1Tx1yECfacywJo_ar3ttJE2_59pfx3ckdtJEgXRQeoEjsRy_uAKRt8ZYK6ifqPQUHC3z0_hazqN8re6diSzZa3bEEzGEI/s1600/image009.jpg" /></a></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">The deployment is completed and the Workflow is activated. You can access the workflow from List > Site Workflows > WF2.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUH-jBL5x0Fji8vu8ghX7S4ySDzRkIK_Eh1d1Ahu4Ev1aXBQSG8vE3O37nMvPgKLN8mdGAEowv3MCcRe1WUbspI4pwcOu2VXxhjdXlX1WJgqZG3QQ_vmKkQotOB5qQ_GJoyi7UwzKFCn4/s1600/image010.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUH-jBL5x0Fji8vu8ghX7S4ySDzRkIK_Eh1d1Ahu4Ev1aXBQSG8vE3O37nMvPgKLN8mdGAEowv3MCcRe1WUbspI4pwcOu2VXxhjdXlX1WJgqZG3QQ_vmKkQotOB5qQ_GJoyi7UwzKFCn4/s1600/image010.jpg" /></a></div>
<div>
<br /></div>
<h3 style="text-align: left;">
Export a Workflow as WSP</h3>
<div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Now we can try exporting a WSP file from an existing SharePoint site. The exported file can be used to deploy to another SharePoint server. For exporting follow the steps below.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Open Site Assets from Site Actions > View All Site Content.</div>
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9SpPBAfXYfwHvCbHyzv0B3AfN-Nba2jOgEpA-1ghmWThuNgAkEWuu4cJRx7YovEozVnv_J92Ajg6UanVrX4aLFyo8iFL949bi_ghJuudm3SLy5TNzJAGOeou0uDBLbvvFjPlliLpmhMU/s1600/image011.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9SpPBAfXYfwHvCbHyzv0B3AfN-Nba2jOgEpA-1ghmWThuNgAkEWuu4cJRx7YovEozVnv_J92Ajg6UanVrX4aLFyo8iFL949bi_ghJuudm3SLy5TNzJAGOeou0uDBLbvvFjPlliLpmhMU/s1600/image011.jpg" /></a></div>
<div>
<br /></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">Click on an existing Workflow, for example Contact Workflow in the above screen. The browser will prompt with the Save As dialog. Click the Save button to get the WSP file. This file can be used to deploy the solution to another SharePoint server.</span></div>
</div>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-44566328598318638482013-05-10T07:22:00.003-07:002013-05-10T07:22:25.685-07:00Apps in SharePoint 2013<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="text-align: left;">
Why Apps? What's wrong with Solutions?</h3>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">The world is getting smaller day by day, thanks to technology. Big desktops became Bulky laptops. Bulky laptops became Notebooks. Notebooks became Ultra books. Now the trend is moving towards Tablets and Smart phones. So does our applications. Web applications becoming Apps. "</span><strong style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">Apps</strong><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">" is not just a marketing strategy to increase use of SharePoint in wider markets, but also a complete replacement of sandbox approach with many other Pros for both Development, Deployment and Usage.</span></div>
<div>
<br /></div>
<h3 style="text-align: left;">
Do you know that sandbox solutions are deprecated in 2013?</h3>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">Sandbox Solutions are introduced in SP 2010 and now they are off, to encourage the usage of Apps. May be we should understand the seriousness of Microsoft towards "Apps" in future. </span><strong style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">Of- course the conventional SP solution approach is still there.</strong></div>
<div>
<br /></div>
<h4 style="text-align: left;">
SP 2013 Development Options</h4>
<div>
<ol style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">Full-trust SharePoint Solutions (WSP)</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Apps</li>
</ol>
</div>
<h3 style="text-align: left;">
<span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;"><span style="font-size: 14px;">Main reasons for "Apps" development</span></span></h3>
<div>
<ol style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">Custom code will not be executed on server. So this can avoid, Application / Server outages.</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Custom code will be executed in Client-Browser or may be in some other scope like IIS or Windows Azure, which is completely out of SharePoint scope.</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Server Object Model (SOM) code is replaced by Client side object model (CSOM) / Rest Services using which Apps can communicate with Server. Authentication is done by OAuth.</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Installing / Updating / Uninstalling of apps can be done without affecting the SharePoint site.</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Better usability in Tablets and Mobile devices.</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Taking SharePoint to next level in terms of Usability, Development, Deployment and Hosting(cloud).</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Finally, everything in SharePoint 2013 is an App.</li>
</ol>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
I know, the next question is "<strong style="border: 0px; margin: 0px; padding: 0px;">Most of these reasons are just sounding like reasons for Sandbox Solutions?</strong>" Well I have a question for you, how many times we have chosen sandbox solution for real-time implementation?</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
<ol style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">No full object model . . .</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Understanding of Sandbox architecture</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Not an easy task to create proxies for execution of full trust code.</li>
</ol>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
What ever may be the reason, real-time applications are tough to develop using a Sandbox solution. That is why "Apps" are introduced in SharePoint 2013 for ease of development and deployment.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<h3 style="text-align: left;">
<span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;"><span style="font-size: 14px;">Hosting Options in Apps</span></span></h3>
</div>
<div>
<ol style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">Provider-hosted</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Hosted in the cloud (Windows Azure autohosted)</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Hosted in a SharePoint environment</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Several combinations of these options.</li>
</ol>
<div>
<span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlkpKypm-K4Ko7rCMweFWBsLdE_YulmKDyos1jPJq6mlEPMhTzBi7hNqi5fnc42OVt7vyXZzajlKV0J7UucZKYHW5937wonjRQ6OxYsgExg808YLMRAEync7Attn4p3WnC3kLndKE9j4g/s1600/2%5B1%5D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlkpKypm-K4Ko7rCMweFWBsLdE_YulmKDyos1jPJq6mlEPMhTzBi7hNqi5fnc42OVt7vyXZzajlKV0J7UucZKYHW5937wonjRQ6OxYsgExg808YLMRAEync7Attn4p3WnC3kLndKE9j4g/s1600/2%5B1%5D.gif" /></a></div>
<div>
<span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
</div>
<h3 style="text-align: left;">
<span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;"><span style="font-size: 14px;">How apps for SharePoint Work</span></span></h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdCryrirbElkmxcHhXjUlzeShfXNEP2Cj_8mKI0QioyQukYY4YSmn6g-BGHk_j3EFLK5zL035O3EhGU0avjH7Pa3ZvANNFN4f3ZfNe-SUCZrn87v-0C-6yGumyX48eBtjKMiO3qC6iadY/s1600/3%5B1%5D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdCryrirbElkmxcHhXjUlzeShfXNEP2Cj_8mKI0QioyQukYY4YSmn6g-BGHk_j3EFLK5zL035O3EhGU0avjH7Pa3ZvANNFN4f3ZfNe-SUCZrn87v-0C-6yGumyX48eBtjKMiO3qC6iadY/s1600/3%5B1%5D.gif" /></a></div>
<div>
<span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
In above case, App1 is a Provider-hosted or a Cloud-Hosted (Auto-Hosted) app and App2 is a SharePoint Hosted App. So anything related to App1 will be created/Maintained in respective locations, either on Provider or Azure servers. This makes App1 safe and secure in execution perspective.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Now we need to look at App2.<br />When you create/Imported/Added a SharePoint-Hosted App, it will create a separate sub-web under your SP Web application. This app will be executed in a separate App Domain different from Farm App Domain. So, as process runs under App Domains, any exceptions in Apps will not cause any Outage to SharePoint Farm.</div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYD-TMrxDvQ6wAZe_GaiYEdu0sE_ok5T7qRgseS1ytw0XdG7l2a_RfPKiUeodohHf7lUputpg6JUQODvSsPQRvn9yNdAeMm8Ip2f-u7Rf8Qy8yvTsm82f71YSUH233hEbFcbyXi-KY4Cg/s1600/5%5B1%5D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYD-TMrxDvQ6wAZe_GaiYEdu0sE_ok5T7qRgseS1ytw0XdG7l2a_RfPKiUeodohHf7lUputpg6JUQODvSsPQRvn9yNdAeMm8Ip2f-u7Rf8Qy8yvTsm82f71YSUH233hEbFcbyXi-KY4Cg/s1600/5%5B1%5D.gif" /></a></div>
<div>
<br /></div>
<div>
<div class="text" id="contentdiv" style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">
We will see the creation of an SharePoint-Hosted App and issues involved in doing so, in our next post.</div>
</div>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-4061470512756109002013-05-08T08:12:00.002-07:002013-05-08T08:12:40.925-07:00Developing Sharepoint Windows Forms<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Intro:</b><br />
<b><br /></b>
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
this Tip is for all developers who would like to make a user friendly Interface using sharepoint sites and Objects.</div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span>
developing a windows Form is a good choice when it comes to fast interactive tool instead of using Basic console Application </span><br />
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">I'm going to list the steps in details to create the windows form </span><br style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;" /><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">Application and how does it support Sharepoint Objects model. </span><br />
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><b>STEP 1:</b></span><br />
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><b><br /></b></span>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">First go to Visual Studio 2010 and Create New Project </span><span style="background-color: white; border: 0px; color: #111111; font-family: Wingdings; font-size: 14px; margin: 0px; padding: 0px;"></span><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">choose the programming language for example C# </span><span style="background-color: white; border: 0px; color: #111111; font-family: Wingdings; font-size: 14px; margin: 0px; padding: 0px;"></span><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">then choose </span><strong style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">Windows Forms Application</strong><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"> </span><br />
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvxwkPVK6NOjabvel3Fphl1l_95HPE0qqg564HTMNsahFskh_zS6ZSS2B_IvTMSbYaflQwNq_OQccur4DyDCLWrk3Mw0WvbWBs_HBaNtlPD7f0rgAT6d8sxyUAyGrKzHo3EIq-xvScd7k/s1600/st1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="263" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvxwkPVK6NOjabvel3Fphl1l_95HPE0qqg564HTMNsahFskh_zS6ZSS2B_IvTMSbYaflQwNq_OQccur4DyDCLWrk3Mw0WvbWBs_HBaNtlPD7f0rgAT6d8sxyUAyGrKzHo3EIq-xvScd7k/s400/st1.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; text-align: start;">
<b>STEP 2:</b></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; text-align: start;">
<b><br /></b></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; text-align: start;">
Rename the Project ,then when it is created right click the Project to edit the <strong style="border: 0px; margin: 0px; padding: 0px;">properties</strong> </div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjK5H_6HtYrak_JfF6B4dpeWmWq7Xmphl2w7aS2z4E1jbnbkNkBUNHrHu6ykw39I4xDgIPc7WfUWeKq1Z-k_Lv5W421ZOLDCW3DIl0YWpt7qryoStXELsB2nbOT4i_vace88e_WMv3qhDg/s1600/st2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="207" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjK5H_6HtYrak_JfF6B4dpeWmWq7Xmphl2w7aS2z4E1jbnbkNkBUNHrHu6ykw39I4xDgIPc7WfUWeKq1Z-k_Lv5W421ZOLDCW3DIl0YWpt7qryoStXELsB2nbOT4i_vace88e_WMv3qhDg/s400/st2.jpg" width="400" /></a></div>
<div>
<br /></div>
<div style="text-align: left;">
<b>STEP 3:</b></div>
<div style="text-align: left;">
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
In the Application tab choose the target frame work <strong style="border: 0px; margin: 0px; padding: 0px;"> .net FrameWork 3.5</strong>.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM_i9LhEzoFu-RUzccSDJT5V5efBQCJX8yAmQHXVeLuqB5MH4KW0kfz4fyluRDvFB5wGi3lAAbayIL-w-bQgtbIDt4QctVOkb1_h-y86nfAhXi_LapmtalSmRyqKuAagN35PmL_yvc5JA/s1600/st3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="206" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM_i9LhEzoFu-RUzccSDJT5V5efBQCJX8yAmQHXVeLuqB5MH4KW0kfz4fyluRDvFB5wGi3lAAbayIL-w-bQgtbIDt4QctVOkb1_h-y86nfAhXi_LapmtalSmRyqKuAagN35PmL_yvc5JA/s400/st3.jpg" width="400" /></a></div>
<div>
<br /></div>
<div>
<b>STEP 4:</b></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">In the Build tab change the platform target to</span><strong style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;"> Any CPU</strong><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">. </span></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhVVlJbi_K8zWkZuc2V_lkYGbsOCl9FCyyAzJOtobLW9WnH0mlYjHO83yKjFTeRBEAoAaTWLJkDVOYnPIE5j-KJ5KoCwlXnb3bp6uNLH-faC4XWz_w78rKTi0kVaQmu64IvbWpSFUDkiE/s1600/st4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="207" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhVVlJbi_K8zWkZuc2V_lkYGbsOCl9FCyyAzJOtobLW9WnH0mlYjHO83yKjFTeRBEAoAaTWLJkDVOYnPIE5j-KJ5KoCwlXnb3bp6uNLH-faC4XWz_w78rKTi0kVaQmu64IvbWpSFUDkiE/s400/st4.jpg" width="400" /></a></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><b>STEP 5:</b></span></div>
<div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><b><br /></b></span></div>
<div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Right click references and add<br />sharepoint references,<strong style="border: 0px; margin: 0px; padding: 0px;"> Microsoft.SharePoint .dll,<br />Microsoft.SharePoint.Client, Microsoft.SharePoint.Client.Runtime</strong>. </div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
select Browse go to the 14% (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7IYBbDJHqlt1MhpKRdsWHyTIMyMoy2FjXsz2a5T7VhV3rjgtAmjx9AWLJSiSqKpemgxLm0QjgkL6Oh2JCLReHGlw0EnMqeWYgIm7lqFkU5kRN5HzOuf29aumR_rOt3JwEgDHb92JJbuI/s1600/st5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="313" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7IYBbDJHqlt1MhpKRdsWHyTIMyMoy2FjXsz2a5T7VhV3rjgtAmjx9AWLJSiSqKpemgxLm0QjgkL6Oh2JCLReHGlw0EnMqeWYgIm7lqFkU5kRN5HzOuf29aumR_rOt3JwEgDHb92JJbuI/s400/st5.jpg" width="400" /></a></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<b>STEP 6:</b></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<b><br /></b></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
right click the Form and select view code to go to the CS file then Add the<strong style="border: 0px; margin: 0px; padding: 0px;"> using statement</strong> in the CS file <br />
<div class="MsoNormal">
<span style="border: 0px; color: blue; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;">using</span><span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> Microsoft.SharePoint;</span> </div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjD4s9OWSTaD9S2hVnchUzwzrRN-boy9S_ZJdkm1JJHNfDsHi2K4EUOri4nJHa47L5wD8CdVmNnUnqKRxQFVRp6hKwC2bAR3FIrk1kTqmrCLhWrTqCvaJun-syBJ2Cun6DOarofY6TfXAY/s1600/st6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="218" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjD4s9OWSTaD9S2hVnchUzwzrRN-boy9S_ZJdkm1JJHNfDsHi2K4EUOri4nJHa47L5wD8CdVmNnUnqKRxQFVRp6hKwC2bAR3FIrk1kTqmrCLhWrTqCvaJun-syBJ2Cun6DOarofY6TfXAY/s400/st6.jpg" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>STEP 7:</b></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
Design the form (add the controls , labels, textboxes…etc.) I have designed a simple form with 2 labels 1 text box and 1 button.</div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq3Dy_ARUM0HFNZHGTi9dh-1vJGQDXYhTZv0UFQ3is2XWjbYH0swaoKUbf-fUSwPbAJjDyO-_Fwj485ZyG9q7IqmOYMhdxPtIIAToNuv-W5FluAoyg9_THn76n-4Mosl91R7aE4bdnKnU/s1600/st7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="167" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq3Dy_ARUM0HFNZHGTi9dh-1vJGQDXYhTZv0UFQ3is2XWjbYH0swaoKUbf-fUSwPbAJjDyO-_Fwj485ZyG9q7IqmOYMhdxPtIIAToNuv-W5FluAoyg9_THn76n-4Mosl91R7aE4bdnKnU/s400/st7.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>STEP 8:</b></div>
<div class="separator" style="clear: both; text-align: left;">
<b><br /></b></div>
<div class="separator" style="clear: both; text-align: left;">
If you have button just right click the button and choose view code <span style="border: 0px; font-family: Wingdings; margin: 0px; padding: 0px;"></span>insert the sharepoint code in the button action .<span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> </span></div>
this is only a simple code that will ask the user to enter URL and click on the button that will display the title of the Site.<span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> </span><span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"></span><br />
<span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> <span style="border: 0px; color: blue; margin: 0px; padding: 0px;">private</span> <span style="border: 0px; color: blue; margin: 0px; padding: 0px;">void</span> button1_Click(<span style="border: 0px; color: blue; margin: 0px; padding: 0px;">object</span> sender, <span style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">EventArgs</span> e)</span><br />
<div class="MsoNormal">
<span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> {</span></div>
<div class="MsoNormal">
<span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> <span style="border: 0px; color: green; margin: 0px; padding: 0px;">//ask the user to enter Site Collection URL</span></span></div>
<div class="MsoNormal">
<span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> <span style="border: 0px; color: blue; margin: 0px; padding: 0px;">string</span> SiteURL = textBox1.Text;</span></div>
<div class="MsoNormal">
<span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> <span style="border: 0px; color: blue; margin: 0px; padding: 0px;">using</span> (<span style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">SPSite</span> SiteCollection = <span style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> <span style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">SPSite</span>(SiteURL))</span></div>
<div class="MsoNormal">
<span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> {</span></div>
<div class="MsoNormal">
<span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> label2.Visible = <span style="border: 0px; color: blue; margin: 0px; padding: 0px;">true</span>;</span></div>
<div class="MsoNormal">
<span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> label2.<wbr></wbr>ForeColor = System.Drawing.<span style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">Color</span>.Green;</span></div>
<div class="MsoNormal">
<span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> label2.Text = <span style="border: 0px; color: #a31515; margin: 0px; padding: 0px;">"Site Collection URL is :"</span> + SiteCollection.RootWeb.Title.<wbr></wbr>ToString();</span></div>
<div class="MsoNormal">
<span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> }</span></div>
<div class="MsoNormal">
<span style="border: 0px; font-family: Consolas; font-size: 9.5pt; margin: 0px; padding: 0px;"> }</span> </div>
</div>
</div>
<br />
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4-UBqKi35ZzdD1VgBcNYerreZdBYIeU74wIr2xYKC7_OXMqja3SwuZc0tp_944HywKSnn4KFFFmLRHKnMaak_l00DJHDxEyHtmPrnWAbtlCFavmqiEDscesS1aK1LjiIIjN5jf5zLAgw/s1600/st8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="171" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4-UBqKi35ZzdD1VgBcNYerreZdBYIeU74wIr2xYKC7_OXMqja3SwuZc0tp_944HywKSnn4KFFFmLRHKnMaak_l00DJHDxEyHtmPrnWAbtlCFavmqiEDscesS1aK1LjiIIjN5jf5zLAgw/s400/st8.jpg" width="400" /></a></div>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><b>STEP 9:</b></span><br />
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">you are done now , only run the solution and you can display the </span><strong style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">windows form</strong><br />
<strong style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;"><br /></strong>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrnHBsQ8Z-3Yo_3pnscNIvJg_TNh5UZxQ4c3lY-2e6v485eV4m4B6zEjumq4rfwIb3QjoZgQ-CHZGEqc9MUCo6C9LgvUzKNGb-brv7ZQtRbUbXiDJKBqJ46ecVffObQujsJZ7kctUkCBw/s1600/st9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrnHBsQ8Z-3Yo_3pnscNIvJg_TNh5UZxQ4c3lY-2e6v485eV4m4B6zEjumq4rfwIb3QjoZgQ-CHZGEqc9MUCo6C9LgvUzKNGb-brv7ZQtRbUbXiDJKBqJ46ecVffObQujsJZ7kctUkCBw/s1600/st9.jpg" /></a></div>
<strong style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;"><br /></strong>
<strong style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;"><br /></strong></div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-39172253013571868192013-05-08T07:57:00.003-07:002013-05-08T07:57:57.401-07:00Granting Anonymous Access to Sharepoint List / Library Programmatically<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
In this post, we will see how to enable and disable Anonymous access to a List or Document library from a Sharepoint feature (C# code).</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
There are 3 different steps involved in granting Anonymous access to a List/Library in a right way.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<b>STEP1:</b></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<b><br /></b></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Enabling the anonymous access to the Web application from Central Admin. This does not mean that the whole web application is now anonymous. This step signifies that this web application has the ability to host resources that can be accessed by Anonymous user.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9IWri23qnk-kN4jaSUY9thZpnK9fREDAYvggUTs1Xz8nqQvPg3ZUH3MFLITSof2EopMpz21AD6z3kWZRNwOeghTdqfXJwiU_VCoODPVnTjRFhzb2DFItYPZBwG5jDUHynMdZOchbERWE/s1600/1%5B3%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9IWri23qnk-kN4jaSUY9thZpnK9fREDAYvggUTs1Xz8nqQvPg3ZUH3MFLITSof2EopMpz21AD6z3kWZRNwOeghTdqfXJwiU_VCoODPVnTjRFhzb2DFItYPZBwG5jDUHynMdZOchbERWE/s1600/1%5B3%5D.png" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
Then,</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidKwUutA2w1UhUsxK5rUoRc2qdCa4Mhp5AIx5OZ-6E6zMgq-uVvS_HIZnlhB8YwwTV5l7UFxcbBTc3sE4BlrlzBaNs_x_P9XOn6oGT3oFJzE08uldc1ktYXPHHWdNCbyQEz4jdTnFzrDI/s1600/2%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidKwUutA2w1UhUsxK5rUoRc2qdCa4Mhp5AIx5OZ-6E6zMgq-uVvS_HIZnlhB8YwwTV5l7UFxcbBTc3sE4BlrlzBaNs_x_P9XOn6oGT3oFJzE08uldc1ktYXPHHWdNCbyQEz4jdTnFzrDI/s1600/2%5B1%5D.png" /></a></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Then,</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXMUp4DdUvsMiNGtHtNV9QrESGiwduR8xud52AKdJw7j2F-VKhi-XaZ3tF5gcDG-Se6XRZy48NupYGJftKQp_tvNhyamF_sg-sOeb56qxoKeCJgG1zbulLNSa5EQHC32yq_etpXyPlHhM/s1600/3%5B3%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXMUp4DdUvsMiNGtHtNV9QrESGiwduR8xud52AKdJw7j2F-VKhi-XaZ3tF5gcDG-Se6XRZy48NupYGJftKQp_tvNhyamF_sg-sOeb56qxoKeCJgG1zbulLNSa5EQHC32yq_etpXyPlHhM/s1600/3%5B3%5D.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">Now click save and close Central Admin. I am pointing again that </span><strong style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">the above step will not make the whole web application accessible to anonymous users</strong><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">. This will </span><strong style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">create scope for hosting something that can be accessible by anonymous user</strong><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><b>STEP2:</b></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><b><br /></b></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">Enabling the Anonymous permissions in Web application settings. Go to Site Permission screen. As you have already enabled Anonymous access for this web application from central admin, a new button "Anonymous Access" will appear on the ribbon.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjARPPKCUftKr0QTWbEUFUJfjVmQPL-GcqoRQ8_SXZ2g3lBvpJ9E6mlZnO77HWVspCb9p6nZ6GH6p9etu3uqtTljFEgpRIZV-mWvI7BrgmGL25NDoF0_fV1KhYW8R5KM-ZbjhPugIKeTUg/s1600/4%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="87" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjARPPKCUftKr0QTWbEUFUJfjVmQPL-GcqoRQ8_SXZ2g3lBvpJ9E6mlZnO77HWVspCb9p6nZ6GH6p9etu3uqtTljFEgpRIZV-mWvI7BrgmGL25NDoF0_fV1KhYW8R5KM-ZbjhPugIKeTUg/s400/4%5B1%5D.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Now, the list can be accessed by unauthenticated / anonymous users.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
But, in real time scenarios, <strong style="border: 0px; margin: 0px; padding: 0px;">step 3 is not recommended</strong> as it involves manual intervention in granting access, which is not possible in most of the PRODUCTION scenarios.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
So, it is recommended to perform step 3 using a feature activation or de-activation.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Here is the code for making a Document library anonymous while activating a feature.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbq7_5j1fqreF17fS66b68h5pkVGfe0bp3bbjDXxrA8KLlM9c_ah503HOxqnF_N36xfLg3A2C5k7DHy2lQLNjqdvutdujgTyvGhf4ndIntxnN5qtPOSHUgZzrzaDBo9XurW45LeeozHes/s1600/8%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="305" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbq7_5j1fqreF17fS66b68h5pkVGfe0bp3bbjDXxrA8KLlM9c_ah503HOxqnF_N36xfLg3A2C5k7DHy2lQLNjqdvutdujgTyvGhf4ndIntxnN5qtPOSHUgZzrzaDBo9XurW45LeeozHes/s400/8%5B1%5D.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Here is the code for removing Anonymous access to a Document library while de-activating a feature.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjml1T9ApwfyrsxT3AW58Uv6mIBnybk3M-3xu1FgyuMv07WX43vR5ir8UA2j1Xaqh3GdFNk9GedN4HbdlFRoa1igHC-jP6rZVtv2qcHwx1oQU6mW4ddIbYK-cdlXpO3h3mvxbYR3sdmVFE/s1600/9%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjml1T9ApwfyrsxT3AW58Uv6mIBnybk3M-3xu1FgyuMv07WX43vR5ir8UA2j1Xaqh3GdFNk9GedN4HbdlFRoa1igHC-jP6rZVtv2qcHwx1oQU6mW4ddIbYK-cdlXpO3h3mvxbYR3sdmVFE/s1600/9%5B1%5D.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; text-align: start;">
Happy coding!</div>
<div>
<br /></div>
<br />
<div>
<br /></div>
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-54413956447096015222013-05-08T07:48:00.004-07:002013-05-08T07:48:50.268-07:00Change Site Collection URL in SharePoint 2010<div dir="ltr" style="text-align: left;" trbidi="on">
<b>The Problem</b><br />
<b><br /></b>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">If you want to change the site name (i.e. </span><a href="http://myserver/sites/SiteName/" style="background-color: white; border: 0px; color: purple; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-decoration: none;">http://myserver/sites/<strong style="border: 0px; margin: 0px; padding: 0px;">SiteName</strong>/</a><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">) in the site collection URL, you can't use Site Setting or Central Administration. Unfortunately, the only way is backup the site, delete it and restore in a new site with the right name.</span><br />
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">In Sharepoint 2007, you can use the </span><em style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">stsadm</em><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"> command to do this, but in SharePoint 2010 you can't do this. You have to use Windows PowerShell for SharePoint.</span><br />
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span>
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
First of all, open SharePoint 2010 Management Shell, you can find it under Microsoft SharePoint 2010 Products in the Start menu.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
The first step is backup the current site:</div>
<div class="pre-action-link" id="premain0" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre0" lang="text" style="background-color: #fbedbb; border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">//
// Backup-SPSite http://myserver/sites/OldSiteName/ -Path C:\MySite.bak
// </pre>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
After that, delete the site using the following code:</div>
<div class="pre-action-link" id="premain1" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre1" lang="text" style="background-color: #fbedbb; border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">//
// Remove-SPSite –Identity http://myserver/sites/OldsiteName/
// </pre>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<strong style="border: 0px; margin: 0px; padding: 0px;">NOTE:</strong> This step is necessary only if you want to restore the buckup in the same server of the old site. You have to do this because after the restore, a lot of items (i.e. lists) use the same IDs of the original site.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Now you can restore the site in a collection with the right name:</div>
<div class="pre-action-link" id="premain2" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre2" lang="text" style="background-color: #fbedbb; border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">//
// Restore-SPSite http://myserver/sites/NewSiteName/ -Path C:\MySite.bak
// </pre>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-36918568353397144552013-05-08T07:40:00.000-07:002013-05-08T07:40:08.303-07:00Create an SSL Site in SharePoint 2010<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
As part of development activities we might need to create an SSL enabled site inside SharePoint 2010. These sites will be accessed using <strong style="border: 0px; margin: 0px; padding: 0px;">HTTPS</strong> instead of HTTP.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
For example:</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn10mld-jr7NYczfpnw_und6ULdfCmbaPgOjAuNzpzH8O0hQq6nVJEINX58evjB-ODhMzi6aOWsTv0DFOB1-4yNnKrygELU1nuRMdZ4ATMhtlv__35LL8X4kHrIoG-EdwC3NkNG5A6jJA/s1600/image001%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn10mld-jr7NYczfpnw_und6ULdfCmbaPgOjAuNzpzH8O0hQq6nVJEINX58evjB-ODhMzi6aOWsTv0DFOB1-4yNnKrygELU1nuRMdZ4ATMhtlv__35LL8X4kHrIoG-EdwC3NkNG5A6jJA/s1600/image001%5B1%5D.png" /></a></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
HTTPS is the secured way of communication between server and client. Here the message is encrypted between client and server. An encryption mechanism is needed protect the message from being manipulated by unwanted parties.<br />
<br />
HTTPS works by installing a certificate in the server side web application. This certificate is used to encrypt the messages between client and server. The encryption is based on a public key and private key usage. The public key will be shared with client for encrypting the message and the decryption is performed on the server side using the private key.<br />
<br />
<strong style="border: 0px; margin: 0px; padding: 0px;">Note</strong>: Stealing the public key does not do any favour in decrypting the message using <strong style="border: 0px; margin: 0px; padding: 0px;">Man In the Middle</strong> attack as Public key can only be used for encryption.<br />
<br />
Please following the steps given below to create a new SSL enabled SharePoint site.<br />
<strong style="border: 0px; margin: 0px; padding: 0px;"><br /></strong>
<strong style="border: 0px; margin: 0px; padding: 0px;">Step 1</strong>: Create New Web Application<br />
<br />
Go to Central Administration and open the Manage Web Applications link. Create a new Web Application with the following properties:<br />
<br />
<ol style="border: 0px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">Name as <strong style="border: 0px; margin: 0px; padding: 0px;">My Secured Site</strong></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Use Secured Sockets Layer (SSL) <strong style="border: 0px; margin: 0px; padding: 0px;">Yes</strong></li>
</ol>
<div>
<b><br /></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixtDdRmZwDjEnG7m_RR4_TODQ0FZ8ltyoV8CZwqeXlcLXEt5ZKGGkZzR1X4OpfRb8dr1cPohSEpM3xZPPidgc-mXiLUJj0mBPyArX3mDQkcuSICbfuTkDpxx28c8CtJ9OuI9bws2toYIA/s1600/image002%5B1%5D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixtDdRmZwDjEnG7m_RR4_TODQ0FZ8ltyoV8CZwqeXlcLXEt5ZKGGkZzR1X4OpfRb8dr1cPohSEpM3xZPPidgc-mXiLUJj0mBPyArX3mDQkcuSICbfuTkDpxx28c8CtJ9OuI9bws2toYIA/s1600/image002%5B1%5D.jpg" /></a></div>
<div>
<b><br /></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbyQPsdgl5JB6lYySdze0P5-FqSd5_hQ6PG1GB4J8hUy7xfziQXTXku2O5b0DD1baHs4wJgkGNnV7pGozVNWKGYYk1HLuF6hzOVMCFtpeACKUbzQ2uUzmt9qTMxU1Y-qJyiiaF63pfzDQ/s1600/image003%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbyQPsdgl5JB6lYySdze0P5-FqSd5_hQ6PG1GB4J8hUy7xfziQXTXku2O5b0DD1baHs4wJgkGNnV7pGozVNWKGYYk1HLuF6hzOVMCFtpeACKUbzQ2uUzmt9qTMxU1Y-qJyiiaF63pfzDQ/s1600/image003%5B1%5D.png" /></a></div>
<div>
<b><br /></b></div>
<div>
Click the OK button to create the new web application.<br />
<br />
Now add a new site collection inside the newly created web application.<br />
<br />
Central Administration > Create Sitecollection > Choose current web application<br />
<strong style="border: 0px; margin: 0px; padding: 0px;"><br /></strong>
<strong style="border: 0px; margin: 0px; padding: 0px;">Step 2</strong>: Set the Certificate<br />
<br />
For SSL enabling you need to specify a Certificate in the Server which contains the public and private keys.<br />
<br />
Go to Internet Information Services (IIS / <em style="border: 0px; margin: 0px; padding: 0px;">inetmgr.exe</em>) and select the newly created site. Click on the Bindings link from the right side.</div>
<div>
<b><br /></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheB10uvI3M_u40VwlyO-NZ0Wle1nNkTUDU3AAVHxD164ItiOJRgEfdNxDmBupS1RF9ua0MBKKCj8sfPiTKXAd5Y3B03oXLQBBTkfPv9SNczsxwbT1CRwk8JL8ZUTJ_T5MgBCBaWCFIMSI/s1600/image004%5B1%5D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheB10uvI3M_u40VwlyO-NZ0Wle1nNkTUDU3AAVHxD164ItiOJRgEfdNxDmBupS1RF9ua0MBKKCj8sfPiTKXAd5Y3B03oXLQBBTkfPv9SNczsxwbT1CRwk8JL8ZUTJ_T5MgBCBaWCFIMSI/s1600/image004%5B1%5D.jpg" /></a></div>
<div>
<b><br /></b></div>
<div>
In the appearing dialog select the <strong style="border: 0px; margin: 0px; padding: 0px;">https</strong> item and click the <strong style="border: 0px; margin: 0px; padding: 0px;">Edit </strong>button.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIeMbYqZd3WRGu3l_P_IaLFz3KnHojMU2ilNJDJRA0XmOgId8mQ6ZmCrQaes_DO0t8y8lmpHtznPHZIRLrO68FQ3fdRHuq_56iqm8SsN9e3m__8qVnacogTeTV7waP4NE_Kd9hD3yxVI8/s1600/image005%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIeMbYqZd3WRGu3l_P_IaLFz3KnHojMU2ilNJDJRA0XmOgId8mQ6ZmCrQaes_DO0t8y8lmpHtznPHZIRLrO68FQ3fdRHuq_56iqm8SsN9e3m__8qVnacogTeTV7waP4NE_Kd9hD3yxVI8/s1600/image005%5B1%5D.png" /></a></div>
<div>
<br /></div>
<div>
In the appearing dialog select the Certificate from drop down list.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgfZsiTBGuG0g0VdppJ0jvePUnKU_k3Ec1rhsJxlXEL4MS92FVGqj3MrkWVqsbyKoI8LqQ4BwS4HQQkKSc0xURJCT4JSwxPLCFDwmmPO_95JZyy8euURInCx7Xa6kC9R3TWmqgn7mnS3M/s1600/image006%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgfZsiTBGuG0g0VdppJ0jvePUnKU_k3Ec1rhsJxlXEL4MS92FVGqj3MrkWVqsbyKoI8LqQ4BwS4HQQkKSc0xURJCT4JSwxPLCFDwmmPO_95JZyy8euURInCx7Xa6kC9R3TWmqgn7mnS3M/s1600/image006%5B1%5D.png" /></a></div>
<div>
<br /></div>
<div>
Click the OK button to continue.<br />
<strong style="border: 0px; margin: 0px; padding: 0px;"><br /></strong>
<strong style="border: 0px; margin: 0px; padding: 0px;">Step 3</strong>: Test the URL.<br />
<br />
Now you are ready to test the HTTPS url. Open a browser and enter the url of the web site. You can also you the Browse link from IIS.<br />
<br />
You will get the page as shown below. It says the certificate is not trusted one. You can use the <strong style="border: 0px; margin: 0px; padding: 0px;">Continue</strong> link to proceed with.</div>
<div>
<b><br /></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWaw8RRnm-bu618yYJWPaULDwwdP7pulV8sZsQDVp7yv7BX9pnXSdpROtBOgXMMTAUgXqnF6P7xNmxR2h1kTReB3WHW4OkhibjDVWUezziS_i2wWkdcHl170IOUO1gDGcp1vHXnDdS7V8/s1600/image007%5B1%5D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWaw8RRnm-bu618yYJWPaULDwwdP7pulV8sZsQDVp7yv7BX9pnXSdpROtBOgXMMTAUgXqnF6P7xNmxR2h1kTReB3WHW4OkhibjDVWUezziS_i2wWkdcHl170IOUO1gDGcp1vHXnDdS7V8/s1600/image007%5B1%5D.jpg" /></a></div>
<div>
<b><br /></b></div>
<div>
Now you should be prompted with the site credentials. Enter the credentials to continue and you should get the site collection which you have created.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTRpa2DV0coBh52vmcNrl1c5O6XtLbHtW_f38QJBUCKA_Igk7v4m_daxmHuQDGT_IVcHsHymrg9DRji9jdg4LCSSAtd-jjp61V4NCFBKpFbhwfjI_g1YRguDaFyelZ16g0WSd2MB2dUnE/s1600/image008%5B1%5D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTRpa2DV0coBh52vmcNrl1c5O6XtLbHtW_f38QJBUCKA_Igk7v4m_daxmHuQDGT_IVcHsHymrg9DRji9jdg4LCSSAtd-jjp61V4NCFBKpFbhwfjI_g1YRguDaFyelZ16g0WSd2MB2dUnE/s1600/image008%5B1%5D.jpg" /></a></div>
<div>
<br /></div>
<div>
Wow! If you can see the above site then you are done with your SSL enabled site. Please note that the URL now starts with <strong style="border: 0px; margin: 0px; padding: 0px;">https</strong>.<br />
<h4 style="font-size: 16px;">
Adding SSL (https) support to an existing web application</h4>
You can add SSL support to an existing web application by performing the following:<br />
<ol style="border: 0px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">Open IIS manager</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Select the web application</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Choose Bindings dialog</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Add new binding of type https</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Select the Certificate</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Click the OK button</li>
</ol>
</div>
<div>
<br /></div>
<br />
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-37476974943622826062013-05-08T06:49:00.001-07:002013-05-08T06:52:50.693-07:00User Permissions in SharePoint-hosted App<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Intro:</b><br />
<b><br /></b>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">This tip demonstrates user permissions in SharePoint-hosted apps in SharePoint 2013 with attention to a multiple user scenario. It also tries to populate selective items from a SharePoint site to a SharePoint-hosted app.</span><br />
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"><br /></span>
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">While I was teaching SharePoint 2013, I noticed that participants were always intrigued by how apps would react to a multiple-user scenario and what the user permissions would be like. So I have tried to put together this scenario in this document with three dummy users. The names used in this article are imaginary and resemblance to any personalities is purely coincidental.</span><br />
<h3 style="background-color: white; color: #666666; font-family: 'Segoe UI', Arial, sans-serif; font-size: 18px; font-weight: normal;">
The Dummy Users</h3>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
I have a team-site called Office Services whose primary administrator is a user called administrator. There are two dummy users that we would be referring to in this tip:</div>
<ol style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">Anne Wallace</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Alan Steiner</li>
</ol>
<h3 style="background-color: white; color: #666666; font-family: 'Segoe UI', Arial, sans-serif; font-size: 18px; font-weight: normal;">
The SharePoint Lists Permissions</h3>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
The names of the lists might sound little strange but I have used those names in order to keep the permissions story simple. The list name basically shows the user associated. So I have created two custom lists in my team site:</div>
<ol style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">Anne ListThis list will display currencies. The administrator and the group called Anne have permissions on this list. For this, a new group called Anne was created and only Anne Wallace was added to this particular group. No permissions are granted to Alan for this list.</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Alan ListThis list will display countries. The administrator and a group called Alan have permissions on this list. For this, a new group called Alan was created and only Alan Steiner was added to this particular group. No permissions are granted to Anne for this list.</li>
</ol>
<h3 style="background-color: white; color: #666666; font-family: 'Segoe UI', Arial, sans-serif; font-size: 18px; font-weight: normal;">
SharePoint-hosted App Magic</h3>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Now let’s take a look at how an app would treat this if we login as some other user (other than administrator who is the super user). So we build a SharePoint hosted app – I have called it <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">SharePointApp_MultiUser</code>. You will see this name on the screen where you have all the apps listed. So let’s talk about what our app does and how we have tried to achieve this. The app simply displays the titles of elements in both these SharePoint lists in the app itself. So basically what we are trying to do is retrieve the data from these SharePoint lists and display in our app. We will make REST call for this and since it is a SharePoint-hosted app, everything will be client side scripting. No server side code can be used here. The <em style="border: 0px; margin: 0px; padding: 0px;">default.aspx</em> page has been kept simple with an area to display Anne List and Alan list – as shown in the code snippet below:</div>
<div class="pre-action-link" id="premain0" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre0" lang="aspnet" style="border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">asp:Content</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">ContentPlaceHolderID</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">PlaceHolderMain"</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">runat</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">server"</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">div</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">p</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">id</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">countriesDiv"</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;"><!--</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;"> The following content will hold the
countries names when you run the app - see App.js </span>--></span>
Countries from Alan's List
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">p</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">p</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">id</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">currenciesDiv"</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;"><!--</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;"> The following content will hold the
currencies names when you run the app - see App.js </span>--></span>
Currencies from Anne's List
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">p</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">div</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">asp:Content</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span> </pre>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
We have to also include a reference to <em style="border: 0px; margin: 0px; padding: 0px;">App.js</em>. All our client-side code will reside in <em style="border: 0px; margin: 0px; padding: 0px;">App.js</em> file. In the JavaScript file, we have two objects called <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">Countries </code>and <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">Currencies </code>for my lists. The implementation of both the objects is exactly the same, so I’ll explain one of those.</div>
<h4 style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 16px;">
JavaScript Object - Countries</h4>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
The <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">Countries </code>object has two properties:</div>
<ul class="property" style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; list-style-image: url(http://www.codeproject.com/images/symbols/property.GIF); margin: 0px; padding: 0px;"><code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">Element </code>- This is the HTML element on the page where our data will be displayed. It is initialized in the <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">Init</code>method.</li>
<li style="border: 0px; list-style-image: url(http://www.codeproject.com/images/symbols/property.GIF); margin: 0px; padding: 0px;"><code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">url </code>– This is the URL which specifies the data that you are getting from the SharePoint site. So in our case, we want to get the titles of Alan List. Hence we specify the name of the list in the URL and the title also in the query string:</li>
</ul>
<div class="pre-action-link" id="premain1" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre1" lang="cs" style="border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">Countries.url = _spPageContextInfo.webAbsoluteUrl +
"</span>/_api/site/rootweb/lists/getByTitle(<span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">'</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">Alan%20List'</span>)/items?$select=Title<span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">;"</span></pre>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
It has four methods:</div>
<ul class="method" style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; list-style-image: url(http://www.codeproject.com/images/symbols/method.GIF); margin: 0px; padding: 0px;"><code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">Init </code>– Initializes the values of element and URL</li>
<li style="border: 0px; list-style-image: url(http://www.codeproject.com/images/symbols/method.GIF); margin: 0px; padding: 0px;"><code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">Load </code>– Specifies the call to the SharePoint site. This is where the <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">GET </code>method and the headers are specified. It also mentions the success and failure attributes</li>
<li style="border: 0px; list-style-image: url(http://www.codeproject.com/images/symbols/method.GIF); margin: 0px; padding: 0px;"><code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">onSuccess </code>– If the method is successful, the data retrieved is displayed in an HTML table</li>
<li style="border: 0px; list-style-image: url(http://www.codeproject.com/images/symbols/method.GIF); margin: 0px; padding: 0px;"><code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">onError </code>– If the method fails, it displays the message – You do not have permissions to view this list</li>
</ul>
<h4 style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 16px;">
AppManifest.xml</h4>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
The next most important thing that we do before deploying our app is to set the required permissions in the<em style="border: 0px; margin: 0px; padding: 0px;">appManifest.xml</em>. <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">AppManifest </code>is a very important entity with respect to the app model in SharePoint. This is the place where all the information about the app resides. So whenever the app tries to access the parent site or any other resource, it has to be specified in the <em style="border: 0px; margin: 0px; padding: 0px;">appManifest.xml</em>. If the required permissions are not specified in the<code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">appManifest </code>file, your app will not behave in the desired manner and throw an exception. This is actually quite similar to the <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">AppManifest </code>file story in Windows 8 apps or Windows Phone 8 apps for that matter; if you have done any kind of app programming there.</div>
<div class="pre-action-link" id="premain2" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre2" lang="xml" style="border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">AppPrincipal</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">Internal</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">AppPrincipal</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">AppPermissionRequests</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">AppPermissionRequest</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">Scope</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">http://sharepoint/content/sitecollection"</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">Right</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">Write"</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">AppPermissionRequests</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">App</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>"</pre>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
So we are done with our coding and now let’s deploy and test our code. The app is successfully deployed using Visual Studio.</div>
<ol style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">Open Internet Explorer as a different user. Enter the credentials for administrator who is the primary owner of the team site. Enter the URL of the team site Office Services and launch the Multi user app. You get to see both the lists on the screen.</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Open Internet Explorer as a different user. Enter the credentials for Alan Steiner who has permissions on Alan’s list but does not have any permission on Anne’s list. Enter the URL of the team site Office Services and launch the Multi user app. You get to see only the countries which are coming from Alan’s list. You also see an error message which states – “You do not have permissions to view this list”. This second error message is for Anne’s list.</li>
<li style="border: 0px; margin: 0px; padding: 0px;">Open Internet Explorer as a different user. Enter the credentials for Anne Wallace who has permissions on Anne list but has no permission on Alan list. Enter the URL of the team site Office Services and launch the multi user app. You get to see only the currencies which are coming from Anne list. You also see an error message which states – “You do not have permissions to view this list”. This error message is for Alan list.</li>
</ol>
<div>
<span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<span style="color: #111111; font-family: Segoe UI, Arial, sans-serif;"><span style="font-size: 14px;">Download a demo code <a href="https://www.opendrive.com/files?OF85MTI2Nzc5X3YxdGVL">here</a></span></span></div>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-27946320353062492852013-05-08T06:38:00.002-07:002013-05-08T06:38:45.088-07:00Authentication for Web Services (using SOAP headers)<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">I recently put up a few web services for a client of mine, which returned some sensitive data. I needed to find a simple way to authenticate the users of these web services. This is the approach I took.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoXQVkfHGKC0Pe06yZV-8vAQIE0M_EK-iD_XTp3dHM4CvFqdOhBifmw0xL7VyjTr7HPlVsZZlYqQr4foSMyCK5aSP9rGXjM1w550en-nqF6dVJVvXgS8Q1NVRb_ne5xgQPuVLWwp6CWRQ/s1600/AuthForWebServices%5B1%5D.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="219" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoXQVkfHGKC0Pe06yZV-8vAQIE0M_EK-iD_XTp3dHM4CvFqdOhBifmw0xL7VyjTr7HPlVsZZlYqQr4foSMyCK5aSP9rGXjM1w550en-nqF6dVJVvXgS8Q1NVRb_ne5xgQPuVLWwp6CWRQ/s320/AuthForWebServices%5B1%5D.gif" width="320" /></a></div>
<br />
<div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
I've started using web services fairly often in the applications that I've been developing, in most cases the information they pass is suitable for the public domain. However a recent project forced me to look into different authentication methods.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
My requirements were that, it had to be simple for the client applications to authenticate, also that the web based administration system had to be used. This prevented me from using the Windows authentication (which is fairly easy to use for the clients of this web service.) By using SOAP headers to pass username and password information, it greatly simplifies any authentication request.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<b>Using the code</b></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
I wanted to make it really easy for the client to understand:<br />
<div>
<pre id="pre0" lang="cs" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">protected</span> System.Web.UI.WebControls.DataGrid dgData;
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">private</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">void</span> Page_Load(<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">object</span> sender, System.EventArgs e)
{
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">//</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">simple client
</span> AuthWebService.WebService webService = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> AuthWebService.WebService();
AuthWebService.AuthHeader authentication = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span>
AuthWebService.AuthHeader();
authentication.Username = <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">test"</span>;
authentication.Password = <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">test"</span>;
webService.AuthHeaderValue = authentication;
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">//</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">Bind the results - do something here
</span> DataSet dsData = webService.SensitiveData();
dgData.DataSource = dsData;
dgData.DataBind();
}</pre>
</div>
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
Basically all the client needs to do is create an authentication object, fill out the username and password, then pass them to the web service object. The web service code is also pretty simple, the .NET framework lets you create custom SOAP headers by deriving from the <code lang="cs" style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">SoapHeader</code> class, so we wanted to add a username and password:<br />
<div class="pre-action-link" id="premain1" style="border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre1" lang="cs" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">using</span> System.Web.Services.Protocols;
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">public</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">class</span> AuthHeader : SoapHeader
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">public</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">string</span> Username;
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">public</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">string</span> Password;
}</pre>
The next step is to identify the web services that need the authentication, in the example I've included it's the method<code lang="cs" style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">SensitiveData</code>. To force the use of our new SOAP header we need to add the following attribute to our method:<br />
<div class="pre-action-link" id="premain2" style="border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre2" lang="cs" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">[SoapHeader (<span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">Authentication"</span>, Required=true)]</pre>
So our full definition for our web service method is:<br />
<div class="pre-action-link" id="premain3" style="border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre3" lang="cs" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">public</span> AuthHeader Authentication;
[SoapHeader (<span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">Authentication"</span>, Required=true)]
[WebMethod (Description=<span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">Returns some sample data"</span>)]
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">public</span> DataSet SensitiveData()
{
DataSet data = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> DataSet();
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">//</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">Do our authentication
</span> <span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">//</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">this can be via a database or whatever
</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">if</span>(Authentication.Username == <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">test"</span> &&
Authentication.Password == <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">test"</span>)
{
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">//</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">they are allowed access to our sensitive data
</span>
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">//</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">just create some dummy data
</span> DataTable dtTable1 = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> DataTable();
DataColumn drCol1 = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> DataColumn(<span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">Data"</span>,
System.Type.GetType(<span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">System.String"</span>));
dtTable1.Columns.Add(drCol1);
DataRow drRow = dtTable1.NewRow();
drRow[<span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">Data"</span>] = <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">Sensitive Data"</span>;
dtTable1.Rows.Add(drRow);
dtTable1.AcceptChanges();
data.Tables.Add(dtTable1);
}<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">else</span>{
data = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">null</span>;
}
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">return</span> data;
}</pre>
I should also mention that when I say SOAP headers, I actually mean the <code lang="xml" style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">soap:Header</code> element in a SOAP request, it has nothing to do with the HTTP headers sent with the request. The SOAP request looks something like:<br />
<div class="pre-action-link" id="premain4" style="border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre4" lang="xml" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-SummaryComment" style="border: 0px; color: grey; margin: 0px; padding: 0px;"><?</span><span class="code-SummaryComment" style="border: 0px; color: grey; margin: 0px; padding: 0px;">xml</span> <span class="code-SummaryComment" style="border: 0px; color: grey; margin: 0px; padding: 0px;">version</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">1.0"</span> <span class="code-SummaryComment" style="border: 0px; color: grey; margin: 0px; padding: 0px;">encoding</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">utf-8"</span><span class="code-SummaryComment" style="border: 0px; color: grey; margin: 0px; padding: 0px;">?</span><span class="code-SummaryComment" style="border: 0px; color: grey; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">soap:Envelope</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">xmlns:soap</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">http://schemas.xmlsoap.org/soap/envelope/"</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">soap:Header</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">AUTHHEADER</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">xmlns</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">http://tempuri.org/"</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">USERNAME</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>string<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">USERNAME</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">PASSWORD</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>string<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">PASSWORD</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">AUTHHEADER</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">soap:Header</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">soap:Body</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">SENSITIVEDATA</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">xmlns</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">http://tempuri.org/"</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">soap:Body</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">soap:Envelope</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span></pre>
I've included both the client and the web service in the attachment.<br />
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Download a sample <a href="https://www.opendrive.com/files?OF85MTI2NzEyX3pORjBO">here</a></div>
</div>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-63696977560988858202013-05-04T22:37:00.000-07:002013-05-04T22:37:18.158-07:00Windows Powershell Interview questions SharePoint 2010<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">
<span style="font-weight: bold;">Q. What is Windows Powershell ?</span><br /><br /><span style="font-weight: bold;">Ans.</span> Windows PowerShell is a new Windows command-line shell designed especially for system administrators. In the SharePoint administration context, Windows PowerShell is another administration <leo_highlight id="leoHighlights_Underline_0" leohighlights_keywords="tool" leohighlights_underline="true" leohighlights_url_bottom="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsBottom.jsp?keywords%3Dtool%26domain%3Dwww.blogger.com" leohighlights_url_top="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsTop.jsp?keywords%3Dtool%26domain%3Dwww.blogger.com" style="background-attachment: scroll; background-color: transparent; background-image: none; background-position: 0% 50%; background-repeat: repeat repeat; border-bottom-color: rgb(255, 255, 150); border-bottom-style: solid; border-bottom-width: 2px; cursor: pointer; display: inline;">tool</leo_highlight> that supersedes the existing Stsadm.exe.<br /><br /><br /><span style="font-weight: bold;">Q. How is Windows Powershell different from Stsadm ?</span><br /><br /><span style="font-weight: bold;">Ans. </span>Unlike stsadm, which accept and return text, Windows PowerShell is built on the<leo_highlight id="leoHighlights_Underline_1" leohighlights_keywords="microsoft" leohighlights_underline="true" leohighlights_url_bottom="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsBottom.jsp?keywords%3Dmicrosoft%26domain%3Dwww.blogger.com" leohighlights_url_top="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsTop.jsp?keywords%3Dmicrosoft%26domain%3Dwww.blogger.com" style="background-attachment: scroll; background-color: transparent; background-image: none; background-position: 0% 50%; background-repeat: repeat repeat; border-bottom-color: rgb(255, 255, 150); border-bottom-style: solid; border-bottom-width: 2px; cursor: pointer; display: inline;">Microsoft</leo_highlight> .NET Framework and accepts and returns .NET Framework objects. In addition to that it also gives you access to the file system on the computer so that you can access registry,digital signature certificate etc..<br /><br /><span style="font-weight: bold;">Q. What are cmdlet's?</span><br /><br /><span style="font-weight: bold;">Ans.</span> Windows PowerShell introduces the concept of a cmdlet which are simple build in commands, written in a .net language like C# or VB.<br /><br /><span style="font-weight: bold;">Q. Can you Create PowerShell scripts for deploying components in SharePoint ?</span><br /><br /><span style="font-weight: bold;">Ans.</span> If you are creating a webpart with VS 2010 then you can deploy it using ctrl + f5. However, to activate the webpart feature you can write a powershell script (.ps1) and execute it after dpeloyment.<br /><br /><br /><span style="font-weight: bold;">Q. Where is Powershell located in sharePoint ?</span><br /><br /><span style="font-weight: bold;">Ans.</span> On the Start menu, click All Programs -> Click <leo_highlight id="leoHighlights_Underline_2" leohighlights_keywords="microsoft" leohighlights_underline="true" leohighlights_url_bottom="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsBottom.jsp?keywords%3Dmicrosoft%26domain%3Dwww.blogger.com" leohighlights_url_top="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsTop.jsp?keywords%3Dmicrosoft%26domain%3Dwww.blogger.com" style="background-attachment: scroll; background-color: transparent; background-image: none; background-position: 0% 50%; background-repeat: repeat repeat; border-bottom-color: rgb(255, 255, 150); border-bottom-style: solid; border-bottom-width: 2px; cursor: pointer; display: inline;">Microsoft</leo_highlight> SharePoint 2010 Products -> Click SharePoint 2010 Management Shell.<br /><br /><br /><span style="font-weight: bold;">Q. If you need going to install a webpart or any custom solution in SharePoint 2010 using PowerShell What permissions do you need?</span><br /><br /><span style="font-weight: bold;">Ans.</span> In order to use Windows PowerShell for SharePoint 2010 Products, a user must be a member of the SharePoint_Shell_Access role on the configuration and content database. In addition to this, the user must also be a member of the WSS_ADMIN_WPG local group on the computer where SharePoint 2010 Products is installed. See Details<br /><a href="http://asheeriyam.blogspot.in/2013/05/permissions-for-windows-powershell.html" style="color: #861b8f; outline: none; text-decoration: none;">Permissions for Windows PowerShell - SPShellAdmin</a><br /><br /><br /><span style="font-weight: bold;">Q. How to list all the commands in PowerShell ?</span><br /><br /><span style="font-weight: bold;">Ans.</span> <span style="font-weight: bold;">Get-Command * </span>commands gets you all the Powershell commands. For more commands see <a href="http://asheeriyam.blogspot.in/2013/05/sharepoint-windows-powershell-commands.html">Here</a></div>
<div>
<br /></div>
<div id="refHTML" style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">
</div>
<span id="leoHighlights_iframe_modal_span_container" style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;"></span></div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com1tag:blogger.com,1999:blog-8836753959938896287.post-87167703889105763002013-05-04T22:16:00.000-07:002013-05-04T22:16:13.169-07:00SharePoint Windows PowerShell Commands<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">
<span style="font-weight: bold;">To Open the Windows PowerShell Session :</span><br /><br />1. On the Start menu, click All Programs.<br /><br />2. Click <leo_highlight id="leoHighlights_Underline_0" leohighlights_keywords="microsoft" leohighlights_underline="true" leohighlights_url_bottom="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsBottom.jsp?keywords%3Dmicrosoft%26domain%3Dwww.blogger.com" leohighlights_url_top="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsTop.jsp?keywords%3Dmicrosoft%26domain%3Dwww.blogger.com" style="background-attachment: scroll; background-color: transparent; background-image: none; background-position: 0% 50%; background-repeat: repeat repeat; border-bottom-color: rgb(255, 255, 150); border-bottom-style: solid; border-bottom-width: 2px; cursor: pointer; display: inline;">Microsoft</leo_highlight> SharePoint 2010 Products.<br /><br />3. Click SharePoint 2010 Management Shell<br /><br />Note : You should have SharePoint_Shell_Access role on the configuration database and you should be a member of the WSS_ADMIN_WPG local group on the computer where SharePoint Server 2010 is installed.<br /><br /><br /><span style="font-weight: bold;">Some of the Common Commands and Operations are: </span><br /><br /><br /><span style="font-weight: bold;">Create Web Application Variable </span><br /><br />$webapp = Get-SPWebApplication "http://WebapplicationUrl"<br /><br /><br /><span style="font-weight: bold;">Create SharePoint Site Variable (Instance of SPSite)</span><br /><br />$siteurl = "http://MySharePointSite"<br /><br />$Oursite=new-object <leo_highlight id="leoHighlights_Underline_1" leohighlights_keywords="microsoft" leohighlights_underline="true" leohighlights_url_bottom="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsBottom.jsp?keywords%3Dmicrosoft%26domain%3Dwww.blogger.com" leohighlights_url_top="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsTop.jsp?keywords%3Dmicrosoft%26domain%3Dwww.blogger.com" style="background-attachment: scroll; background-color: transparent; background-image: none; background-position: 0% 50%; background-repeat: repeat repeat; border-bottom-color: rgb(255, 255, 150); border-bottom-style: solid; border-bottom-width: 2px; cursor: pointer; display: inline;">Microsoft</leo_highlight>.SharePoint.SPSite($siteurl)<br /><br />Here we have created a variable Oursite, which contains an instance of type SPSite. Now you can use it to display all webs in the site collection.<br /><br />$Oursite.AllWebs more // List all Webs in the Site<br /><br /><br /><span style="font-weight: bold;">Create Service Application Variable</span><br /><br />$spapp = Get-SPServiceApplication -Name "ServiceApplicationDisplayName"<br /><br /><br /><span style="font-weight: bold;">Create a Webapplication: </span><br /><br />New -SPWebApplication -ApplicationPoolName <span style="color: #009900;"><Name of the application pool></span> -Name<span style="color: #009900;"><Name of the new Web application></span> [ -Port <span style="color: #009900;"><Port on which the Web application can be accessed></span>] [-HostHeader <span style="color: #009900;"><Valid URL assigned to the Web application that must correlate to the alternate access mapping configuration></span>] [-URL<span style="color: #009900;"> <Load-balanced URL for the Web application></span>][ -ApplicationPoolAccount <span style="color: #009900;"><User account that this application pool will run as></span>]<br /><br /><span style="font-weight: bold;">Delete WebApplication </span><br /><br /><span id="ctl00_MTCS_main_ctl04"></span></div>
<pre class="libCScode" id="ctl00_MTCS_main_ctl04_code" space="preserve" style="background-color: white; font-size: 11px; line-height: 17px; text-align: justify;">
Remove-SPWebApplication –identity -URL <span style="color: #009900;"><http://sitename></span> -Confirm</pre>
<br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; line-height: 17px; text-align: justify;"><br />Create\Delete a Site Collection: </span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Create a Site collection:</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Get-SPWebTemplate</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">$template = Get-SPWebTemplate "STS#0"</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">New-SPSite –Url "<URL for the new site collection>" –OwnerAlias "<domain\user>" –Template $template</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Here $template is a Variable to store the type of template we want to use while creating a site collection.</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Delete a Site Collection:</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Remove-SPSite –Identity <URL> –GradualDelete</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Here <URL > is a site Collection Url .</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; line-height: 17px; text-align: justify;">Back\Restore a content database</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; line-height: 17px; text-align: justify;">To Backup : </span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Backup -SPFarm -Directory <Backup folder> -BackupMethod -Item <Content database name> [-Verbose]</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Backup folder - is a folder to save your backup.</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">BackupMethod – Can Specify between Full or Differential.</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; line-height: 17px; text-align: justify;">To Restore: </span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Restore -SPFarm -Directory <Backup folder> -RestoreMethod Overwrite -Item <Content database name> [-BackupId] [-Verbose]</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">If you don’t know the BackupID you can display all the backups using the below command and get the GUID of the Backup.</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Get-SPBackupHistory -Directory <Backup folder></span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">You can check all the Backup-Restore Operations Here</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; line-height: 17px; text-align: justify;">Deploy WebPart Soluiton Package</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Install -SPWebPartPack -LiteralPath "PathToCABorwspFile" -Name "NameOFWebPart"</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">PathToCABorwspFile- is the full path to the CAB file that is being deployed.</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">NameOFWebPart- is the name of the Web Part that is being deployed.</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><strong style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;"></strong><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><strong style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;"><br />Install Activate and Deactivate Feature using Windows Powershell </strong><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; color: #009900; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Install Feature :</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">$MyFeatureId = $(Get -SPFeature -limit all where {$_.displayname -eq "myfeatureName"}).Id</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Install -SPFeature $MyFeatureId</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; color: #009900; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Activate\Enable Feature :</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">$singleSiteCollection = Get -SPSite -Identity http://MySingleSiteCollectionURL</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Enable -SPFeature $MyFeatureId -Url $singleSiteCollection.URL</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; color: #009900; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Deactivate\Disable Feature :</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">$singleSiteCollection = Get-SPSite -Identity http://MySingleSiteCollectionURL</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Disable -SPFeature $MyFeatureId -Url $singleSiteCollection.URL</span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; line-height: 17px; text-align: justify;"><br />Command TO List all the PowerShell Commands </span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /><div id="refHTML" style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">
</div>
<span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Get-Command –PSSnapin “</span><leo_highlight id="leoHighlights_Underline_0" leohighlights_keywords="microsoft" leohighlights_underline="true" leohighlights_url_bottom="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsBottom.jsp?keywords%3Dmicrosoft%26domain%3Dwww.blogger.com" leohighlights_url_top="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsTop.jsp?keywords%3Dmicrosoft%26domain%3Dwww.blogger.com" style="background-attachment: scroll; background-image: none; background-position: 0% 50%; background-repeat: repeat repeat; border-bottom-color: rgb(255, 255, 150); border-bottom-style: solid; border-bottom-width: 2px; cursor: pointer; display: inline; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Get-Comma</leo_highlight><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">nd –PSSnapin “</span><leo_highlight id="leoHighlights_Underline_0" leohighlights_keywords="microsoft" leohighlights_underline="true" leohighlights_url_bottom="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsBottom.jsp?keywords%3Dmicrosoft%26domain%3Dwww.blogger.com" leohighlights_url_top="http%3A//shortcuts.thebrowserhighlighter.com/leonardo/plugin/highlights/3_1/tbh_highlightsTop.jsp?keywords%3Dmicrosoft%26domain%3Dwww.blogger.com" style="background-attachment: scroll; background-image: none; background-position: 0% 50%; background-repeat: repeat repeat; border-bottom-color: rgb(255, 255, 150); border-bottom-style: solid; border-bottom-width: 2px; cursor: pointer; display: inline; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Microsoft</leo_highlight><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">.SharePoint.PowerShell” format-table name > C:\SP2010_PowerShell_Commands.txt</span><span id="leoHighlights_iframe_modal_span_container" style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;"> </span><br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" /></div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-65645133779945487382013-05-04T22:14:00.002-07:002013-05-04T22:14:57.496-07:00Permissions for Windows PowerShell - SPShellAdmin<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">In order to use Windows PowerShell for SharePoint 2010 Products, a user must be a member of the </span><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; line-height: 17px; text-align: justify;">SharePoint_Shell_Access</span><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;"> role on the configuration and content database. In addition to this, the user must also be a member of the </span><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; line-height: 17px; text-align: justify;">WSS_ADMIN_WPG</span><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">local group on the computer where SharePoint 2010 Products is installed.</span><br />
<br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" />
<span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">To add a user as SharePoint_Shell_Access on the SharePoint database use the below powershell cmdlet :</span><br />
<br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" />
<span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Add-SPShellAdmin</span><br />
<br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" />
<span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Please Note that to run the above cmdlet you must have</span><br />
<span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">* Membership in the </span><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; line-height: 17px; text-align: justify;">securityadmin </span><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">fixed server role on the SQL Server instance</span><br />
<span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">* Membership in the </span><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; line-height: 17px; text-align: justify;">db_owner</span><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;"> fixed database role on all affected databases</span><br />
<span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">* and local administrative permission on the local computer.</span><br />
<br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" />
<span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">In addition to above some important things to Note:</span><br />
<br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" />
<span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">* The user gets added to the </span><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; line-height: 17px; text-align: justify;">WSS_Admin_WPG</span><span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;"> group on all Web servers when the user is added to the SharePoint_Shell_Access role.</span><br />
<br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" />
<span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">* If the target database does not have a SharePoint_Shell_Access role, the role is automatically created.</span><br />
<br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" />
<span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">* If you use the database parameter, the user is added to the role on the farm configuration database, the Central Administration content database, and the specified database. Using the database parameter is the preferred method because most of the administrative operations require access to the Central Administration content database. The cmdlet is something like below :</span><br />
<br style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;" />
<span style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 17px; text-align: justify;">Add-SPShellAdmin -UserName Domainname\User -database {Database GUID}</span></div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-15866348824270167562013-05-04T21:58:00.003-07:002013-05-04T21:58:26.956-07:00PowerShell interview questions and Literacy<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="font-family: georgia, serif; font-size: 20px; margin: 10px 10px 20px;">
<h1 style="color: #f85931; font-size: 48px; margin: 10px;">
PowerShell Literacy</h1>
<div style="margin: 10px 10px 20px;">
<strong style="color: #ce1836;">What is PowerShell Literacy?</strong> PowerShell Literacy centers on being PowerShell "literate" - that is, being able to read, understand, and grok PowerShell. PowerShell literacy isn't just being able to read PowerShell, but being able to <strong style="color: #ce1836;">think</strong> in PowerShell.</div>
<div style="margin: 10px 10px 20px;">
</div>
<div style="margin: 10px 10px 20px;">
Many of us come to PowerShell from <strong style="color: #ce1836;">VBScript</strong>. Others from <strong style="color: #ce1836;">unix</strong> shell scripting. Others have been all <strong style="color: #ce1836;">GUI</strong> with a dash of batch files. PowerShell inherits much from these various predecessors, but PowerShell written from these perspectives often<strong style="color: #ce1836;">leads to solutions that even a mother couldn't love</strong> - so we're going to start off at the <strong style="color: #ce1836;">basement level</strong>.</div>
<div style="margin: 10px 10px 20px;">
<strong style="color: #ce1836;">Why read this?</strong> It's true that there are many PowerShell books out there, in print and online, and many of them are great. This one focuses on making you self-sufficient at PowerShell. If you're a <strong style="color: #ce1836;">doer</strong>, you will go far with this book as it will give you the few tools you need to get moving. If you need all the details, or if you need tons of script examples, then this probably <strong style="color: #ce1836;">isn't</strong> the book for you.</div>
<div style="margin: 10px 10px 20px;">
This quick tutorial will build up a beginner's PowerShell knowledge from the<strong style="color: #ce1836;">basement level</strong>. I hope that this text can teach a beginner not just syntax, and not just code examples for how to do cool stuff, but actually to teach an understanding of PowerShell... An understanding of how the language works, and also how it can be used to do work for you.</div>
<div style="margin: 10px 10px 20px;">
</div>
<div class="script-title" style="color: #f85931; font-family: 'Courier New', Courier, monospace; font-size: 22px; font-weight: bold; margin-bottom: 13px; margin-top: 45px;">
C:\Users\Daniel> powershell<br />
PS C:\Users\Daniel ></div>
<div class="word-title" style="color: #f85931; font-size: 22px; font-weight: bold; margin-bottom: 22px;">
1. Enter: PowerShell</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
To start PowerShell, simply open a normal command prompt and run the command <span class="code" style="font-family: 'Courier New', Courier, monospace;">powershell</span>. Alternatively, run <span class="code" style="font-family: 'Courier New', Courier, monospace;">powershell</span> in the Run prompt (or within Windows 7's text input in the Start Menu).</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
In short, PowerShell is Microsoft's new shell and scripting language for use in managing Windows. It combines some of the best lessons learned from decades of UNIX administering, and deep integration with the Windows environment. Since it's built on Windows, its design and functionality directly addresses the challenges and benefits of working within Microsoft's operating systems.</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
Get used to the above prompt. It's the "interactive" shell way of working with PowerShell. We're going to spend the majority of this text beating this prompt into submission.</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
<div class="script-title" style="color: #f85931; font-family: 'Courier New', Courier, monospace; font-size: 22px; font-weight: bold; margin-bottom: 13px; margin-top: 45px;">
PS > "Oi, mundo!"<br />
Oi, mundo!</div>
<div class="word-title" style="color: #f85931; font-size: 22px; font-weight: bold; margin-bottom: 22px;">
2. Exchanging pleasantries</div>
<div class="word-para" style="margin-bottom: 15px;">
Above is a simple "Hello World" in PowerShell.</div>
<div class="word-para" style="margin-bottom: 15px;">
If you type a string literal (a string in quotes) into PowerShell, it will interpret it as a string. Note that both double-quotes (" ") and single-quotes (' ') are accepted in PowerShell (but they have slightly different functionality - more on that later!).</div>
<div class="word-para" style="margin-bottom: 15px;">
Similarly for numbers:</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; margin-bottom: 15px;">
PS > 4<br />
4<br />
PS > 1+1<br />
2<br />
PS > 3/2<br />
1.5</div>
<div class="word-para" style="margin-bottom: 15px;">
Note that when you divided two integers, PowerShell smartly converted the result into a floating point number. This is called "widening" the type, and is expected and welcomed in a shell environment - but may be a shock to traditional developers.</div>
<div class="word-para" style="margin-bottom: 15px;">
Shell veterans, both from Windows and UNIX, should feel right at home in PowerShell - commands such as<span class="code" style="font-family: 'Courier New', Courier, monospace;">dir</span>, <span class="code" style="font-family: 'Courier New', Courier, monospace;">cd</span>, and <span class="code" style="font-family: 'Courier New', Courier, monospace;">ls</span> all work in PowerShell out-of-the-box.</div>
<div class="word-para" style="margin-bottom: 15px;">
<div class="script-title" style="color: #f85931; font-family: 'Courier New', Courier, monospace; font-size: 22px; font-weight: bold; margin-bottom: 13px; margin-top: 45px;">
PS > "this is no ordinary string - it's an object!".ToUpper()<br />
THIS IS NO ORDINARY STRING - IT'S AN OBJECT!</div>
<div class="word-title" style="color: #f85931; font-size: 22px; font-weight: bold; margin-bottom: 22px;">
3. Ditch the string, embrace the object.</div>
<div class="word-para" style="margin-bottom: 15px;">
The shell in PowerShell is object-based, rather than text-based. In a UNIX shell and in cmd.exe (Windows's native command-line program), when you run a command - you get a resultant string. When you run a command in PowerShell, you actually get a .NET object. But what does that distinction really mean?</div>
<div class="word-para" style="margin-bottom: 15px;">
Let's look at the above command again. We've created a string - everything within the quotes. But actually, we created a <strong style="color: #ce1836;">string</strong> object - a bunch of information in the computer which represents the <strong style="color: #ce1836;">idea</strong> of a string - rather than just a bunch of adjacent characters.</div>
<div class="word-para" style="margin-bottom: 15px;">
So after we create that string object, we use syntax similar to C# to run the <span class="code" style="font-family: 'Courier New', Courier, monospace;">ToUpper()</span> method of the string. Like other OO programming language objects, objects in PowerShell have properties (values) and methods (procedures that do stuff). We're running the <span class="code" style="font-family: 'Courier New', Courier, monospace;">ToUpper()</span> method, which outputs an uppercase version of the string. Note that running this method didn't actually change anything about the object or the string it represents.</div>
<div class="word-para" style="margin-bottom: 15px;">
The text that you see on your screen is a formatted text representation of the object, rather than the object itself.</div>
<div class="word-para" style="margin-bottom: 15px;">
Objects. Not text. This is a big deal. For real. "Why?" Read on...</div>
</div>
<div class="word-para" style="margin-bottom: 15px;">
<div class="script-title" style="color: #f85931; font-family: 'Courier New', Courier, monospace; font-size: 22px; font-weight: bold; margin-bottom: 13px; margin-top: 45px;">
PS > ps<br />
PS > (get-process)[0].processname<br />
ACEngSvr</div>
<div class="word-title" style="color: #f85931; font-size: 22px; font-weight: bold; margin-bottom: 22px;">
4. Objects - shell works for you, you don't work for the shell</div>
<div class="word-para" style="margin-bottom: 15px;">
For UNIX admins, <span class="code" style="font-family: 'Courier New', Courier, monospace;">ps</span> is all-too-familiar. This command will return a bunch of useful info on all of the running processes on the computer. PowerShell has its own version of <span class="code" style="font-family: 'Courier New', Courier, monospace;">ps</span>. If you run <span class="code" style="font-family: 'Courier New', Courier, monospace;">ps</span>, you should see an output that is quite similar to what UNIX offers. But then take a look at the second statement. Note that <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-process</span> is the formal name for <span class="code" style="font-family: 'Courier New', Courier, monospace;">ps</span> in PowerShell. Don't worry too much about the syntax for now - basically what we are doing with <span class="code" style="font-family: 'Courier New', Courier, monospace;">[0]</span> is asking for just the first process in the returned list.</div>
<div class="word-para" style="margin-bottom: 15px;">
The important bit is the <span class="code" style="font-family: 'Courier New', Courier, monospace;">.processname</span>. In UNIX, if we wanted to get the name of a process, we would need to use some kind of regular expression to extract it out of the text blob returned by the shell. In PowerShell, however, we can simply ask for it. Using the dot operator ( <span class="code" style="font-family: 'Courier New', Courier, monospace;">.</span> ), we can attack properties directly without any hacky work.</div>
<div class="word-para" style="margin-bottom: 15px;">
So, objects will let us access member properties of our outputs much easier. It also lets us access their member methods (the do-stuff pieces). This lets us interact with our output without thinking too hard - we can save that brain power for solving problems.</div>
<div class="word-para" style="margin-bottom: 15px;">
On top of all that, these objects are special even among objects. These objects are derived from the .NET Framework's objects. To non-Windows-developers, this won't mean much. We'll see later on, however, why this makes PowerShell much more powerful than if it had just implemented its own custom objects.</div>
<div class="word-para" style="margin-bottom: 15px;">
<div class="script-title" style="color: #f85931; font-family: 'Courier New', Courier, monospace; font-size: 22px; font-weight: bold; margin-bottom: 13px; margin-top: 45px;">
PS > get-location<br />
PS > get-childitem -path c:\<br />
PS > get-service</div>
<div class="word-title" style="color: #f85931; font-size: 22px; font-weight: bold; margin-bottom: 22px;">
5. cmdlets - native PowerShell commands pack a punch</div>
<div class="word-para" style="margin-bottom: 15px;">
So far, we've seen how PowerShell handles numbers and strings, and how it can understand typical shell commands. But PowerShell wouldn't be its own beast without it having its own, native commands.</div>
<div class="word-para" style="margin-bottom: 15px;">
These native PowerShell commands are called cmdlets (pronounced command-lets). For the geeks wondering, cmdlets are compiled .NET code, which makes them optimized and very fast.</div>
<div class="word-para" style="margin-bottom: 15px;">
Cmdlets look and operate like command-line utilities in other shells. As such, the syntax is similar. Cmdlets can take in named parameters (like the "<span class="code" style="font-family: 'Courier New', Courier, monospace;">-newest 5</span>" below), or positional parameters (which are interpreted based on position and don't require being named, such as "<span class="code" style="font-family: 'Courier New', Courier, monospace;">Application</span>" below).</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; margin-bottom: 15px;">
PS > get-eventlog Application -newest 5</div>
<div class="word-para" style="margin-bottom: 15px;">
The inputs for cmdlets don't have to be primitives such as strings or numbers (like the above example), and instead take objects as inputs. Likewise, they output objects. We saw this in the case of <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-process</span>, and the same is true for all of the above cmdlets as well.</div>
<div class="word-para" style="margin-bottom: 15px;">
One neat design choice in PowerShell cmdlets is the standardized naming convention. All cmdlets have a "verb-noun" format. The noun is a thing, and the verb is what is being done to the thing. <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-process</span> is a cmdlet that gets (and outputs) processes, while <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-eventlog</span> gets items from the Event Log. This makes it super-easy to read and immediately understand cmdlets, even if it's the first time you come across them. Neat, huh?</div>
</div>
<div class="word-para" style="margin-bottom: 15px;">
<div class="section" style="font-size: medium; margin: 15px;">
<div class="script-title" style="color: #f85931; font-family: 'Courier New', Courier, monospace; font-size: 22px; font-weight: bold; margin-bottom: 13px; margin-top: 45px;">
PS > get-help get-process</div>
<div class="word-title" style="color: #f85931; font-size: 22px; font-weight: bold; margin-bottom: 22px;">
6. We all need help sometimes. For those times, make get-help your friend.</div>
<div class="word-para" style="margin-bottom: 15px;">
If you're hoping to be self-sufficient in PowerShell, this is the most important page in the book. <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-help</span> is the most useful cmdlet in PowerShell, and you just need to accept this as gospel.</div>
<div class="word-para" style="margin-bottom: 15px;">
<span class="code" style="font-family: 'Courier New', Courier, monospace;">get-help</span> fills the same role that "<span class="code" style="font-family: 'Courier New', Courier, monospace;">man</span>" pages do in UNIX. <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-help</span> gives a brief description of a cmdlet, allowing you to quickly learn new cmdlets from within PowerShell, rather than jumping out to a book or online reference.</div>
<div class="word-para" style="margin-bottom: 15px;">
"Brief", you say? Unimpressed? Ok then, try this on for size:</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; margin-bottom: 15px;">
PS > get-help get-process -detailed</div>
<div class="word-para" style="margin-bottom: 15px;">
Boom. Description plus sample uses. This is the most important lesson I can give you. Try <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-help</span> on some of the other cmdlets we've used so far. Or, if you're feeling adventuresome, use it to check out some of the other available cmdlets:</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; margin-bottom: 15px;">
PS > get-help get*<br />
PS > get-help *item*<br />
PS > get-help *</div>
<div>
<div class="script-title" style="color: #f85931; font-family: 'Courier New', Courier, monospace; font-size: 22px; font-weight: bold; margin-bottom: 13px; margin-top: 45px;">
PS > "this is not a string, it's a string object" | get-member</div>
<div class="word-title" style="color: #f85931; font-size: 22px; font-weight: bold; margin-bottom: 22px;">
7. get-member, or: second-most-important is still really important</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
Remember how I used the <span class="code" style="font-family: 'Courier New', Courier, monospace;">ToUpper()</span> method on a string in a previous example? Ever wonder how I knew about that method? Wonder no more. Let me introduce you to <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-member</span>.</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
<span class="code" style="font-family: 'Courier New', Courier, monospace;">get-member</span> is nearly as important as <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-help</span>. Where <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-help</span> gave you assistance on unfamiliar cmdlets, <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-member</span> will give you information on unfamiliar objects. <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-member</span> will tell you the name of the object type (in above case, <span class="code" style="font-family: 'Courier New', Courier, monospace;">System.String</span>) as well as all of the methods and properties of the object. You can then pummel the object with the dot operator and cool methods.</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; font-size: 16px; margin-bottom: 15px;">
PS > get-location | get-member<br />
PS > (get-location).drive<br />
PS > (get-location).path<br />
PS > (get-location).provider</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
Note: Another cool command for learning about PowerShell is <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-command</span>. Why not use <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-help</span> to find out how to use <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-command</span>?</div>
</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
<div class="section" style="font-size: medium; margin: 15px;">
<div class="script-title" style="color: #f85931; font-family: 'Courier New', Courier, monospace; font-size: 22px; font-weight: bold; margin-bottom: 13px; margin-top: 45px;">
PS > "wait a second... what's that bar over there? " | get-member</div>
<div class="word-title" style="color: #f85931; font-size: 22px; font-weight: bold; margin-bottom: 22px;">
8. The internet is a series of tubes, and so is PowerShell</div>
<div class="word-para" style="margin-bottom: 15px;">
Observant readers were probably asking what the hell syntax I used in the previous example with <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-member</span>. Non-observant readers, take note: I used weird syntax.</div>
<div class="word-para" style="margin-bottom: 15px;">
Thus is the first documented usage of the pipe operator and the pipeline in PowerShell. UNIX admins, don't sleep through this section, as PowerShell's pipeline works in a fundamentally different way than UNIX's pipeline construct.</div>
<div class="word-para" style="margin-bottom: 15px;">
For those unfamiliar with the idea of a pipeline, it's a compact syntax for sending the output of one command as the input of the next. In UNIX, this meant that the string output (which is designed more for humans to read than computers) is forwarded on, while in PowerShell the actual object (which is easily understood by computers) is forwarded. In <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-member</span>'s case, whatever object is to the left of <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-member</span> acts as input to <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-member</span>; <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-member</span> figures out all of the object's interfaces and then outputs that information.</div>
<div class="word-para" style="margin-bottom: 15px;">
This is where PowerShell's object-based nature really starts to change the game. In other command-line environments, advanced queries would require sophisticated (and brittle) text parsing. Now, the object is our best friend.</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; margin-bottom: 15px;">
PS > get-childitem<br />
PS > get-childitem | sort-object Name -descending</div>
<div>
<span style="background-color: transparent; color: #f85931; font-family: 'Courier New', Courier, monospace; font-size: 22px; font-weight: bold;"><br /></span></div>
<div>
<span style="background-color: transparent; color: #f85931; font-family: 'Courier New', Courier, monospace; font-size: 22px; font-weight: bold;">PS > "more pipelining" | get-member | format-list</span></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="section" style="font-size: medium; margin: 15px;">
<div class="word-title" style="color: #f85931; font-size: 22px; font-weight: bold; margin-bottom: 22px;">
9. Anatomy of a pipeline</div>
<div class="word-para" style="margin-bottom: 15px;">
So. The point of the above example is to show a real-world case where we may want to do a multi-level pipeline. First, we create an object that we're interested in. Then, we decide we want to find out more about its members, so we pipe it to <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-member</span>. The problem is, the "Definition" outputted by <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-member</span> is too long to be displayed. So, we pipe the member information into <span class="code" style="font-family: 'Courier New', Courier, monospace;">format-list</span>, which is one of our formatting utilities - not unsurprisingly, this one outputs each part in a list.</div>
<div class="word-para" style="margin-bottom: 15px;">
</div>
<div class="word-para" style="margin-bottom: 15px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjp2JVsURk1LVgEybAev_ncjo3edt_hOxQGBPR1gCw-LxYnL8k0CqWplHFMva8eq7GnzebQ3JtwUDBNM3uOKDljWADd-NfItSGrENvObTdbYZb7CpxFn3kWHvzl1r4p2UNbLtlZDEggNg0/s1600/pipeline%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="220" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjp2JVsURk1LVgEybAev_ncjo3edt_hOxQGBPR1gCw-LxYnL8k0CqWplHFMva8eq7GnzebQ3JtwUDBNM3uOKDljWADd-NfItSGrENvObTdbYZb7CpxFn3kWHvzl1r4p2UNbLtlZDEggNg0/s400/pipeline%5B1%5D.png" width="400" /></a></div>
The above diagram visually represents what's going on in the pipeline. Each step generates objects and forwards them to the right. When we get to the right-most cmdlet, it too forwards its output to the right - but the output hits a brick wall. In the shell, that brick wall is called <span class="code" style="font-family: 'Courier New', Courier, monospace;">out-default</span>. <span class="code" style="font-family: 'Courier New', Courier, monospace;">out-default</span> is a handy cmdlet that runs at the tail of all of the commands we run. It takes whatever is left at the end, interprets it, and displays it to us on the screen.</div>
<div class="word-para" style="margin-bottom: 15px;">
If <span class="code" style="font-family: 'Courier New', Courier, monospace;">out-default</span> didn't exist, all of our hard-earned output would still be stuck in computer-readable objects rather than human-readable representations of those objects. And that wouldn't be too useful, would it?</div>
</div>
<div style="margin: 10px 10px 20px;">
</div>
<div class="script-title" style="color: #f85931; font-family: 'Courier New', Courier, monospace; font-size: 22px; font-weight: bold; margin-bottom: 13px; margin-top: 45px;">
PS > get-process<br />
PS > get-process | measure-object<br />
PS > get-process | select-object -first 10<br />
PS > get-process | sort-object PM -descending</div>
<div class="word-title" style="color: #f85931; font-size: 22px; font-weight: bold; margin-bottom: 22px;">
10. The pipeline and the object are BFFs</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
I've told you (at least) two things so far that you've more or less had to take at face-value: the pipeline is a useful concept, and objects make using the pipeline that much easier. Now it's time to prove that these concepts make PowerShell a breeze to use.</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
Consider the <span class="code" style="font-family: 'Courier New', Courier, monospace;">sort-object</span> command above. In a text-based environment, we would have needed to parse each line to get the "<span class="code" style="font-family: 'Courier New', Courier, monospace;">PM</span>" value, then targeted our sort on that. Now, we just tell <span class="code" style="font-family: 'Courier New', Courier, monospace;">sort-object</span> straight-up: sort on <span class="code" style="font-family: 'Courier New', Courier, monospace;">PM</span>. It's such a common-sense idea that that those who haven't had the pleasure of using <span class="code" style="font-family: 'Courier New', Courier, monospace;">awk</span>probably can't understand why I'm harping on this. If that's you, praise your luck and stick with PowerShell where it's safe.</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
Let's look at some more examples:</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; font-size: 16px; margin-bottom: 15px;">
PS > get-process | format-table ProcessName, PM, CPU -autosize</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
This is simple but powerful. <span class="code" style="font-family: 'Courier New', Courier, monospace;">format-table</span> will format the incoming objects in the pipeline into a table. By providing specific properties as positional parameters, we're telling it that we don't want the standard selection of properties, and instead the ones we selected. The <span class="code" style="font-family: 'Courier New', Courier, monospace;">-autosize</span> switch tells <span class="code" style="font-family: 'Courier New', Courier, monospace;">format-table</span> to read in all of the objects, and then determine the best width for the columns (note that <span class="code" style="font-family: 'Courier New', Courier, monospace;">-autosize</span> means that <span class="code" style="font-family: 'Courier New', Courier, monospace;">format-table</span> can't "stream" - streaming is where a cmdlet deals with each object as it receives it; in this case, <span class="code" style="font-family: 'Courier New', Courier, monospace;">format-table</span> has to wait until it goes through them ALL before it begins its work. With large collections, it means there will be a pause before output will be written to the screen).</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; font-size: 16px; margin-bottom: 15px;">
PS > get-process | where-object { $_.PM -gt 10MB }</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
Now we introduce some new syntax. The { <span class="code" style="font-family: 'Courier New', Courier, monospace;">...</span> } bit is called a scriptblock. Within the curly braces can be any number of PowerShell commands (if they are inline, use the semicolon (<span class="code" style="font-family: 'Courier New', Courier, monospace;">;</span>) to separate them).</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
The <span class="code" style="font-family: 'Courier New', Courier, monospace;">$</span> symbol is the variable symbol in PowerShell. Every variable name must begin with a dollar sign - for example: <span class="code" style="font-family: 'Courier New', Courier, monospace;">$var1</span>, <span class="code" style="font-family: 'Courier New', Courier, monospace;">$var2</span>, <span class="code" style="font-family: 'Courier New', Courier, monospace;">$abcdefg</span> are all valid variable names, but <span class="code" style="font-family: 'Courier New', Courier, monospace;">var3</span> is not. <span class="code" style="font-family: 'Courier New', Courier, monospace;">$_</span> is a special variable. It translates to "whatever object is in the pipeline".</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
With <span class="code" style="font-family: 'Courier New', Courier, monospace;">where-object</span>, we are filtering the incoming objects based on the criteria listed in the scriptblock. In this case, we check the <span class="code" style="font-family: 'Courier New', Courier, monospace;">PM</span> property of each object in the pipeline (<span class="code" style="font-family: 'Courier New', Courier, monospace;">$_.PM</span>) and see if it is greater than 10MB. Note that <span class="code" style="font-family: 'Courier New', Courier, monospace;">10MB</span> is automatically translated by the shell to equate to 10485760 - the <span class="code" style="font-family: 'Courier New', Courier, monospace;">KB</span> and <span class="code" style="font-family: 'Courier New', Courier, monospace;">MB</span> modifiers exist in PowerShell to make administrators' lives easier.</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; font-size: 16px; margin-bottom: 15px;">
PS > get-process | foreach-object { $_.CPU }</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
Another use of the scriptblock. In this case, rather than filtering based on the scriptblock, <span class="code" style="font-family: 'Courier New', Courier, monospace;">foreach-object</span>will execute the scriptblock against EACH object (remember that <span class="code" style="font-family: 'Courier New', Courier, monospace;">$_</span> means "whatever object is in the pipeline right now"). In the above case, the action is simply to output CPU of each object - a pretty lame example. But check out this more advanced version:</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; font-size: 16px; margin-bottom: 15px;">
PS > get-process | foreach-object -begin { $sum=0 } -process { $sum = $sum + $_.CPU } -end { $sum }</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
Neat, huh? The <span class="code" style="font-family: 'Courier New', Courier, monospace;">process</span> scriptblock runs against each object (like the single scriptblock did in the previous example). The <span class="code" style="font-family: 'Courier New', Courier, monospace;">begin</span> scriptblock is ran just one time, BEFORE any objects are processed; <span class="code" style="font-family: 'Courier New', Courier, monospace;">end</span> is ran just one time, AFTER all objects are processed. The above example initializes a variable, <span class="code" style="font-family: 'Courier New', Courier, monospace;">$sum</span>. Then the <span class="code" style="font-family: 'Courier New', Courier, monospace;">CPU</span> of each object is added to <span class="code" style="font-family: 'Courier New', Courier, monospace;">$sum</span>. Then we output the variable <span class="code" style="font-family: 'Courier New', Courier, monospace;">$sum</span>. All in a very compact syntax.</div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
<span style="background-color: transparent; color: #f85931; font-family: 'Courier New', Courier, monospace; font-size: 22px; font-weight: bold;"><br /></span></div>
<div class="word-para" style="font-size: 16px; margin-bottom: 15px;">
<span style="background-color: transparent; color: #f85931; font-family: 'Courier New', Courier, monospace; font-size: 22px; font-weight: bold;">PS > ps | sort PM -descending | select -first 10 | % -begin { $sum=0 } -process { $sum += $_.CPU } -end { $sum } | write-host -foregroundcolor DarkGreen</span></div>
<br />
<div class="section" style="font-size: medium; margin: 15px;">
<div class="word-title" style="color: #f85931; font-size: 22px; font-weight: bold; margin-bottom: 22px;">
11. pipe | pipe | pipe | pipe | pipe</div>
<div class="word-para" style="margin-bottom: 15px;">
Don't panic. Breathe. Let's walk through this slowly.</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; margin-bottom: 15px;">
PS > ps</div>
<div class="word-para" style="margin-bottom: 15px;">
Ok. No big deal. <span class="code" style="font-family: 'Courier New', Courier, monospace;">ps</span> is just an alias for <span class="code" style="font-family: 'Courier New', Courier, monospace;">get-process</span>.</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; margin-bottom: 15px;">
PS > ps | sort PM -descending</div>
<div class="word-para" style="margin-bottom: 15px;">
We're still ok. <span class="code" style="font-family: 'Courier New', Courier, monospace;">sort</span> is an alias for <span class="code" style="font-family: 'Courier New', Courier, monospace;">sort-object</span>. This is the same command we ran in the last example: we're sorting all objects based on the <span class="code" style="font-family: 'Courier New', Courier, monospace;">PM</span> property, and putting them in <span class="code" style="font-family: 'Courier New', Courier, monospace;">descending</span> order.</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; margin-bottom: 15px;">
PS > ps | sort PM -descending | select -first 10</div>
<div class="word-para" style="margin-bottom: 15px;">
Now, we take that sorted list and run <span class="code" style="font-family: 'Courier New', Courier, monospace;">select</span> (alias for <span class="code" style="font-family: 'Courier New', Courier, monospace;">select-object</span>) to grab just the first 10 results. Note that this gives us the top-10 objects based on PM.</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; margin-bottom: 15px;">
PS > ps | sort PM -descending | select -first 10 | % -begin { $sum=0 } -process { $sum += $_.CPU } -end { $sum }</div>
<div class="word-para" style="margin-bottom: 15px;">
Now, using the very-compact <span class="code" style="font-family: 'Courier New', Courier, monospace;">%</span> alias for <span class="code" style="font-family: 'Courier New', Courier, monospace;">foreach-object</span> to accumlate the CPU of the top-10 objects based on PM. This takes the pipeline's many objects and reduces them to a single integer. (<span class="code" style="font-family: 'Courier New', Courier, monospace;">foreach-object</span> gets such a kickin' alias because it's used so often in common tasks; we can all only aspire to be so awesome.)</div>
<div class="code-para" style="background-color: #dedede; border-style: solid; border-width: 1px; font-family: 'Courier New', Courier, monospace; margin-bottom: 15px;">
PS > ps | sort PM -descending | select -first 10 | % -begin { $sum=0 } -process { $sum += $_.CPU } -end { $sum } | write-host -foregroundcolor DarkGreen</div>
<div class="word-para" style="margin-bottom: 15px;">
Finally, for some flair, we send that integer through <span class="code" style="font-family: 'Courier New', Courier, monospace;">write-host</span> (a cmdlet that writes objects to the display) and setting the text color to <span class="code" style="font-family: 'Courier New', Courier, monospace;">DarkGreen</span>. So in total, how would you describe what we did?</div>
<div class="word-para" style="margin-bottom: 15px;">
-> In Dark Green text, we displayed the combined CPU of the 10 processes with the most Physical Memory usage.</div>
<div class="word-para" style="margin-bottom: 15px;">
That complex idea was represented - clearly and concisely - in PowerShell due to the pipeline and its object-based nature.</div>
<div class="word-para" style="margin-bottom: 15px;">
<br /></div>
</div>
<br />
<div style="margin: 10px 10px 20px;">
To be effective with PowerShell, you need to start to actually <strong style="color: #ce1836;">think in PowerShell</strong>. You need to be like The One and look at commands and visualize what's going on. You must, to coin a term, be <strong style="color: #ce1836;">PowerShell Literate</strong>.</div>
<div style="margin: 10px 10px 20px;">
Following this intro are a bunch of PowerShell one-liners. It's your job to <strong style="color: #ce1836;">understand</strong>what each line is doing, and to be able to <strong style="color: #ce1836;">articulate</strong> it in words to yourself or someone else.</div>
<div style="margin: 10px 10px 20px;">
Describe the <strong style="color: #ce1836;">objects</strong> that are created, how they are passed through the <strong style="color: #ce1836;">pipeline</strong>, what kind of object is <strong style="color: #ce1836;">outputted</strong> or what is <strong style="color: #ce1836;">displayed</strong>. Strive to really describe what you see. Start to see the patterns of usage in PowerShell.</div>
<div style="margin: 10px 10px 20px;">
If you see something new or you simply have forgotten what a cmdlet does or how it works, feel free to use <strong style="color: #ce1836;">get-help</strong> to learn more about the cmdlet. This functionality will be available to you in the real world, and there's no penalty for using it here, if reading the help file gives you the key info to describe the command fully.</div>
<div style="margin: 10px 10px 20px;">
Give each example a try, then click on the example to see an explanation.</div>
<div class="section" style="font-size: medium; margin: 15px;">
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">1. PS > get-process | format-wide -auto</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">2. PS > get-acl | get-member</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">3. PS > get-process | where-object { $_.Name -like "svc*" }</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">4. PS > get-childitem env:</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">5. PS > $host</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">6. and 7.<br /><br />PS > get-childitem cert:\localmachine\authroot | format-table subject, notafter</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">8. PS > get-command -commandtype alias | format-wide -auto</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">9. PS > (get-date "8/2").tostring("MM/dd/yy")</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">10. PS > dir Registry::HKEY_USERS</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">11. PS > get-childitem $env:USERPROFILE\Documents | where-object { $_.psIsContainer }</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">12. PS > get-acl $env:userprofile | format-list</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">13. PS > ps | sort PM | select-object -last 25 | where-object { $_.CPU } | sort ID</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">14. PS > get-itemproperty HKLM:\SOFTWARE\Microsoft\Notepad\DefaultFonts</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">15. PS > get-service | sort-object DisplayName</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">16. PS > get-eventlog application -newest 100 | ? { $_.EntryType -eq "Error" } | fl timewritten,source,message</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">17. PS > "{0:F1}" -f ((get-date 1/1/2100) - (get-date)).totalminutes</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">18. PS > get-childitem "$env:userprofile\documents" | where-object { $_.name -match "^....`.txt$" }</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">19. PS > get-childitem "$env:userprofile\documents" | where-object { $_.name -like "PIC*" } | foreach-object { copy-item $_.fullname -destination "$env:userprofile\documents\photos\" }</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">20. PS > $env:computername</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">21. PS > test-path C:\pscustinstaller.log</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">22. and 23.<br />PS > dir c:\windows\system32 | where-object { $_.name -like "wi*" } | foreach { $_.fullname }<br />PS > dir c:\windows\system32 | where-object { $_.name -like "wi*" } | foreach { write-host $_.fullname }</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">24. PS > $env:path += ";D:\Files\"</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">25. PS > $x = 5; "'$x': $x"; "`$x: $x"; '$x: ' + "$x"</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">26. PS > ls c:\windows | sort lastaccesstime -descend</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">27. PS > dir c:\windows\system32 | where-object { $_.LastAccessTime -gt ([DateTime]::Now).AddDays(-7) }</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">28. PS > ls hklm:\SOFTWARE\Microsoft\.NETFramework -recurse | where-object { $_.Name -like "*2.0.50727*" } | fl Name</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<span class="code" style="color: black;">29. PS > get-content users.txt | sort-object -unique</span></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<span class="code" style="color: black;">30. PS > get-childitem cert:\localmachine\root | where-object { $_.subject -like "*Trust Network*" } | where-object { $_.notafter -gt (get-date).addyears(10) } | ft Subject, friendlyname</span></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<span class="code" style="color: black;">31. PS > dir env: | where { $_.name -like "user*" }</span></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">32. PS > get-acl (dir "c:\program files" | % { $_.fullname }) | fl</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">33. PS > get-wmiobject win32_quickfixengineering | format-table hotfixID, installedon, description -autosize</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">34. PS > ls $env:USERPROFILE\Documents | ? { $_.name -like "*.jpg" -or $_.name -like "*.jpeg" } | % { $_.name }</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">35. and 36.<br />PS > get-process | select-object name, cpu, path<br />PS > get-process | format-table name, cpu, path</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">37. PS > get-childitem c:\windows\system32 | foreach-object { $_.fullname; $_.creationtime -lt [datetime]"1/1/2010"; "" }</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">38. PS > [void][system.reflection.assembly]::LoadWithPartialName("System.Windows.Forms")</span></a></div>
<div class="posh-question" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<a class="toggle" href="javascript:;" style="color: #a3a948; text-decoration: none;"><span class="code" style="color: black;">39. PS > get-childitem c:\windows\system32 | foreach-object -begin { $x = 0 } -process { $x += $_.length } -end { [math]::round($x/1MB,2).tostring() + " MB" }</span></a></div>
<div class="posh-question active" style="font-family: 'Courier New', Courier, monospace; margin-top: 13px;">
<span class="code" style="color: black;">40. PS > new-psdrive "scripts" -psprovider filesystem -root "C:\users\bill\scripts\powershell"</span></div>
</div>
<br />
<br />
Here are some sample <strong style="color: #ce1836;">PowerShell interview questions</strong>. These are the kinds of questions that could be asked to gauge one's basic literacy and comfort level with PowerShell.</div>
<div style="font-family: georgia, serif; font-size: 20px; margin: 10px 10px 20px;">
Some things to keep in mind:</div>
<ul style="font-family: georgia, serif;">
<li>In general, interview questions are meant to be relatively quick - quick to ask, and quick to answer.</li>
<li>As such, the solution should be straight-forward - worry about efficiency and clever tricks later.</li>
<li>These questions are mostly technology-agnostic, aside from Windows and PowerShell themselves (no Exchange, IIS, SharePoint, etc. -based questions).</li>
<li>There may be many ways to solve a problem, the solutions provided are just one interpretation and solution.</li>
</ul>
<div style="font-family: georgia, serif; font-size: 20px; margin: 10px 10px 20px;">
</div>
<div style="font-family: georgia, serif; font-size: 20px; margin: 10px 10px 20px;">
Give each question a try. As in an interview, you can get a <strong style="color: #ce1836;">hint</strong> in the right direction by clicking the Hint button To see a <strong style="color: #ce1836;">solution</strong>, click on the text of the question.</div>
<div class="section" style="margin: 15px;">
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
1. Basic literacy. Describe the following:<br />
a. What is PowerShell? Why is it called a shell?<br />
b. How does PowerShell differ previous Windows scripting techniques, such as CMD/batch files, VBScript, etc.?<br />
c. What is a cmdlet?<br />
d. What is meant when it's said that Powershell is "object-based"?<br />
e. What is the pipeline? How is it useful?</div>
<div class="hint-button" style="font-family: georgia, serif;">
<b>[None]</b></div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
2. How would you find the name of the local computer?</div>
<div class="hint-button">
<span style="font-family: georgia, serif;"><b>Environment variable</b></span></div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
3. Convert the number <span class="code" style="font-family: 'Courier New', Courier, monospace;">11867</span> into hexadecimal. Now, convert the hex value <span class="code" style="font-family: 'Courier New', Courier, monospace;">0x1aab</span> to decimal (base-10).</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>Part 1: Convert to a string; Part 2: Don't think too hard.</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
4. Get the amount of free space on the C drive.</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>WMI is an option</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
5. Count the number of lines in a file, excluding blank spaces.</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>3 Steps: Get all lines, filter out blanks, count what's left.</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
6. Get names of all "Manual" services that aren't running. All that are.</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>WMI - unfortunately get-service doesn't have StartMode info</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
7. Read in a text file, replace all social security numbers with ***-**-****.</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>PowerShell has a built-in -replace operator.</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
8. Get all running processes using over 10MB of (physical) memory. Save this info to CSV file.</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>get-help *process*; get-help *csv*</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
9. Look in a directory, return all txt files that have a name of the pattern: 4 letters, followed by 3 numbers.</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>Perhaps too complex pattern for get-childitem's -filter</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
10. Look at the recent log files in a given directory (extension ".log") - those modified within the past 24 hours. Search for the word "ERROR", and return the lines that contain ERROR.</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>Tackle each step in order, using pipeline to your advantage -- can be done with a 1-liner</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
11. Get the number of processors/cores on your system. Get the clock speed of the processor(s).</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>WMI is a good place to start when looking for system info</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
12. Assume you have a file with a bunch of records - names, or phone numbers, or GUIDs, etc. Read in that file, remove all duplicate records.</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>Get the contents, then pipe to... some cmdlet</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
13. Download a website (http://www.zappos.com/), return all of the phone numbers on the page.</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>WebClient to download, then match on the pattern</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
14. Get every other line in a text file (ie. 1st, 3rd, 5th lines...)</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>Remember that array indeces go 0, 1, 2, 3...</b><br />
<b>For loop is one possibility, but can also be done with pipeline approach.</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
15. Load an XML document from file. Find all of the nodes of a particular type wherever they are, and get the inner text. For example, get all of the "price" nodes.</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>Use XPath syntax to get nodes.</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
16. Get events from System event log referring to services entering "running state". Limit to only the most-recent hundred entries in System.</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>Look at the Message property of each event</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
17. Read in numbers from a text file (one integer per line). If the number is greater than 10, print the number in green text; else, print it in red.</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>[int] | get-member -static</b><br />
<b>write-host</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
18. Use netstat to get all open network connections. Filter to just those "LISTENING".</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>netstat -a</b><br />
<b>Remember - netstat is a legacy CMD utilty, and will return a big blob of text rather than objects.</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
19. How many seconds are in the next year?</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>When subtracting two DateTime objects, a TimeStamp object is returned</b></div>
</div>
<div class="posh-question" style="font-family: georgia, serif; margin-top: 13px;">
20. Get the running services on a remote machine. How would you do it if you don't have PowerShell V2?</div>
<div class="toggle_hint" style="font-family: georgia, serif;">
<div class="posh-hint">
<b>Without V2, fall back on WMI</b><br />
<b><br /></b></div>
</div>
</div>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-62052823324976030702013-05-03T22:32:00.002-07:002013-05-03T22:32:52.206-07:00Developing Initiation Form on Sharepoint Workflows<div dir="ltr" style="text-align: left;" trbidi="on">
Have you ever wondered what's the use of Initiation Forms on Sharepoint? Have you ever thought of creating a list item based on an item on another list? Do you want to extend the 2 buttons in Manual Workflow Initiation to have input forms? Well that’s the use of the Initiation Forms and I will run you though a sample that will work for you.<br />
<br />
So what is an Initiation form? It's simply a page that is presented when you start a workflow manually, the page where you see two buttons for “Start” and “Cancel”. By default, you have those buttons but you can extend this page by adding form fields and use the value on those as variables that you can consume for your workflow process.<br />
<br />
So let's start with a sample, let's say you have the requirement to have an Office Supply list where your team can place an order on a specific item and that invokes a workflow on the back, making a task list grabbing important details like Name of requester, quantity and the Item requested. Here are the steps to achieve it.<br />
<ol style="border: 0px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">Create an “Office Supplies” List:<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1145" height="329" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/01.jpg?w=630&h=346" style="border: 0px; height: 329px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 600px;" title="01" width="600" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Now using Sharepoint Designer, go to your list and create a workflow.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1146" height="359" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/02.jpg?w=630&h=377" style="border: 0px; height: 359px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 600px;" title="02" width="600" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Name your workflow, I called it “Supply Request Workflow”<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1147" height="290" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/03.jpg?w=540&h=290" style="border: 0px; height: 290px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 540px;" title="03" width="540" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Now Save and Publish your workflow and make sure it created a Task List and History List:<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1148" height="487" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/04.jpg?w=629&h=511" style="border: 0px; height: 487px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 600px;" title="04" width="600" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Double check if you have the Task List by going to your Sharepoint instance:<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1149" height="269" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/05.jpg?w=427&h=269" style="border: 0px; height: 269px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 427px;" title="05" width="427" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Now update that task list to cater to the following new fields: Item Requested, Quantity and Requested By.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1150" height="376" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/06.jpg?w=630&h=395" style="border: 0px; height: 376px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 600px;" title="06" width="600" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Back to Sharepoint Designer and edit your workflow again:<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1151" height="213" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/07.jpg?w=543&h=213" style="border: 0px; height: 213px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 543px;" title="07" width="543" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Now create an Initiation Form by clicking the Initiation Form Parameters:<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1152" height="175" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/08.jpg?w=630&h=184" style="border: 0px; height: 175px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 600px;" title="08" width="600" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Now add the field, this is the field that will populate your Task List as well on step 6, so create the same fields and its format you have on the said step.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1153" height="270" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/09.jpg?w=462&h=270" style="border: 0px; height: 270px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 462px;" title="09" width="462" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Once done, it is time for you to set up an Action on Step 1, and we need to create a “Create List Item” action:<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1154" height="332" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/10.jpg?w=426&h=332" style="border: 0px; height: 332px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 426px;" title="10" width="426" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Now choose the property “this list”.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1155" height="102" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/11.jpg?w=605&h=104" style="border: 0px; height: 102px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 600px;" title="11" width="600" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Now choose the “Association: Task List”:<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1156" height="423" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/12.jpg?w=378&h=423" style="border: 0px; height: 423px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 378px;" title="12" width="378" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Modify the Value sent to those fields:<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1157" height="151" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/13.jpg?w=258&h=151" style="border: 0px; height: 151px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 258px;" title="13" width="258" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">For example, in the Title Field (“of the Task List”), you want to use the Current Item which is the “Office Supply List” Name.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1158" height="423" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/14.jpg?w=508&h=423" style="border: 0px; height: 423px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 508px;" title="14" width="508" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">You can add more <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">string</code>s of your choice if you want, so since this is a new request we make the title “New Item Requested : Your Item”.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1159" height="425" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/15.jpg?w=508&h=425" style="border: 0px; height: 425px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 508px;" title="15" width="508" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Now for other fields like <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">Quantity</code>, you can grab it from the initiation form you created in Step 8. To do that, just choose “Workflow Variables and Parameters” in Data Source and you will see the fields you created on the “Field from source”.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1160" height="198" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/16.jpg?w=378&h=198" style="border: 0px; height: 198px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 378px;" title="16" width="378" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Once all values are properly assigned, click OK.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1161" height="423" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/17.jpg?w=378&h=423" style="border: 0px; height: 423px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 378px;" title="17" width="378" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Now Save and Publish again.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1162" height="217" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/18.jpg?w=630&h=228" style="border: 0px; height: 217px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 600px;" title="18" width="600" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Now usually manual initiation workflow starts by hitting the Workflows Button, then choosing the appropriate workflow to run. To make it a bit user-friendly, I guess we will have to create a button on the Display Form Ribbon of an item. Do that by clicking Custom Action and choose “Display Form Ribbon”.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1163" height="314" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/19.jpg?w=630&h=330" style="border: 0px; height: 314px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 600px;" title="19" width="600" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Now name your button, I called it Request now. And set it to initiate your “Supply Request Workflow”.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1164" height="495" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/20.jpg?w=560&h=495" style="border: 0px; height: 495px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 560px;" title="20" width="560" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Add your icons. Then you are done.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1165" height="495" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/21.jpg?w=560&h=495" style="border: 0px; height: 495px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 560px;" title="21" width="560" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Open now a list item on “Office Supplies” list, then you will see your “Request Now” button. Click that.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1166" height="296" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/22.jpg?w=630&h=310" style="border: 0px; height: 296px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 600px;" title="22" width="600" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Now you see your “Supply Request Workflow” with the input forms you had defined.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1167" height="291" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/23.jpg?w=534&h=291" style="border: 0px; height: 291px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 534px;" title="23" width="534" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">Click start to initiate the request, and you will see it on the “Task List”<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1168" height="142" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/24.jpg?w=630&h=150" style="border: 0px; height: 142px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 600px;" title="24" width="600" /></a></li>
<li style="border: 0px; margin: 0px; padding: 0px;">With the fields populated as configured.<a href="javascript:;" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;"><img border="0" class="alignnone size-full wp-image-1169" height="533" hspace="0" src="http://anyrest.files.wordpress.com/2010/12/25.jpg?w=630&h=560" style="border: 0px; height: 533px; margin: 0px; max-width: 100%; overflow: auto; padding: 0px; width: 600px;" title="25" width="600" /></a><br />
</li>
</ol>
<br /></div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-67258764519144393382013-05-03T22:17:00.004-07:002013-05-03T22:17:58.640-07:00SharePoint 2010 Forms Templates<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">In this article I'll tell you how to change standard templates for Edit, Display and New Forms for List Items and Documents in Sharepoint 2010. You can make it with SharePoint Designer or InfoPath for partucular lists. This is described here:</span><br />
<ul style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;"><a href="http://office.microsoft.com/en-us/sharepoint-designer-help/create-a-custom-list-form-using-sharepoint-designer-HA010378258.aspx" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;">http://office.microsoft.com/en-us/sharepoint-designer-help/create-a-custom-list-form-using-sharepoint-designer-HA010378258.aspx</a></li>
<li style="border: 0px; margin: 0px; padding: 0px;"><a href="http://msdn.microsoft.com/en-us/library/gg180738.aspx" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;">http://msdn.microsoft.com/en-us/library/gg180738.aspx</a></li>
</ul>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
But what if you need to change all forms of templates in the farms with your custom form through wsp-package? While I was investigating this question I found many suggestions to change file 14<em style="border: 0px; margin: 0px; padding: 0px;">\TEMPLATE\CONTROLTEMPLATES\DefaultTemplates.ascx</em>:</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
This template is used for default list edit, display and to create form of list items:</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
<pre id="pre0" lang="xml" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">SharePoint:RenderingTemplate</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">id</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">ListForm"</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">runat</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">server"</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">Template</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
… <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">Template</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">SharePoint:RenderingTemplate</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span></pre>
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
And this one is used for documents:<br />
<div>
<pre id="pre1" lang="xml" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">SharePoint:RenderingTemplate</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">id</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">DocumentLibraryForm"</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">runat</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">server"</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">Template</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
… <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">Template</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">SharePoint:RenderingTemplate</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span></pre>
</div>
<div>
Yes, if you change these templates and make iisreset you'll get what you want — a new template for all forms. So, what if we don't want to change the system files? Okey, let's look at the control, that manages templates in<em style="border: 0px; margin: 0px; padding: 0px;">CONTROLTEMPLATES</em> folder: SPControlTemplateManager. The method <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">GetTemplateByName(String)</code> of this class returns the template of <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">RenderingTemplatecontrol</code> by its ID. All templates are loaded to the static HASH-table after the first call of this method. That is why we should make iisreset after changing <em style="border: 0px; margin: 0px; padding: 0px;">DefaultTemplates.ascxfile</em>. So let's see how it works:</div>
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
<pre id="pre2" lang="cs" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">private</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">static</span> Hashtable GetTemplateCollection()
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">if</span> ((s_templateTable == <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">null</span>) && (HttpContext.Current != <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">null</span>))
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">lock</span> (InternalSyncObject)
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">if</span> (s_templateTable == <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">null</span>)
{
Hashtable templateTable = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> Hashtable();
FileInfo[] files = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> DirectoryInfo(
HttpContext.Current.Server.MapPath(systemTemplateLocation)).GetFiles(<span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">*.ascx"</span>);
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">string</span> controlTemplateFile = systemTemplateLocation + defaultTemplateFile;
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">string</span> str3 = systemTemplateLocation + mobileDefaultTemplateFile;
LoadControlTemplate(templateTable, controlTemplateFile);
LoadControlTemplate(templateTable, str3);
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">foreach</span> (FileInfo info2 <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">in</span> files)
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">if</span> (!(info2.Name == defaultTemplateFile) && !(info2.Name == mobileDefaultTemplateFile))
{
controlTemplateFile = systemTemplateLocation + info2.Name;
LoadControlTemplate(templateTable, controlTemplateFile);
}
}
s_templateTable = templateTable;
}
}
}
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">return</span> s_templateTable;
}</pre>
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
Variables values:<br />
<ul style="border: 0px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">systemTemplateLocation = "/_controltemplates/";</li>
<li style="border: 0px; margin: 0px; padding: 0px;">defaultTemplateFile = "DefaultTemplates.ascx";</li>
</ul>
As you see, first, this control loads all templates from <em style="border: 0px; margin: 0px; padding: 0px;">DefaultTemplates.ascxfile</em>. Then it gets all files form<em style="border: 0px; margin: 0px; padding: 0px;">CONTROLTEMPLATES</em> directory and loads all templates from them. So if it finds templates with the same name as defined in <em style="border: 0px; margin: 0px; padding: 0px;">DefaultTemplates.ascx</em> it replaces them. Okey, let’s check it. Create a new file in <em style="border: 0px; margin: 0px; padding: 0px;">CONTROLTEMPLATE</em>directory and add a template to it:<br />
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
<pre id="pre3" lang="xml" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">SharePoint:RenderingTemplate</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">id</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">ListForm"</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">runat</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">server"</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">Template</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">h1</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>Custom form!<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">h1</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">Template</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">SharePoint:RenderingTemplate</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span></pre>
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Make iisreset, navigate some list and try to create a new item. You'll see our title instead of form. Okey, it works perfectly for standard templates, but what if we want to change the template for only one Web Application or SiteCollection or change the template for DocumentSet display form, which stores its template in file<em style="border: 0px; margin: 0px; padding: 0px;">DocSetTemplates.ascx</em>. Let's look at ListFormWebPart. This class has property TemplateName which is used to get a template name by current context (Edit, Create or Display):</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
<pre id="pre4" lang="cs" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">public</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">string</span> TemplateName
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">get</span>
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">if</span> (<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.templateName == <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">null</span>)
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.EnsureListAndForm();
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">if</span> (<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.ItemContext != <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">null</span>)
{
SPContentType contentType = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.ItemContext.ContentType;
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">if</span> (contentType != <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">null</span>)
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">switch</span> (<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.pageType)
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">case</span> PAGETYPE.PAGE_DISPLAYFORM:
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.templateName = contentType.DisplayFormTemplateName;
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">break</span>;
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">case</span> PAGETYPE.PAGE_EDITFORM:
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.templateName = contentType.EditFormTemplateName;
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">break</span>;
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">case</span> PAGETYPE.PAGE_NEWFORM:
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.templateName = contentType.NewFormTemplateName;
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">break</span>;
}
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">if</span> ((<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.templateName != <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">null</span>) && (<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.templateName.Length > <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>))
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">return</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.templateName;
}
}
}
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">if</span> (<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.form != <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">null</span>)
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.templateName = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.form.TemplateName;
}
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">else</span>
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.templateName = <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">ListForm"</span>;
}
}
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">return</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.templateName;
}
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">set</span>
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">this</span>.templateName = value;
}
}</pre>
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
To get the name of the templates it uses properties of ContentType: <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">DisplayFormTemplateName</code>,<code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">EditFormTemplateName</code>, <code style="border: 0px; color: #990000; font-family: Consolas, 'Courier New', Courier, mono; font-size: 11pt; margin: 0px; padding: 0px;">NewFormTemplateName</code>. So, we can create a new template in <em style="border: 0px; margin: 0px; padding: 0px;">CONTROLTEMPLATES</em>directory and set its name into all content types we need with powershell, for example. If we remove our template nothing happens, because if the template is not found it uses a default ListForm template.</div>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-51572731821554173652013-05-03T21:33:00.001-07:002013-05-03T21:34:02.291-07:00Send email messages with embedded images<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">While creating email messages with HTML content, normally the images are displayed with IMG tag, where the SRC attribute pointing to an image, which is hosted in the web server. Most email clients will not display the images, which is downloading from the web. Instead of pointing to web URL, you can embed image in the mail message with the help of </span><a href="http://msdn.microsoft.com/en-IN/library/system.net.mail.linkedresource.aspx" style="background-color: white; border: 0px; color: purple; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-decoration: none;">LinkedResource</a><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"> and </span><a href="http://msdn.microsoft.com/en-IN/library/system.net.mail.alternateview.aspx" style="background-color: white; border: 0px; color: purple; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-decoration: none;">AlternateView</a><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"> classes.</span><br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Here is the snippet, which embed an image to the email. The convention to access linked resource is cid:name of the linked resource, which is the value of IMG tag SRC attribute.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
<pre class="brush: csharp; title: ; notranslate" id="pre0" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">var</span> logo = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> LinkedResource(<span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">@"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">C:\logo.jpg"</span>);
logo.ContentId = Guid.NewGuid().ToString();
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">var</span> body =
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">string</span>.Format(<span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">@"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;"><html><body><h1>Image</h1><img src="</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">cid:{0}"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;"> /></body></html>"</span>,
logo.ContentId);
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">var</span> view = AlternateView.CreateAlternateViewFromString(body, <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">null</span>, <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">"</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">text/html"</span>);
view.LinkedResources.Add(logo);
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">using</span> (<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">var</span> message = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body,
IsBodyHtml = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">true</span>
})
{
message.AlternateViews.Add(view);
smtp.Send(message);
}</pre>
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
Note: This method will increase the size of the email, as the images are embedded.<br />
<div>
<br /></div>
<div>
<strong style="border: 0px; margin: 0px; padding: 0px;">Related content:</strong><br />
<ol style="border: 0px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;"><a href="http://www.dotnetthoughts.net/fluent-email-library-for-c-using-dynamicobject/" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;" title="Permanent link to Fluent email library for c# using DynamicObject">Fluent email library for c# using DynamicObject</a></li>
<li style="border: 0px; margin: 0px; padding: 0px;"><a href="http://www.dotnetthoughts.net/uploading-files-using-webservice/" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;" title="Permanent link to Uploading Files using Webservice">Uploading Files using Webservice</a></li>
<li style="border: 0px; margin: 0px; padding: 0px;"><a href="http://www.dotnetthoughts.net/post-data-using-httpwebrequest-in-c-sharp/" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;" title="Permanent link to Post data using HttpWebRequest in C#">Post data using HttpWebRequest in C#</a></li>
<li style="border: 0px; margin: 0px; padding: 0px;"><a href="http://www.dotnetthoughts.net/how-to-store-and-retrieve-files-from-sql-server-database/" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;" title="Permanent link to How to Store and Retrieve files from SQL Server Database">How to Store and Retrieve files from SQL Server Database</a></li>
<li style="border: 0px; margin: 0px; padding: 0px;"><a href="http://www.dotnetthoughts.net/convert-image-to-icon-using-c/" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;" title="Permanent link to Convert Image to Icon using C#">Convert Image to Icon using C#</a></li>
</ol>
</div>
<div class="betterrelated" style="border: 0px; margin: 0px; padding: 0px;">
</div>
<br /></div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-16615901394202041032013-05-03T21:27:00.000-07:002013-05-03T21:27:32.897-07:00Creating a smoke using Particle System in Silverlight<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">Here’s what we’re trying to achieve: </span><a href="http://jkarthik.vacau.com/ParticleEffect.html" style="background-color: white; border: 0px; color: purple; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-decoration: none;">demo</a><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"> </span><br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
One of a fellow programmer came up with a question of “How do you create Smoke effect using Silverlight?” Well there may be plenty of code, third-party tools and plug-ins strewn over the internet for this, but out of a professional curiosity I got into the business of creating one out of my own hands.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
The whole concept of creating smoke (without fire <img alt=";)" class="wp-smiley" complete="true" src="http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif" style="border: 0px; height: auto; margin: 0px; max-width: 100%; overflow: auto; padding: 0px;" /> ) can be done through what they call as <a href="http://en.wikipedia.org/wiki/Particle_system" style="border: 0px; color: purple; margin: 0px; padding: 0px; text-decoration: none;">Particle System</a>. It’s a technique where in you employ very small graphical objects in large numbers to simulate effects like say Smoke, Fire, Snow, Dust, etc…</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
We need the smoke to be moving freely, so a canvas would be a best bet for the layout.</div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
<pre id="pre0" lang="xml" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">Canvas</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">x:Name</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">myCanvas"</span> <span class="code-attribute" style="border: 0px; color: red; margin: 0px; padding: 0px;">Background</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">="</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">White"</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;"><</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">/</span><span class="code-leadattribute" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">Canvas</span><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">></span></pre>
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
From this point on the rest of the Smoke effect would be programmed in code behind file (C-Sharp in my case)<br />
<br />
Let’s think a minute about smoke, shall we? Smoke starts at a point, very concentrated (Generation Point). According to the complex laws of physics, it simply rises up becoming dilute all the way. Finally blending well with the air where it seems to disappear (Vanishing Point).<br />
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-BG1qxlUm_poPDdRUQxP1Z0GABUvRk-ptd7tnLxOwigiHcQYOZZbTY_ALLgGYJaIsFkFVYTynltAESNmSbyjY2N-67cdIenLudSb_7sFU-Zxcc3WRRZRNaw6NcsRlxZ-eHz2FGdJifHU/s1600/particleeffect%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-BG1qxlUm_poPDdRUQxP1Z0GABUvRk-ptd7tnLxOwigiHcQYOZZbTY_ALLgGYJaIsFkFVYTynltAESNmSbyjY2N-67cdIenLudSb_7sFU-Zxcc3WRRZRNaw6NcsRlxZ-eHz2FGdJifHU/s1600/particleeffect%5B1%5D.png" /></a></div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
<div class="wp-caption alignleft" id="attachment_168" style="border: 0px; margin: 0px; padding: 0px; width: 328px;">
<div class="wp-caption-text">
Understanding the dynamics of smoke</div>
</div>
<br />
Our approach would be to consider smoke as made up of small particles, which would originate at the Generation Point. These particles as time passes would simply rise up, becoming transparent by smaller percentages as it goes and finally becoming invisible at the Vanishing Point.<br />
<br />
These particles are going to be ellipses. Let’s have a method which does just that.<br />
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
<pre id="pre1" lang="cs" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">public</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">static</span> Ellipse createEllipse()
{
Ellipse objEllipse = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> Ellipse();
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">//</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">Smaller sized particles
</span>objEllipse.Width = <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>;
objEllipse.Height = <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>;
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">//</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">Giving the particles a Smokey look
</span>RadialGradientBrush rgbObj = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> RadialGradientBrush();
GradientStop gsObj1 = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> GradientStop();
gsObj1.Color = Colors.Transparent;
gsObj1.Offset = <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">2</span>;
GradientStop gsObj2 = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> GradientStop();
gsObj2.Color = Colors.DarkGray;
gsObj2.Offset = <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">5</span>;
GradientStop gsObj3 = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> GradientStop();
gsObj3.Color = Colors.Black;
gsObj3.Offset = <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">001</span>;
rgbObj.GradientStops.Add(gsObj1);
rgbObj.GradientStops.Add(gsObj2);
rgbObj.GradientStops.Add(gsObj3);
objEllipse.Fill = rgbObj;
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">//</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">Set the position of the ellipses to the Generation Point
</span>Canvas.SetTop(objEllipse, <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">300</span>);
Canvas.SetLeft(objEllipse, <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">150</span>);
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">return</span> objEllipse;
}</pre>
<br />
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
</div>
While the Silverlight application initializes, we’d simply call the following line to add a new smoke particle:<br />
<div>
<pre id="pre2" lang="cs" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">myCanvas.Children.Add(createEllipse());</pre>
</div>
<div>
Well, this is just one particle. By every tick of the clock, new particles should be generated to give the effect of the smoke billowing. This calls for a DispatcherTimer instance which would give me an event for say every 2 millisecond.</div>
<div>
<pre id="pre3" lang="cs" style="border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">System.Windows.Threading.DispatcherTimer timer = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> System.Windows.Threading.DispatcherTimer();
timer.Interval = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> TimeSpan(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">2</span>);
timer.Tick += timer_Tick;
timer.Start();</pre>
</div>
<div>
At every tick, we need to be doing a set of tasks based on a few decisions.</div>
<div>
<br /></div>
<div>
<strong style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">Firstly,</strong><span style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;"> we cannot afford to overload the memory/screen with infinite number of particles. When a smoke particle simply disappears beyond the vanishing point, we can move them down to the generation point and reuse them. For this purpose, let’s have a limit of 1000 particles that can be freshly generated. If the screen has less than 1000 of them, we can go ahead and generate a new one.</span></div>
<div>
<pre id="pre4" lang="cs" style="border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">if</span> (myCanvas.Children.Count < <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1000</span>){
generateFireParticles();
}</pre>
</div>
<div>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<strong style="border: 0px; margin: 0px; padding: 0px;">Secondly,</strong> at every instant – *all* the smoke particles should perform the following tasks:</div>
<ul style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">Rise up</li>
</ul>
<div class="pre-action-link" id="premain5" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre5" lang="cs" style="border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">Canvas.SetTop(item, Canvas.GetTop(item) - <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">25</span>);
</pre>
<ul style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">Grow and become lighter in visibility</li>
</ul>
<div class="pre-action-link" id="premain6" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre6" lang="cs" style="border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">item.Opacity = item.Opacity - <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">009</span>;
item.Width = item.Width + <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">075</span>;
item.Height = item.Height + <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">075</span>;</pre>
<ul style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 10px 0px; padding: 0px 0px 0px 40px;">
<li style="border: 0px; margin: 0px; padding: 0px;">And take a wavy path up. Smoke particles take a simply chaotic path up, they just don’t go up in a straight line.</li>
</ul>
<div class="pre-action-link" id="premain7" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre7" lang="cs" style="border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;">Random randObj = <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">new</span> Random(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">10</span>);
Canvas.SetLeft(item, Canvas.GetLeft(item) - (Math.Pow(-1, randObj.Next(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">5</span>)) * randObj.Next(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">2</span>)));</pre>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<strong style="border: 0px; margin: 0px; padding: 0px;">Thirdly,</strong> Move every vanished particle back to its original point.</div>
<div class="pre-action-link" id="premain8" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre8" lang="cs" style="border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">if</span> (item.Opacity < <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0001</span>){
item.Opacity = <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>;
item.Width = item.Height = <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>;
Canvas.SetTop(item, <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">150</span>);
Canvas.SetLeft(item, <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">300</span>);
}</pre>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
So, considering all above, my timer tick event would look like this:</div>
<div class="pre-action-link" id="premain9" style="background-color: white; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-width: 0px 0px 1px; color: #005782; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right;" width="100%">
<br /></div>
<pre id="pre9" lang="cs" style="border: 1px solid rgb(251, 237, 187); font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">void</span> timer_Tick(<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">object</span> sender, EventArgs e)
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">if</span> (myCanvas.Children.Count < <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1000</span>)
{
generateFireParticles();
}
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">foreach</span> (Ellipse item <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">in</span> myCanvas.Children)
{
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">if</span> (item.Opacity < <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0001</span>)
{
item.Opacity = <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>;
item.Width = item.Height = <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>;
Canvas.SetTop(item, Y);
Canvas.SetLeft(item, X);
}
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">else</span>
{
item.Opacity = item.Opacity - <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">009</span>;
item.Width = item.Width + <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">075</span>;
item.Height = item.Height + <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">075</span>;
Canvas.SetTop(item, Canvas.GetTop(item) - <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">25</span>);
Canvas.SetLeft(item, Canvas.GetLeft(item) - (Math.Pow(-1, randObj.Next(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">5</span>)) * randObj.Next(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">2</span>)));
}
}
}</pre>
<div style="background-color: white; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
Thus, was how we can generate a smoke effect in Silverlight using Particle System. With a minor change in the color and nature of the ellipse, you can create Fire or other similiar effects.</div>
</div>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0tag:blogger.com,1999:blog-8836753959938896287.post-46899998174237375322013-05-03T12:06:00.000-07:002013-05-03T12:06:01.091-07:00How to setup multiple startup projects in Visual Studio ?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
In this blog post I am going to describe a small tips of visual studio where you will get to know how you can launch multiple project at same time. This is quite useful when you are working on a solution which having multiple project type and you want to run few of them in same time.</div>
<div style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
Let’s assume you have a frontend application which developed using WPF and in the backend you are calling a WCF Service. Now to test the application you need both of them on running stage. By default Visual Studio project Setup type sets to <code style="color: #3366cc; margin: 0px; padding: 0px;">Single Startup Project</code> . If you set any of the project as “Start up” then that project will start when you run the application. So after that you need to run the second project also. Below is the Project setup window where you can find the all the setting related with project start up. You can open that window by right clicking on <code style="color: #3366cc; margin: 0px; padding: 0px;">Solution</code>” ><code style="color: #3366cc; margin: 0px; padding: 0px;">Properties</code> > <code style="color: #3366cc; margin: 0px; padding: 0px;">Common Properties</code>” > <code style="color: #3366cc; margin: 0px; padding: 0px;">Startup Project”</code></div>
<div style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
<code style="color: #3366cc; margin: 0px; padding: 0px;"><br /></code></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxna7se7VIaOXsRex3qxbmQ9ak7Dl7di-d6AuuGyOnMDNJsh6NsxIsMrIczY5H9VJzSJbXWyXnk0gUpMw3FtUH78CVN0ZrOB2xgMbFhE-tnnMlZ6QeRX1Y4YeumUP2AjetUtBCJrhFlqI/s1600/811201023347AM_thumb%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="203" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxna7se7VIaOXsRex3qxbmQ9ak7Dl7di-d6AuuGyOnMDNJsh6NsxIsMrIczY5H9VJzSJbXWyXnk0gUpMw3FtUH78CVN0ZrOB2xgMbFhE-tnnMlZ6QeRX1Y4YeumUP2AjetUtBCJrhFlqI/s320/811201023347AM_thumb%5B1%5D.png" width="320" /></a></div>
<div style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
<code style="color: #3366cc; margin: 0px; padding: 0px;"></code></div>
<div style="color: black; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
<code style="color: #3366cc; margin: 0px; padding: 0px;">Now, if you look into the above picture you will find we have three options for project setup.</code></div>
<div style="color: black; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
</div>
<div style="color: black; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
<code style="color: #3366cc; margin: 0px; padding: 0px;"><span id="more-82" style="margin: 0px; padding: 0px;"></span></code></div>
<div style="color: black; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
<code style="color: #3366cc; margin: 0px; padding: 0px;"><strong style="margin: 0px; padding: 0px;"><span style="color: #804040; margin: 0px; padding: 0px;">1. Current Selection :</span></strong> This selection will automatically select the project as startup when ever you will click on the project.</code></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8zhknOLVr6cQPwkSDcBrXsbe9Dw6Tb6SZENDCikZw0tO5i_1PVBdpX4KPcpD03rLlMGzPvPF6F9azizcNJc3WlPK8hLylBtgTTzwaz_WSoPCTvRKkO0HPD18jPGtQo_Q-LcLmFVtu_qc/s1600/CurrentSelection_thumb%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8zhknOLVr6cQPwkSDcBrXsbe9Dw6Tb6SZENDCikZw0tO5i_1PVBdpX4KPcpD03rLlMGzPvPF6F9azizcNJc3WlPK8hLylBtgTTzwaz_WSoPCTvRKkO0HPD18jPGtQo_Q-LcLmFVtu_qc/s1600/CurrentSelection_thumb%5B1%5D.png" /></a></div>
<div style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
<code style="color: #3366cc; margin: 0px; padding: 0px;"><br /></code></div>
<div style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
<code style="color: #3366cc; margin: 0px; padding: 0px;"><strong style="color: black; font-family: 'Trebuchet MS', sans-serif; margin: 0px; padding: 0px;"><span style="color: maroon; margin: 0px; padding: 0px;">2. Single Startup Project :</span> </strong><span style="color: black; font-family: 'Trebuchet MS', sans-serif;">This is the default setup for Visual Studio where first created project will be set as startup, if you want to change the startup project, just right click on the project and select </span><em style="color: black; font-family: 'Trebuchet MS', sans-serif; margin: 0px; padding: 0px;">“Set as Startup Project”</em><span style="color: black; font-family: 'Trebuchet MS', sans-serif;"> or Open the properties windows and select the project from the dropdown window of </span><em style="color: black; font-family: 'Trebuchet MS', sans-serif; margin: 0px; padding: 0px;">“Single startup project”</em><span style="color: black; font-family: 'Trebuchet MS', sans-serif;"> as shown in below picture.</span></code></div>
<div style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
<code style="color: #3366cc; margin: 0px; padding: 0px;"><br /></code></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf659TlYBYAtS9fyiEsrjrYi_V06oAc7jNsu84Oq8Gm5aKCMigQsKxyB_aUUcxgJcIneJW8XczouJWD91oTed_Mzesxis841P0bvabRYQ5x6tBbWs_3KMPGQksoW9XNnncIyFmRnepTts/s1600/single2_thumb%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf659TlYBYAtS9fyiEsrjrYi_V06oAc7jNsu84Oq8Gm5aKCMigQsKxyB_aUUcxgJcIneJW8XczouJWD91oTed_Mzesxis841P0bvabRYQ5x6tBbWs_3KMPGQksoW9XNnncIyFmRnepTts/s1600/single2_thumb%5B1%5D.png" /></a></div>
<div style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
<code style="color: #3366cc; margin: 0px; padding: 0px;"><br /></code></div>
<div style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
<code style="color: #3366cc; margin: 0px; padding: 0px;"><strong style="color: black; font-family: 'Trebuchet MS', sans-serif; margin: 0px; padding: 0px;"><span style="color: navy; margin: 0px; padding: 0px;">3. Multiple Startup Project:</span> </strong><span style="color: black; font-family: 'Trebuchet MS', sans-serif;">For above two option you can run only one project at a time. So if you want to run multiple application same time you can change the setting from Multiple project setup section. Using multiple startup project setting you can set the multiple startup project from the </span><code style="margin: 0px; padding: 0px;">Action Tab</code><span style="color: black; font-family: 'Trebuchet MS', sans-serif;">.</span></code></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1pi64cvbH-oaPP2M9UOyP_z-xJ2Ubo5CvDsSRln3_GZVlUtMGJNKCNT_WdyAM_15BqGD5VUk8DHg6rMMjy-YU_89rpA0qQGtMdLPisaSJRPApsDc1fE6h0fFWED5NSHjQ5c2vZYUB2Os/s1600/Multiple1_thumb%5B1%5D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="133" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1pi64cvbH-oaPP2M9UOyP_z-xJ2Ubo5CvDsSRln3_GZVlUtMGJNKCNT_WdyAM_15BqGD5VUk8DHg6rMMjy-YU_89rpA0qQGtMdLPisaSJRPApsDc1fE6h0fFWED5NSHjQ5c2vZYUB2Os/s320/Multiple1_thumb%5B1%5D.png" width="320" /></a></div>
<div style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
<code style="color: #3366cc; margin: 0px; padding: 0px;"><span style="color: black; font-family: 'Trebuchet MS', sans-serif;"><br /></span></code></div>
<div style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; padding: 5px 10px;">
<code style="color: #3366cc; margin: 0px; padding: 0px;"><span style="color: black; font-family: 'Trebuchet MS', sans-serif;">So if you set both of the project action “</span><code style="margin: 0px; padding: 0px;">Start</code><span style="color: black; font-family: 'Trebuchet MS', sans-serif;">” and run the application both of this project will run. So you do not need to rework to start the different project again.</span></code></div>
</div>
Asheeriyam Inchttp://www.blogger.com/profile/04547469289790329772noreply@blogger.com0