tag:blogger.com,1999:blog-2223985324585753602024-03-14T11:12:42.518-07:00Inside SharePointSharePoint, Apps, Add-in, JQuery, ASP.Net, C#Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-222398532458575360.post-43382977623544645912015-09-12T20:46:00.001-07:002015-09-12T20:47:00.424-07:00Event Scheduler<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="margin-left: 40px;">
<img alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHaeFN8eX7UhgPydiPW5WDyNV8WiPAHiqvvPwtL7S56NhgbMjUomvuB04pYc7QLsrfApVSnHOONnSOLgcczVgBN975t2vicJRyES6lHqW0WHFan5Gk605Dor0bOkjDUmn9nxS_cY9oi5U/s1600/icon-appointments-white.png" style="float: left; height: 96px; margin-left: 15px; margin-right: 15px; width: 96px;" />Event Scheduler app, bridges the gap of registering for an event in your organization or client, based on Date and Time, Slots available with email confirmation.</div>
<div style="margin-left: 40px;">
Register for an event, for like a training/ medical camp based on the time slots designated by the Event coordinator.</div>
<div style="margin-left: 40px;">
<br /></div>
<div style="margin-left: 40px;">
<br /></div>
<div style="margin-left: 40px;">
Event coordinator can create an event with the info like:</div>
<div style="margin-left: 40px;">
<ul style="text-align: left;">
<li> Event Start and End Date Time</li>
<li> Slot Duration</li>
<li> Maximum number of appointments for a slot</li>
<li> Break Time and its duration</li>
<li> Mark it as all day event</li>
<li> Mark it as recurring event</li>
<li> Versioning</li>
</ul>
</div>
<div style="margin-left: 40px;">
Attendees can:</div>
<div style="margin-left: 40px;">
<ul style="text-align: left;">
<li> click on the event and register a slot from Ribbon or Context menu</li>
<li> choose from slots available for the selected date</li>
<li> Update or delete the registered slot</li>
<li> View his/her appointments in calendar and list view</li>
<li> Confirmation email on schedule/update/delete</li>
</ul>
</div>
<div style="margin-left: 40px;">
</div>
Please donate to come up with more apps and additional features<br />
<div style="text-align: right;">
<br /></div>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<div style="text-align: right;">
<input name="cmd" type="hidden" value="_s-xclick" /> <input name="encrypted" type="hidden" value="-----BEGIN PKCS7-----MIIHRwYJKoZIhvcNAQcEoIIHODCCBzQCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYAiDmd853ed2bx09wiLeoHWobEJQxcmdFgdKQ3Iqq0teDf54/DCuTaWwAFwpCfroBP0QafjPJeGHE5Nm0T8TWy7MlK8lUDMvz6E/wfSXORpnTwvDsN5bfM8COW9h6Zme6fB6N72tml30WvQgAy7CXM7Ggs/vo13Mhc5BxYfgcPLWDELMAkGBSsOAwIaBQAwgcQGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQIeCHPiMjEFx2AgaDTd7vcsNLePK5ZeXO97CsqsnyCFN3AHgWxIdOpMgqsZg3K2ZskWRVcY/sv1QsCrp2nQZPHEP8wwIBOXV0FddAJpAv6jSdQZNsKTsFSGZm+4rvWsGtlpRbwr6aisopoa0TApZuex1Hb9uB61D6H5ypKf/h303esqfiFsTd8P2Ekiefk33VZNFCuYUq5EQZRXDRAOZOH8uRnbYV3LjcelVDYoIIDhzCCA4MwggLsoAMCAQICAQAwDQYJKoZIhvcNAQEFBQAwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLUGF5UGFsIEluYy4xEzARBgNVBAsUCmxpdmVfY2VydHMxETAPBgNVBAMUCGxpdmVfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tMB4XDTA0MDIxMzEwMTMxNVoXDTM1MDIxMzEwMTMxNVowgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLUGF5UGFsIEluYy4xEzARBgNVBAsUCmxpdmVfY2VydHMxETAPBgNVBAMUCGxpdmVfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBR07d/ETMS1ycjtkpkvjXZe9k+6CieLuLsPumsJ7QC1odNz3sJiCbs2wC0nLE0uLGaEtXynIgRqIddYCHx88pb5HTXv4SZeuv0Rqq4+axW9PLAAATU8w04qqjaSXgbGLP3NmohqM6bV9kZZwZLR/klDaQGo1u9uDb9lr4Yn+rBQIDAQABo4HuMIHrMB0GA1UdDgQWBBSWn3y7xm8XvVk/UtcKG+wQ1mSUazCBuwYDVR0jBIGzMIGwgBSWn3y7xm8XvVk/UtcKG+wQ1mSUa6GBlKSBkTCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb22CAQAwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQCBXzpWmoBa5e9fo6ujionW1hUhPkOBakTr3YCDjbYfvJEiv/2P+IobhOGJr85+XHhN0v4gUkEDI8r2/rNk1m0GA8HKddvTjyGw/XqXa+LSTlDYkqI8OwR8GEYj4efEtcRpRYBxV8KxAW93YDWzFGvruKnnLbDAF6VR5w/cCMn5hzGCAZowggGWAgEBMIGUMIGOMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50YWluIFZpZXcxFDASBgNVBAoTC1BheVBhbCBJbmMuMRMwEQYDVQQLFApsaXZlX2NlcnRzMREwDwYDVQQDFAhsaXZlX2FwaTEcMBoGCSqGSIb3DQEJARYNcmVAcGF5cGFsLmNvbQIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTUwOTA5MDQyOTE4WjAjBgkqhkiG9w0BCQQxFgQUrQKiGZJeks85xpCoBWMVw4IyGP4wDQYJKoZIhvcNAQEBBQAEgYCJPy+buysYsFgQS2CXXTiUtV0VvH2dg3esuCvyMDZKCsd+Jkduz+Mk3C1ETVRaFoME7U2kcuOF4qCAafQ/uaqyoOJ2ocLPDE+0Vi+Mjw5Nzpxz03T78ia3NMAfTqnti5dyveqa5EVv1sS0WDXZL3B8G1V8YgE+8ZGgEs8g290RpQ==-----END PKCS7-----
" /> <input alt="PayPal - The safer, easier way to pay online!" border="0" name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" type="image" /> <img alt="" border="0" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" /></div>
</form>
</div>
Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com0tag:blogger.com,1999:blog-222398532458575360.post-25180159387651921782014-01-06T12:18:00.003-08:002014-01-06T12:20:25.981-08:00News Slider with multiple data sources for SharePoint (Content Query Webpart).<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Project Description</b><br />
<br />
News Slider is built for
SharePoint 2007, 2010, 2013 which covers the below technical specifications<br />
<b>Technical Specifications:</b><br />
<ul>
<li>Built for SharePoint 2007, 2010, 2013 </li>
<li>Fetch data from multiple libraries (ex: Document Libraries, Pages Libraries)
</li>
<li>jQuery based rendering </li>
<li>Enhanced/ Customized Content Query webpart </li>
<li>Responsive
<ul>
<li>Adapt to any screen </li>
</ul>
</li>
<li>Touch
<ul>
<li>Swipe support that tracks touch movements on supported devices
</li>
</ul>
</li>
<li>CSS3 transitions
<ul>
<li>Animations that run smoothly on modern devices </li>
</ul>
</li>
<li>Display only specified items </li>
<li>Display only published items </li>
<li>Display as per your sort order </li>
<li>Play/Pause </li>
<li>Next/Previous </li>
<li>Pause on Hover </li>
</ul>
<b>Dependancies:</b><br />
<ul>
<li>jQuery 1.7.1+ </li>
</ul>
<b>Download:</b><br />
<b><a href="https://sharepointnewsslider.codeplex.com/">https://sharepointnewsslider.codeplex.com/</a></b><br />
<br />
<b>instructions document is available under downloads tab </b><br />
<b> </b><br />
<b>Screenshots:</b><br />
<b><img alt="" src="http://download-codeplex.sec.s-msft.com/Download/SourceControlFileDownload.ashx?ProjectName=sharepointnewsslider&changeSetId=30845&itemId=657161" height="356" width="600" /></b><br />
<br />
Thanks to <a href="http://slidesjs.com/" target="_blank">SlidesJS</a> team for
developing a responsive and flexible Slider plugin based on jQuery. Please
donate for their hardwork</div>
Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com0tag:blogger.com,1999:blog-222398532458575360.post-2392804056325090412014-01-06T12:11:00.000-08:002014-01-06T12:11:06.131-08:00ItemUpdating event only when metadata/properties are changed<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDgMYTOSOnS27uQGFKY9MMXwcBdxQpqChFRbHd1yMeeW8NuAXaYvNtP94eAAI3KvHBE4JYjvoyp4dtcJLS5nOEmM-XFXBFMEPLLAizCr7PlUUlhLL4mOlA4wmBcg7tKRtmEYHl_0oY9Tfk/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;">1: if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null &amp;&amp; properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null)
2: {
3: //This is when the update event is triggered by check-in.
4: }
5: else{
6: //This is triggered by events other than check-in action.
7: if (Convert.ToInt32(properties.AfterProperties["vti_filesize"]) == 0)
8: {
9: }
10: }
</code></pre>Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com0tag:blogger.com,1999:blog-222398532458575360.post-57848519802062422002010-12-30T08:50:00.000-08:002010-12-30T09:45:44.070-08:00Redirect to a Page in custom Site Definition - SharePoint<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTEyIWNJwC9L8CpK9Xm5eRKSq7BYhsBRfkgIvIqsvZlGAfbMGL60LNZnNmFLHOf4dhAuyMJHkNmtfoRBligLAoNyfbixP6QrBGNHKcKVZKr2ELpXm9Fb5ibHuKheikS7n-SS2vPUXqww8/s1600/PublishingCollaborationSite.gif" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="89" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTEyIWNJwC9L8CpK9Xm5eRKSq7BYhsBRfkgIvIqsvZlGAfbMGL60LNZnNmFLHOf4dhAuyMJHkNmtfoRBligLAoNyfbixP6QrBGNHKcKVZKr2ELpXm9Fb5ibHuKheikS7n-SS2vPUXqww8/s200/PublishingCollaborationSite.gif" width="200" /></a></div>A Site Definition defines a unique type of Microsoft SharePoint Foundation Web site. There are several site definitions built into SharePoint Foundation. A site definition can include more than one site definition configuration. A SharePoint Foundation Web site is based on particular site definition configuration. For this reason, a site definition may be thought as a family of configurations, although some families contain only one configuration.<br />
<ul><li>Site Definitions are the foundations on which all sites and user templates are built. </li>
<li>Site Definitions are predefined components needs to be included when a site was created in SharePoint server. </li>
<li>Site Definition contains information of Web Part , Lists, Features and navigation bars to be included in the site.</li>
</ul><br />
The following are the four site definitions whose configurations can be used to create new Web sites.<br />
<ol><li>STS includes the site definition configurations for, Blank Site, Team Site, and Document Workspace. </li>
<li>MPS includes the site definition configurations for Basic Meeting Workspace, Blank Meeting Workspace, Decision Meeting Workspace, Social Meeting Workspace, and Multipage Meeting Workspace. </li>
<li>BLOG provides a site definition configuration for blogs. </li>
<li>SGS provides a site definition configuration for Group Work Site. </li>
</ol><br />
<strong><span style="color: #0b5394; font-size: large;">Requirement:</span></strong><br />
<br />
Redirecting to a custom page, for example like custom settings page, once a new site is created, using custom site definition. This functionality can be also used to have a delayed redirection to site home page, when we perform any site provisioning activities like updating/ modifying the properties of webparts, available on the home page, at runtime.<br />
<br />
<span style="color: #0b5394; font-size: large;"><strong>Solution:</strong></span><br />
<br />
Assuming that the reader has basic idea working with a custom Site Definition in SharePoint, I m explaining in the below solution. All the configuration we are going to make for achieving this functionality will be done in ONET.XML file only, for our custom site definition with the publishing template.<br />
<br />
So here in this solution I m using Publishing Site template, as publishing site has a Redirect page layout, which can be used to create a webpage in the pages library, when the template is being applied.<br />
<br />
<strong><span style="color: #3d85c6;">Step 1: Activating "RedirectPageContentTypeBinding" Feature in the WebFeatures section</span></strong><br />
<br />
This is a very important step, as on activating this feature, the Pages library is configured with Redirect Page Content Type. By default when the Pages library is created in Publishing site, Redirect page content type will not be available. So as to bind this content type "RedirectPageContentTypeBinding" has to be activated, which allows us to create a new page using Redirect Page Layout.<br />
<br />
<pre class="brush: xml;"></webfeatures>
<feature id="306936FD-9806-4478-80D1-7E397BFA6474">
</webfeatures>
</pre><strong><span style="color: #3d85c6;">Step 2: Creating a Redirect Page in the pages library</span></strong><br />
<br />
Here we are creating new pages in the Pages Library, using the content type based upon our requirement. <br />
<pre class="brush: xml;"><module name="HomePage" path="" url="$Resources:cmscore,List_Pages_UrlName;">
<file type="GhostableInLibrary" url="RedirectPage.aspx">
<property name="Title" value="$Resources:cmscore,PageLayout_RedirectPage_Title;"></property>
<property name="ContentType" value="#$Resources:cmscore,contenttype_redirectpage_name;"></property>
<property name="PublishingPageLayout" value="~SiteCollection/_catalogs/masterpage/RedirectPageLayout.aspx, Redirect Page"></property>
<property name="RedirectURL" value="~Site/Pages/Default.aspx, Home Page"></property>
</file>
<file type="GhostableInLibrary" url="Default.aspx">
<property name="Title" value="$Resources:spscore,HomeLandingPage_Title;"></property>
<property name="ContentType" value="$Resources:cmscore,contenttype_welcomepage_name;"></property>
<property name="PublishingPageLayout" value="~SiteCollection/_catalogs/masterpage/DefaultLayout.aspx, Welcome Page"></property>
</file>
</module>
</pre>Observe the RedirectURL property, we are explicitly providing the path of default welcome page in the new site going to be created. "~Site" fetches the absolute URL of the site being created, where as "~SiteCollection" fetches the absolute URL of the Site Collection, where the new site is being created.<br />
RedirectURL property can be changed based upon your requirement.<br />
<br />
<strong><span style="color: #cc0000;">Note:</span></strong> XML folder in your custom Site definition should have the pages above mentioned, along with ONET.XML<br />
Folder structure should be as below:<br />
<br />
SiteTemplates<br />
--- CustomSiteDefinitionName<br />
---XML<br />
---ONET.XML<br />
---Default.aspx<br />
---Redirectpage.aspx<br />
<br />
<div></div><strong><span style="background-color: #3d85c6;"><span style="background-color: white; color: #3d85c6;">Step 3: Specifying Redirect page to open once new site is successfully</span></span><span style="background-color: white; color: #3d85c6;"> created</span></strong><br />
<br />
Add the below tag in the Configuration Tag, which specifies, a particular page to be executed once the new site is created. Default behaviour without this tag is to open home page of the site.<br />
<pre class="brush: xml;"><executeurl url="$Resources:cmscore,List_Pages_UrlName;/RedirectPage.aspx">
</pre>Deploy the site definition & create a new site based upon the custom template.Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com1tag:blogger.com,1999:blog-222398532458575360.post-16839720115821801572010-11-11T14:35:00.000-08:002010-12-30T08:38:33.974-08:00PushPin to show or hide DIV and maintain state across pages and Users using JQuery<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkg7HtDnVEYOWV9IKPC2mwu2XprVUHGA9XZI_zaqb4bDfoxT9F2BKMf3ugA0ypNHY0TKFTNk2RVOR7CqDuCSFu9OtVmeHl-QEDc2fs8jzVowq91bNIk04Mo7SCkCmmnWZPaFU_Dp5m1BE/s1600/pushpin1.jpg" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" px="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkg7HtDnVEYOWV9IKPC2mwu2XprVUHGA9XZI_zaqb4bDfoxT9F2BKMf3ugA0ypNHY0TKFTNk2RVOR7CqDuCSFu9OtVmeHl-QEDc2fs8jzVowq91bNIk04Mo7SCkCmmnWZPaFU_Dp5m1BE/s1600/pushpin1.jpg" /></a></div>JQuery has very cool features, providing the wide range of plugins to play around with your webpage. Here in this post I m going to discuss regarding a requirement I had to make use of JQuery to maintain the state of a DIV across pages, as well as across Users logged into the application.<br />
<br />
<span style="color: #0b5394; font-family: inherit;"><strong>Requirement:</strong></span><br />
<br />
This requirement is to provide interface for searching certain content in the SharePoint List based upon the keywords. This search window/pane should have the capability of toggle, as well as the capability of fixing/pin down (stopping toggle i.e showing the DIV) which should be maintained across the pages in the application untill the user either closes the pane or unfix. Also, this provision should be available as per the User choice, logged in to the application.<br />
<br />
<strong><span style="color: #0b5394;">Example:</span></strong><br />
For better understanding we shall consider two user's named User1 & User2. When User1 loggs in to the application and prefers to pin down the DIV after showing DIV by toggle, that DIV should be in open state, in all the pages being traversed, untill preferred to pin up. But this preference should not reflect to User2, as this user might not prefer to search or looking into the DIV.<br />
<br />
<strong><span style="color: #0b5394;">Challenges:</span></strong><br />
<ol><li>Maintaining the Open/Close state across all pages based upon the preference to show/hide respectively.</li>
<li>Maintain the Open/Close state based upon the logged in User preference to show/hide respectively.</li>
</ol><br />
<strong><span style="color: #0b5394;">Solution:</span></strong><br />
<ol><li>Add Script References for <br />
<b>JQuery Plugin:</b><br />
<pre class="brush: javascript;"><script src="/jquery-1.4.2.min.js" type="text/javascript">
</script>
</pre><u>Download:</u> <a href="http://jquery.com/">http://jquery.com/</a><br />
<br />
<b>Sessions Plugin:</b><br />
<pre class="brush: javascript;"><script src="/jquery.namesession.js" type="text/javascript">
</script></pre><u>Download:</u> <a href="http://plugins.jquery.com/node/8213/release">http://plugins.jquery.com/node/8213/release</a><br />
<br />
<b>JSON Plugin:</b><br />
<pre class="brush: javascript;"><script src="/json2.js" type="text/javascript">
</script>
</pre><u>Download:</u> <a href="http://www.json.org/json2.js">http://www.json.org/json2.js</a></li>
<li>Create a DIV tag holding all your content as below:<br />
<pre class="brush: html;"><div id="SearchFund-dialog" style="display: none; width: 600px;" title="Search Fund"><fieldset style="border-bottom: #6593cf 2px solid; border-left: #6593cf 2px solid; border-right: #6593cf 2px solid; border-top: #6593cf 2px solid;"><legend></legend>
<div style="vertical-align: top;"><div style="float: left; width: 6%;"></div><div class="validateTips" style="float: left; width: 85%;"></div><div><div style="float: left; width: 4%;"><a href="http://draft.blogger.com/post-edit.g?blogID=222398532458575360&postID=1683972011582180157#" id="anchorPinPoint" role="button" style="-moz-user-select: none;" title="Keep Search Open" unselectable="on">
<span class="ui-icon ui-icon-pin-s" style="-moz-user-select: none; cursor: pointer;" unselectable="on">Keep Open</span>
</a></div><div style="float: left; width: 4%;"><a class="ui-dialog-titlebar-close ui-corner-all" href="http://draft.blogger.com/post-edit.g?blogID=222398532458575360&postID=1683972011582180157#" role="button" style="-moz-user-select: none;" title="Close" unselectable="on">
<span class="ui-icon ui-icon-closethick" style="-moz-user-select: none; cursor: pointer;" unselectable="on">close</span>
</a> </div></div></div><div>Your Content / Controls</div></fieldset></div></pre><b>Note:</b>Styles & images are from JQuery UI Smoothness theme.</li>
<li>Add the below script in the head tag<br />
<pre class="brush: javascript;">$(document).ready(function() {
$.namesession.set("LoggedInUser",$().SPServices.SPGetCurrentUser({fieldName: "UserName", debug: false}));
var SearchWindowStatus= ($.namesession.get('SearchWindowStatus_'+$.namesession.get('LoggedInUser',''), '')!= '')?$.namesession.get('SearchWindowStatus_'+$.namesession.get('LoggedInUser',''), '') :$.namesession.set('SearchWindowStatus_'+$.namesession.get('LoggedInUser',''),false);
if(SearchWindowStatus){
$('#SearchFund-dialog').show();
$("a[id$=anchorPinPoint]").children().removeClass('ui-icon-pin-w').addClass('ui-icon-pin-s').attr('title','Keep Search Closed');
}else{
$('#SearchFund-dialog').hide();
}
$(this).click(function() {
$('#SearchFund-dialog').toggle();
}):
$("a[id$=anchorPinPoint]").bind({
mouseover:function() {
$(this).addClass('ui-state-hover');
},
mouseout:function() {
$(this).removeClass('ui-state-hover');
},
focus:function() {
$(this).addClass('ui-state-focus');
},
blur:function() {
$(this).removeClass('ui-state-focus');
},
click:function() {
TogglePinPoint(this)
return false;
}
});
function TogglePinPoint(ctrl)
{
if($(ctrl).children().hasClass('ui-icon-pin-w'))
{
$(ctrl).children().removeClass('ui-icon-pin-w').addClass('ui-icon-pin-s').attr('title','Keep Search Closed');
$.namesession.set('SearchWindowStatus_'+$.namesession.get('LoggedInUser',''),true);
}else if($(ctrl).children().hasClass('ui-icon-pin-s'))
{
$(ctrl).children().removeClass('ui-icon-pin-s').addClass('ui-icon-pin-w').attr('title','Keep Search Open');
$.namesession.set('SearchWindowStatus_'+$.namesession.get('LoggedInUser',''),false);
}
}
});
</pre></li>
</ol><br />
<strong>Note:</strong> Ensure your web.config file is configured for AJAX & JSON<br />
Enable SessionState is set to true in the config filePranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com0tag:blogger.com,1999:blog-222398532458575360.post-10174421431469608242010-11-10T17:16:00.000-08:002010-11-11T11:17:49.737-08:00Folders in SharePoint Pages Library for Publishing Site<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/AVvXsEgDsDAeijvOU0pI1yi6aHNVhhbqOqZunF5aPo_ST7jUdCd0mnNittlBXUNwG_PSURgKqc6YnK6-5nzjpvRmsmZXLSoSCaaBMEbt3h7eFflWf-FLzw-I1BLNzCO-ctgJAS0yoMvra8AGJ2I/s1600/crtpage.gif" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDsDAeijvOU0pI1yi6aHNVhhbqOqZunF5aPo_ST7jUdCd0mnNittlBXUNwG_PSURgKqc6YnK6-5nzjpvRmsmZXLSoSCaaBMEbt3h7eFflWf-FLzw-I1BLNzCO-ctgJAS0yoMvra8AGJ2I/s1600/crtpage.gif" /></a></div>SharePoint Publishing site template has Pages Document Library, which is a repository for pages with a flexibility of creating pages based upon Page Layouts. Pages created in this library by default are configured with three content types Pages, Article Page & Welcome Page each having their own fields based upon necessity.<br />
<br />
Pages Library is flexible in creating pages with different layouts, based upon the design & requirement, but does not have a provision to create pages in folders & access them as per the sitemap/ breadcrumbs, as we create in a basic document library. We can go to advanced settings of the library & configure for showing "New Folder" under the New Menu, even though when we create a page under the folders, it is saved under root folder of the library which does not meet our purpose.<br />
<br />
So here in this post, I would like to share one of the solution I implemented in our project, which sufficed very well using Pages Library for creating pages in the folders.<br />
<br />
<span style="color: #0b5394; font-size: large;"><strong>Troubleshooting:</strong></span><br />
The process of troubleshooting started from creating a new page. In the publishing site when we try to create a new page either from menu option under "Site Actions" or from the "New Menu" in library, we are redirected to "CreatePage.aspx" available under layouts virtual directory. So this is the page where we can customize as per our requirement.<br />
<br />
<span style="color: #0b5394; font-size: large;"><strong>Steps to recreate:</strong></span><br />
<br />
<span style="color: #3d85c6;"><strong>Building Custom page for creating a page:</strong></span><br />
<ol><ol><li>Copy the "CreatePage.aspx" available in the layouts folder of SharePoint 12 hive & place it in the same directory or else in your custom directory and rename with a custom name as "CreatePage_Custom.aspx".</li>
<li>Open the CreatePage_Custom.aspx in designer or visual studio and search for the tag <pre class="brush: c-sharp;"><asp:label id="parentUrlLabel" runat="server"></asp:label></pre>Set the property "Visible=false" as this is the control which holds name of the Pages library.<br />
<b> Note:</b> Do not delete this tag, there is a reference in the code behind.</li>
<li>Add the below directive to have publishing assembly reference<br />
<pre class="brush: c-sharp;"><%@ Import Namespace="Microsoft.SharePoint.Publishing" %></pre></li>
<li>Microsoft.SharePoint.Publishing.Internal.CodeBehind.CreatePage is the class in the code behind, but the respective methods are not exposed. So the next option is inline coding in the page, where we use custom event of the submit button to have our functilnality to add the page in the Pages library.<br />
<pre class="brush: c-sharp;">protected void OnCustomSubmit(Object sender, EventArgs e)
{
string newPageUrl = "";
SPWeb web = SPContext.Current.Web;
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
PageLayout[] layouts = publishingWeb.GetAvailablePageLayouts();
int layoutItemId = Convert.ToInt32(pageTemplatePicker.SelectedValue);
PageLayout layout = FindLayoutById(layoutItemId,publishingWeb);
string pageName = urlNameTextBox.Text + ".aspx";
PublishingPage newPage = publishingWeb.GetPublishingPages().Add(Request.QueryString["RootFolder"].ToString() + "/" + pageName, layout);
newPageUrl = web.Url + "/" + newPage.Url; // Here you can append the Querystring if you want to show the created page in the Edit Mode.
newPage.Title = titleTextBox.Text;
newPage.Description = descriptionTextBox.Text;
newPage.Update();
Response.Redirect(newPageUrl);
}
protected PageLayout FindLayoutById(int layoutItemId,PublishingWeb localPublishingweb)
{
SPListItem itemById = localPublishingweb.Web.Site.RootWeb.GetCatalog(SPListTemplateType.MasterPageCatalog).Items.GetItemById(layoutItemId);
if (itemById == null)
{
return null;
}
return new PageLayout(itemById);
}</pre></li>
<li><br />
Refer the server click event to the custom event cretaed above.<br />
<pre class="brush: c-sharp;"><asp:button class="ms-ButtonHeightWidth" id="buttonCreatePage" onclick="OnCustomSubmit" runat="server" text="Create Page" type="submit"></asp:button> </pre></li>
<li>Creating a custom content type:<pre class="brush: xml;"><?xml version="1.0" encoding="utf-8" ?>
<elements xmlns="http://schemas.microsoft.com/sharepoint/">
<contenttype ID="0x010100d510f8b1b4b642d192cb3fb1f6fc7307"
Name="TPD Article Page"
Group="TPD Page Layout Content Types"
Description="Content Type for creating Publishing Article page in Pages/Document library"
Version="0">
<fieldrefs>
<fieldref ID="{3de94b06-4120-41a5-b907-88773e493458}" Name="PublishingPageImage"/>
<fieldref ID="{F55C4D88-1F2E-4ad9-AAA8-819AF4EE7EE8}" Name="PublishingPageContent"/>
<fieldref ID="{B3525EFE-59B5-4f0f-B1E4-6E26CB6EF6AA}" Name="SummaryLinks"/>
<fieldref ID="{D3429CC9-ADC4-439b-84A8-5679070F84CB}" Name="ArticleByLine"/>
<fieldref ID="{71316CEA-40A0-49f3-8659-F0CEFDBDBD4F}" Name="ArticleStartDate"/>
<fieldref ID="{66F500E9-7955-49ab-ABB1-663621727D10}" Name="PublishingImageCaption"/>
<fieldref ID="{a932ec3f-94c1-48b1-b6dc-41aaa6eb7e54}" Name="HeaderStyleDefinitions"/>
</FieldRefs>
<documenttemplate TargetName="/_layouts/Project/CreatePage_Custom.aspx" />
</ContentType>
</Elements></pre></li>
<li>Deploy content type to the web application Add this new custom content type to the Pages library from the library settings.<br />
</li>
<li>Allow library to display New Folder option in New Menu, for creating sub folders. <br />
</li>
<li>Create a page using the new content type available under New Menu.<br />
</li>
</ol></ol><br />
<b><i>Reference:<br />
</i></b>If there is a requirement to create a page from the menu item under Site Actions, please refer to this post.<br />
<a href="http://blogs.msdn.com/b/syedi/archive/2008/07/18/why-should-one-save-publishing-pages-in-pages-list-always-in-moss-bend-it.aspx">http://blogs.msdn.com/b/syedi/archive/2008/07/18/why-should-one-save-publishing-pages-in-pages-list-always-in-moss-bend-it.aspx</a>Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com1tag:blogger.com,1999:blog-222398532458575360.post-1011736600093497742010-07-03T19:11:00.000-07:002010-07-03T20:02:28.344-07:00SharePoint 2010 Virtual Machine for EvaluationVirtual Machine running Microsoft SharePoint Server 2010, OCS, Web Applications, FAST Search, Project Server, Project Pro Plus 2010, Visio, Project, SQL Server 2008 R2 and Exchange Server 2010 were published by Microsoft. This download contains a two Windows Server 2008 R2 Hyper-V Virtual Machine set for evaluating and demonstrating Office 2010, SharePoint 2010 and Project Server 2010 – including ECM and PerformancePoint Services<br />
<br />
Active directory has been preconfigured with over 200 “demo” users with metadata in an organizational structure. All of these user profiles have been imported and indexed for search within SharePoint Server 2010. <br />
<br />
SharePoint Server 2010 has been configured in a “Complete” farm using the default SQL Server 2008 R2 instance. A default site has been created using the Team Site template at http://intranet.contoso.com/ and a FAST Search Center at <a href="http://intranet.contoso.com/search/">http://intranet.contoso.com/search/</a><br />
<br />
Get it from: <a href="http://go.microsoft.com/?linkid=9728417">http://go.microsoft.com/?linkid=9728417</a><br />
<br />
Virtual machine “a” contains the following pre-configured software:<br />
<ol><li>Windows Server 2008 R2 Standard Evaluation Edition x64, running as an Active Directory Domain Controller for the “CONTOSO.COM” domain with DNS and WINS</li>
<li>Microsoft SQL Server 2008 R2 Enterprise Edition with Analysis, Notification, and Reporting Services</li>
<li>Microsoft Office Communication Server 2007 R2</li>
<li>Microsoft Visual Studio 2010</li>
<li>Microsoft SharePoint Server 2010 Enterprise Edition</li>
<li>Microsoft Office Web Applications</li>
<li>Microsoft FAST Search for SharePoint 2010</li>
<li>Microsoft Project Server 2010</li>
<li>Microsoft Office Professional Plus 2010</li>
<li>Microsoft Visio 2010</li>
<li>Microsoft Project 2010</li>
<li>Microsoft Office Communicator 2007 R2</li>
</ol>Virtual machine “b” contains the following pre-configured software:<br />
<ol><li>Windows Server 2008 R2 Standard Evaluation Edition x64, joined to the “CONTOSO.COM” domain</li>
<li>Microsoft Exchange Server 2010</li>
</ol>Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com0tag:blogger.com,1999:blog-222398532458575360.post-79487902647220735342010-07-03T19:05:00.000-07:002010-07-03T20:02:46.270-07:00SharePoint 2010 Virtual LabsWe know SharePoint 2010 is a very advanced product in terms of features, capabilities and infrastructure etc. In this scenarios setting up an environment for ourselves is a difficult process atleaset to evaluate the product.<br />
<br />
Eventhough now we can install SharePoint 2010 in Windows 7 & Server 2008 they need to be X-64 bit. Upgrading our machines accordingly might involve some investment. So now we have a Virtual labs provided by Microsoft to evaluate the features listed below.<br />
<br />
<br />
It's our turn to to explore and update to new technologies provided by SharePoint 2010. <br />
<br />
Test drive <a href="http://msdn.microsoft.com/en-us/cc707678.aspx">SharePoint 2010 in a Virtual lab</a>. Take part and see how Microsoft Office SharePoint Server supports all intranet, extranet, and Web applications across an enterprise within one integrated platform. <br />
<br />
<div></div>Virtual labs cover the following:<br />
<ul><li>MSDN Virtual Lab: Client Object Model</li>
<li>MSDN Virtual Lab: Customizing MySites</li>
<li>MSDN Virtual Lab: Designing Lists and Schemas </li>
<li>MSDN Virtual Lab: Developing a BCS External Content Type with Visual Studio 2010 </li>
<li>MSDN Virtual Lab: Developing a Sandboxed Solution with Web Parts </li>
<li>MSDN Virtual Lab: Developing a Visual Web Part in Visual Studio 2010 </li>
<li>MSDN Virtual Lab: Developing Business Intelligence Applications </li>
<li>MSDN Virtual Lab: Enterprise Content Management </li>
<li>MSDN Virtual Lab: Getting Started with SharePoint 2010 </li>
<li>MSDN Virtual Lab: LINQ to SharePoint 2010 </li>
<li>MSDN Virtual Lab: SharePoint 2010 User Interface Advancements </li>
<li>MSDN Virtual Lab: Visual Studio SharePoint Tools </li>
<li>MSDN Virtual Lab: WorkflowMSDN Virtual Lab: Workflow</li>
</ul>Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com1tag:blogger.com,1999:blog-222398532458575360.post-14351754599776794952010-04-07T13:26:00.000-07:002010-04-16T17:04:12.134-07:00Handling ClientID issues in SharePoint Webparts & jQuery<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaQI0LMudBKFMCvnHgXhA6Mq8adBZILQV0gE-naR2tDEmH36PCUGvDcZj1LXdzB59Q0KZbyJ_xuh0ipRhGJjt5_AJoaQeh5wHv_Ty6RQQ8wRSjAWxcw12WKk1mgutVa3CtwyT6JCB8y-s/s1600-h/JQuery.jpg" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" nt="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaQI0LMudBKFMCvnHgXhA6Mq8adBZILQV0gE-naR2tDEmH36PCUGvDcZj1LXdzB59Q0KZbyJ_xuh0ipRhGJjt5_AJoaQeh5wHv_Ty6RQQ8wRSjAWxcw12WKk1mgutVa3CtwyT6JCB8y-s/s1600/JQuery.jpg" /></a></div>In ASP.NET/SharePoint a Control has a fully qualified ID that can be deduced from the control hierarchy and can be accessed with the properties ClientID or UniqueID. It then becomes the unique id or name of rendered html controls. It makes sense that these properties should be used right after the control hierarchy is completely defined, that means before the rendering, therefore in the PreRender.<br />
<br />
What is not so well known is that accessing those two properties sets the _cachedUniqueID member, which sets irrevocably the ID to a control. That's why using these properties in ItemCreated events, for example, makes the html id of controls to remain the default defined one.<br />
<br />
<strong>Example:</strong> In a DataList, you have an item template that contains a control, let's call it Control1. The rendered id in html will look like this: <strong>ctl00_m_g_aaf13d41_fc78_40be_81d5_2f40e534844f_txtName</strong>, but if you use ClientID inside the DataList_ItemCreated event, the rendered html id will be just Control1, thus making any javascript manipulation futile.<br />
<br />
Of course, one could create a method to return the UniqueID without setting the cached value, since there are moments when the partial hierarchy is enough to define a proper id. Unfortunately, for controls without a specific and declared id, ASP.NET creates and automatic ID like ctl[number] or _ctl[number] and, of course, those methods and fields are all private or internal. One could use Reflection to get to them, but what would be the point?<br />
<br />
UniqueID and ClientID are overridable, though, so one can change their behaviour in user defined controls.<br />
<br />
<span style="color: #0b5394; font-size: large;">Solution for handling in jQuery, Javascript & SharePoint Webparts (C#).</span><br />
<br />
jQuery is fantastic! It makes client-side development faster and countless plug-ins are available for just about every need. Using jQuery with Asp.NET Web-Forms gets aggravating when dealing with nested server controls. ClientID’s get appended when using ASP.NET Master Pages. Objects in JavaScript tend to look like this:<br />
<pre class="brush: c-sharp;">ctl00_m_g_aaf13d41_fc78_40be_81d5_2f40e534844f_txtName
</pre>The difficulty of the issue above is that, in order to get the element txtName, It’s necessary to know the full “path”. It’s quite aggravating to refer to get the object using the method below:<br />
<pre class="brush: javascript;">document.getElementByID('ctl00_m_g_aaf13d41_fc78_40be_81d5_2f40e534844f_txtName');
</pre>This becomes a big problem when developing server controls or web parts that may be used in a typical ASP.NET application or SharePoint. You cannot hard-code the path above if you don’t know the full path of the control.<br />
<br />
Fortunately, there are a few ways to get around this. There are three, in particular, I will mention. The first is the jQuery equivalent to the standard JavaScript method:<br />
<pre class="brush: javascript;">document.getElementById("<%=txtName.ClinetID%>");");
</pre>This can be done in jQuery by using:<br />
<pre class="brush: javascript;">$("#'<%=txtName.ClinetID%>");");
</pre>The second jQuery method does not require server tags. This method searches through all tags and looks for an element ending with the specified text. The jQuery code for this method is shown below:<br />
<pre class="brush: javascript;">$("[id$='_txtName']");
</pre>There are, of course, drawbacks to both methods above. The first is fast, but requires server tags. It’s fast, but it just looks messy. Also, it will not work with external script files. The second alternative is clean, but it can be slow. As I said earlier, there are several other alternatives, but these two are the ones I find myself using the most.<br />
<br />
The third registering Javascript in C# code behind.<br />
<pre class="brush: c-sharp;">Page.ClientScript.RegisterStartupScript(GetType(), "saveScript",
String.Format("function EnableSave( isDisabled )"+
"{{ var saveButton = document.getElementById(\"{0}\");"+
"saveButton.disabled=isDisabled;}}", btnSave.ClientID), true);
</pre><br />
Do not forget to call this script after controls have been loaded, I mean after Controls.Add(); in CreateChildControls method while developing webparts.Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com0tag:blogger.com,1999:blog-222398532458575360.post-53439631932898319282009-10-26T23:30:00.000-07:002010-04-03T19:06:01.988-07:00New features in C# 4.0 - Variance<div class="separator" style="clear: both; text-align: center;"><a href="http://www.blogger.com/" imageanchor="1" rel="prettysociable" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXwqmOX16iC1CFUEL8Zv5CzFlo5KmS08uyvNePg4fq58atVH7BBZ87y7IJdtVpfp-hmUJAQj7ukV2FP52_2cKJjD-D6ufON3fDYQHjFZxWvIHzxGtDgsMPoWqWqp3aKcWo0Rhn7dYRP0o/s1600/C%23.jpg" /></a></div><br />
An aspect of generics that often comes across as surprising is that the following is illegal:<br />
<br />
<br />
<pre class="brush: c-sharp;">IList<string> strings = new List<string>();
IList<object> objects = strings;</string></string></pre><br />
The second assignment is disallowed because strings does not have the same element type as objects. There is a perfectly good reason for this. If it were allowed you could write:<br />
<pre class="brush: c-sharp;">objects[0] = 5;
string s = strings[0];</pre><br />
Allowing an int to be inserted into a list of strings and subsequently extracted as a string. This would be a breach of type safety.<br />
However, there are certain interfaces where the above cannot occur, notably where there is no way to insert an object into the collection. Such an interface is IEnumerable<T><t>. If instead you say:</t><br />
<pre class="brush: c-sharp;">IEnumerable<object></pre><br />
There is no way we can put the wrong kind of thing into strings through objects, because objects doesn’t have a method that takes an element in. Variance is about allowing assignments such as this in cases where it is safe. The result is that a lot of situations that were previously surprising now just work.<br />
<br />
<span style="color: #0b5394; font-size: large;"><b>Covariance</b></span><br />
<br />
In .NET 4.0 the IEnumerable<T><br />
<t>interface will be declared in the following way:<br />
</t><br />
<pre class="brush: c-sharp;">public interface IEnumerable<out t=""> : IEnumerable
{
IEnumerator<t> GetEnumerator();
}
public interface IEnumerator<out t=""> : IEnumerator
{
bool MoveNext();
T Current { get; }
}</out></t></out></pre><br />
The “out” in these declarations signifies that the T can only occur in output position in the interface – the compiler will complain otherwise. In return for this restriction, the interface becomes “covariant” in T, which means that an IEnumerable<A> is considered an IEnumerable<B><br />
<br />
if A has a reference conversion to B.<br />
<br />
As a result, any sequence of strings is also e.g. a sequence of objects.<br />
<br />
This is useful e.g. in many LINQ methods. Using the declarations above:<br />
<pre class="brush: c-sharp;"><b>
var result = strings.Union(objects); // succeeds with an IEnumerable<object> </object></b></pre><br />
This would previously have been disallowed, and you would have had to to some cumbersome wrapping to get the two sequences to have the same element type.<br />
<b><br />
<span style="color: #0b5394; font-size: large;"><b>Contravariance</b></span></b><br />
Type parameters can also have an “in” modifier, restricting them to occur only in input positions. An example is IComparer<t>:</t> <br />
<pre class="brush: c-sharp;"><b>
public interface IComparer<in t="">
{
public int Compare(T left, T right);
}</in></b></pre><b><br />
</b>The somewhat baffling result is that an IComparer<b><object> can in fact be considered an IComparer<string>! It makes sense when you think about it: If a comparer can compare any two objects, it can certainly also compare two strings. This property is referred to as contravariance. A generic type can have both in and out modifiers on its type parameters, as is the case with the Func<…> delegate types: public delegate TResult Func<in out="" targ,="" tresult="">(TArg arg); </in> Obviously the argument only ever comes in, and the result only ever comes out. Therefore a Func<object,string> can in fact be used as a Func<string,object>. <span style="color: #0b5394; font-size: large;"><b>Limitations</b></span> Variant type parameters can only be declared on interfaces and delegate types, due to a restriction in the CLR. Variance only applies when there is a reference conversion between the type arguments. For instance, an IEnumerable<int> is not an IEnumerable<object> because the conversion from int to object is a boxing conversion, not a reference conversion. </object></int></string,object></object,string> Also please note that the CTP does not contain the new versions of the .NET types mentioned above. In order to experiment with variance you have to declare your own variant interfaces and delegate types. <span style="color: #0b5394; font-size: large;"><b>COM Example</b></span> Here is a larger Office automation example that shows many of the new C# features in action. <pre class="brush: c-sharp;">using System;
using System.Diagnostics;
using System.Linq;
using Excel = Microsoft.Office.Interop.Excel;
using Word = Microsoft.Office.Interop.Word;
class Program
{
static void Main(string[] args) {
var excel = new Excel.Application();
excel.Visible = true;
excel.Workbooks.Add(); // optional arguments omitted
excel.Cells[1, 1].Value = "Process Name"; // no casts; Value dynamically
excel.Cells[1, 2].Value = "Memory Usage"; // accessed
var processes = Process.GetProcesses()
.OrderByDescending(p => p.WorkingSet)
.Take(10);
int i = 2;
foreach (var p in processes) {
excel.Cells[i, 1].Value = p.ProcessName; // no casts
excel.Cells[i, 2].Value = p.WorkingSet; // no casts
i++;
}
Excel.Range range = excel.Cells[1, 1]; // no casts
Excel.Chart chart = excel.ActiveWorkbook.Charts.
Add(After: excel.ActiveSheet); // named and optional arguments
chart.ChartWizard(
Source: range.CurrentRegion,
Title: "Memory Usage in " + Environment.MachineName); //named+optional
chart.ChartStyle = 45;
chart.CopyPicture(Excel.XlPictureAppearance.xlScreen,
Excel.XlCopyPictureFormat.xlBitmap,
Excel.XlPictureAppearance.xlScreen);
var word = new Word.Application();
word.Visible = true;
word.Documents.Add(); // optional arguments
word.Selection.Paste();
}
}</pre>The code is much more terse and readable than the C# 3.0 counterpart. Note especially how the Value property is accessed dynamically. This is actually an indexed property, i.e. a property that takes an argument; something which C# does not understand. However the argument is optional. Since the access is dynamic, it goes through the runtime COM binder which knows to substitute the default value and call the indexed property. Thus, dynamic COM allows you to avoid accesses to the puzzling Value2 property of Excel ranges. </string></object></b>Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com0tag:blogger.com,1999:blog-222398532458575360.post-66055464945653002842009-10-26T23:24:00.000-07:002010-02-28T23:01:30.217-08:00New features in C# 4.0 - Features for COM interop<div class="separator" style="clear: both; text-align: center;"><a href="" imageanchor="1" rel="prettysociable" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXwqmOX16iC1CFUEL8Zv5CzFlo5KmS08uyvNePg4fq58atVH7BBZ87y7IJdtVpfp-hmUJAQj7ukV2FP52_2cKJjD-D6ufON3fDYQHjFZxWvIHzxGtDgsMPoWqWqp3aKcWo0Rhn7dYRP0o/s1600/C%23.jpg" /></a></div>Dynamic lookup as well as named and optional parameters greatly improve the experience of interoperating with COM APIs such as the Office Automation APIs. In order to remove even more of the speed bumps, a couple of small COM-specific features are also added to C# 4.0. <br />
<br />
<b><span style="color: #0b5394; font-size: large;">Dynamic import</span></b><br />
<br />
Many COM methods accept and return variant types, which are represented in the PIAs as object. In the vast majority of cases, a programmer calling these methods already knows the static type of a returned object from context, but explicitly has to perform a cast on the returned value to make use of that knowledge. These casts are so common that they constitute a major nuisance.<br />
<br />
In order to facilitate a smoother experience, you can now choose to import these COM APIs in such a way that variants are instead represented using the type dynamic. In other words, from your point of view, COM signatures now have occurrences of dynamic instead of object in them.<br />
<br />
This means that you can easily access members directly off a returned object, or you can assign it to a strongly typed local variable without having to cast. To illustrate, you can now say<br />
<br />
excel.Cells[1, 1].Value = "Hello";<br />
instead of <br />
((Excel.Range)excel.Cells[1, 1]).Value2 = "Hello";<br />
and<br />
Excel.Range range = excel.Cells[1, 1];<br />
instead of<br />
Excel.Range range = (Excel.Range)excel.Cells[1, 1];<br />
<br />
<b><span style="color: #0b5394; font-size: large;">Compiling without PIAs</span></b><br />
<br />
Primary Interop Assemblies are large .NET assemblies generated from COM interfaces to facilitate strongly typed interoperability. They provide great support at design time, where your experience of the interop is as good as if the types where really defined in .NET. However, at runtime these large assemblies can easily bloat your program, and also cause versioning issues because they are distributed independently of your application.<br />
<br />
The no-PIA feature allows you to continue to use PIAs at design time without having them around at runtime. Instead, the C# compiler will bake the small part of the PIA that a program actually uses directly into its assembly. At runtime the PIA does not have to be loaded.<br />
<br />
<span style="color: #0b5394; font-size: large;"><b>Omitting ref</b></span><br />
<br />
Because of a different programming model, many COM APIs contain a lot of reference parameters. Contrary to refs in C#, these are typically not meant to mutate a passed-in argument for the subsequent benefit of the caller, but are simply another way of passing value parameters.<br />
<br />
It therefore seems unreasonable that a C# programmer should have to create temporary variables for all such ref parameters and pass these by reference. Instead, specifically for COM methods, the C# compiler will allow you to pass arguments by value to such a method, and will automatically generate temporary variables to hold the passed-in values, subsequently discarding these when the call returns. In this way the caller sees value semantics, and will not experience any side effects, but the called method still gets a reference.<br />
<br />
<b><span style="color: #0b5394; font-size: large;">Open issues</span></b><br />
<br />
A few COM interface features still are not surfaced in C#. Most notably these include indexed properties and default properties. As mentioned above these will be respected if you access COM dynamically, but statically typed C# code will still not recognize them.<br />
<br />
There are currently no plans to address these remaining speed bumps in C# 4.0.Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com0tag:blogger.com,1999:blog-222398532458575360.post-63815854821191319892009-10-26T23:12:00.000-07:002010-04-16T17:06:07.409-07:00New features in C# 4.0 - Named and Optional Arguments<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXwqmOX16iC1CFUEL8Zv5CzFlo5KmS08uyvNePg4fq58atVH7BBZ87y7IJdtVpfp-hmUJAQj7ukV2FP52_2cKJjD-D6ufON3fDYQHjFZxWvIHzxGtDgsMPoWqWqp3aKcWo0Rhn7dYRP0o/s1600-h/C%23.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXwqmOX16iC1CFUEL8Zv5CzFlo5KmS08uyvNePg4fq58atVH7BBZ87y7IJdtVpfp-hmUJAQj7ukV2FP52_2cKJjD-D6ufON3fDYQHjFZxWvIHzxGtDgsMPoWqWqp3aKcWo0Rhn7dYRP0o/s1600/C%23.jpg" /></a></div>Named and optional parameters are really two distinct features, but are often useful together. Optional parameters allow you to omit arguments to member invocations, whereas named arguments is a way to provide an argument using the name of the corresponding parameter instead of relying on its position in the parameter list.<br />
<br />
Some APIs, most notably COM interfaces such as the Office automation APIs, are written specifically with named and optional parameters in mind. Up until now it has been very painful to call into these APIs from C#, with sometimes as many as thirty arguments having to be explicitly passed, most of which have reasonable default values and could be omitted.<br />
<br />
Even in APIs for .NET however you sometimes find yourself compelled to write many overloads of a method with different combinations of parameters, in order to provide maximum usability to the callers. Optional parameters are a useful alternative for these situations.<br />
<br />
<b><span style="color: #0b5394; font-size: large;">Optional parameters</span></b><br />
<br />
A parameter is declared optional simply by providing a default value for it:<br />
<pre class="brush: c-sharp;">public void M(int x, int y = 5, int z = 7);
Here y and z are optional parameters and can be omitted in calls:
M(1, 2, 3); // ordinary call of M
M(1, 2); // omitting z – equivalent to M(1, 2, 7)
M(1); // omitting both y and z – equivalent to M(1, 5, 7)</pre><div style="color: #0b5394;"><br />
</div><div style="color: #0b5394;"> <b><span style="font-size: large;">Named and optional arguments</span></b></div><br />
C# 4.0 does not permit you to omit arguments between commas as in M(1,,3). This could lead to highly unreadable comma-counting code. Instead any argument can be passed by name. Thus if you want to omit only y from a call of M you can write:<br />
<pre class="brush: c-sharp;">M(1, z: 3); // passing z by name
or
M(x: 1, z: 3); // passing both x and z by name
or even
M(z: 3, x: 1); // reversing the order of arguments</pre><br />
All forms are equivalent, except that arguments are always evaluated in the order they appear, so in the last example the 3 is evaluated before the 1.<br />
<br />
Optional and named arguments can be used not only with methods but also with indexers and constructors.<br />
<br />
<div style="color: #0b5394;"><b><span style="font-size: large;">Overload resolution</span></b></div><br />
Named and optional arguments affect overload resolution, but the changes are relatively simple:<br />
A signature is applicable if all its parameters are either optional or have exactly one corresponding argument (by name or position) in the call which is convertible to the parameter type.<br />
Betterness rules on conversions are only applied for arguments that are explicitly given – omitted optional arguments are ignored for betterness purposes.<br />
<br />
If two signatures are equally good, one that does not omit optional parameters is preferred.<br />
<pre class="brush: c-sharp;">M(string s, int i = 1);
M(object o);
M(int i, string s = “Hello”);
M(int i);
M(5);</pre><br />
Given these overloads, we can see the working of the rules above.M(string,int) is not applicable because 5 doesn’t convert to string. <br />
M(int,string) is applicable because its second parameter is optional, and so, obviously are M(object) and M(int).<br />
<br />
M(int,string) and M(int) are both better than M(object) because the conversion from 5 to int is better than the conversion from 5 to object.<br />
<br />
Finally M(int) is better than M(int,string) because no optional arguments are omitted.<br />
Thus the method that gets called is M(int).Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com0tag:blogger.com,1999:blog-222398532458575360.post-85381947190708097442009-10-26T22:28:00.000-07:002010-02-28T23:02:06.277-08:00New features in C# 4.0 - Dynamic Lookup<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXwqmOX16iC1CFUEL8Zv5CzFlo5KmS08uyvNePg4fq58atVH7BBZ87y7IJdtVpfp-hmUJAQj7ukV2FP52_2cKJjD-D6ufON3fDYQHjFZxWvIHzxGtDgsMPoWqWqp3aKcWo0Rhn7dYRP0o/s1600-h/C%23.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXwqmOX16iC1CFUEL8Zv5CzFlo5KmS08uyvNePg4fq58atVH7BBZ87y7IJdtVpfp-hmUJAQj7ukV2FP52_2cKJjD-D6ufON3fDYQHjFZxWvIHzxGtDgsMPoWqWqp3aKcWo0Rhn7dYRP0o/s1600/C%23.jpg" /></a></div>Dynamic lookup allows you a unified approach to invoking things dynamically. With dynamic lookup, when you have an object in your hand you do not need to worry about whether it comes from COM, IronPython, the HTML DOM or reflection; you just apply operations to it and leave it to the runtime to figure out what exactly those operations mean for that particular object.<br />
<br />
This affords you enormous flexibility, and can greatly simplify your code, but it does come with a significant drawback: Static typing is not maintained for these operations. A dynamic object is assumed at compile time to support any operation, and only at runtime will you get an error if it wasn’t so. Oftentimes this will be no loss, because the object wouldn’t have a static type anyway, in other cases it is a tradeoff between brevity and safety. In order to facilitate this tradeoff, it is a design goal of C# to allow you to opt in or opt out of dynamic behavior on every single call.<br />
<br />
<b style="color: #0b5394;"><span style="font-size: large;">The dynamic type</span></b><br />
<br />
C# 4.0 introduces a new static type called dynamic. When you have an object of type dynamic you can “do things to it” that are resolved only at runtime:<br />
<pre class="brush: c-sharp;">
dynamic d = GetDynamicObject(…);
d.M(7);
</pre>The C# compiler allows you to call a method with any name and any arguments on d because it is of type dynamic. At runtime the actual object that d refers to will be examined to determine what it means to “call M with an int” on it.<br />
<br />
The type dynamic can be thought of as a special version of the type object, which signals that the object can be used dynamically. It is easy to opt in or out of dynamic behavior: any object can be implicitly converted to dynamic, “suspending belief” until runtime. Conversely, there is an “assignment conversion” from dynamic to any other type, which allows implicit conversion in assignment-like constructs:<br />
<br />
<pre class="brush: c-sharp;">dynamic d = 7; // implicit conversion
int i = d; // assignment conversion
</pre><br />
<span style="font-size: large;"><b style="color: #0b5394;">Dynamic operations</b></span><br />
<br />
Not only method calls, but also field and property accesses, indexer and operator calls and even delegate invocations can be dispatched dynamically:<br />
<pre class="brush: c-sharp;">
dynamic d = GetDynamicObject(…);
d.M(7); // calling methods
d.f = d.P; // getting and settings fields and properties
d[“one”] = d[“two”]; // getting and setting thorugh indexers
int i = d + 3; // calling operators
string s = d(5,7); // invoking as a delegate
</pre><br />
The role of the C# compiler here is simply to package up the necessary information about “what is being done to d”, so that the runtime can pick it up and determine what the exact meaning of it is given an actual object d. Think of it as deferring part of the compiler’s job to runtime.<br />
<br />
The result of any dynamic operation is itself of type dynamic.<br />
<br />
<span style="font-size: large;"><b style="color: #0b5394;">Runtime lookup</b></span><br />
<br />
At runtime a dynamic operation is dispatched according to the nature of its target object d:<br />
COM objects<br />
If d is a COM object, the operation is dispatched dynamically through COM IDispatch. This allows calling to COM types that don’t have a Primary Interop Assembly (PIA), and relying on COM features that don’t have a counterpart in C#, such as indexed properties and default properties.<br />
<br />
<b style="color: #6fa8dc;">Dynamic objects</b><br />
<br />
If d implements the interface IDynamicObject d itself is asked to perform the operation. Thus by implementing IDynamicObject a type can completely redefine the meaning of dynamic operations. This is used intensively by dynamic languages such as IronPython and IronRuby to implement their own dynamic object models. It will also be used by APIs, e.g. by the HTML DOM to allow direct access to the object’s properties using property syntax.<br />
<br />
<b style="color: #6fa8dc;">Plain objects</b><br />
<br />
Otherwise d is a standard .NET object, and the operation will be dispatched using reflection on its type and a C# “runtime binder” which implements C#’s lookup and overload resolution semantics at runtime. This is essentially a part of the C# compiler running as a runtime component to “finish the work” on dynamic operations that was deferred by the static compiler.<br />
<br />
<span style="font-size: large;"><b style="color: #0b5394;">Example</b></span><br />
<br />
<pre class="brush: c-sharp;">Assume the following code:
dynamic d1 = new Foo();
dynamic d2 = new Bar();
string s;
d1.M(s, d2, 3, null);
</pre><br />
Because the receiver of the call to M is dynamic, the C# compiler does not try to resolve the meaning of the call. Instead it stashes away information for the runtime about the call. This information (often referred to as the “payload”) is essentially equivalent to:<br />
<br />
“Perform an instance method call of M with the following arguments:<br />
1. a string <br />
2. a dynamic <br />
3. a literal int 3<br />
4. a literal object null”<br />
<br />
At runtime, assume that the actual type Foo of d1 is not a COM type and does not implement<br />
IDynamicObject. In this case the C# runtime binder picks up to finish the overload resolution job based on runtime type information, proceeding as follows:<br />
1. Reflection is used to obtain the actual runtime types of the two objects, d1 and d2, that did not have a static type (or rather had the static type dynamic). The result is Foo for d1 and Bar for d2.<br />
2. Method lookup and overload resolution is performed on the type Foo with the call M(string,Bar,3,null) using ordinary C# semantics.<br />
3. If the method is found it is invoked; otherwise a runtime exception is thrown.<br />
<br />
<span style="font-size: large;"><b style="color: #0b5394;">Overload resolution with dynamic arguments</b></span><br />
<br />
Even if the receiver of a method call is of a static type, overload resolution can still happen at runtime. This can happen if one or more of the arguments have the type dynamic:<br />
<br />
<pre class="brush: c-sharp;">Foo foo = new Foo();
dynamic d = new Bar();
var result = foo.M(d);
</pre><br />
The C# runtime binder will choose between the statically known overloads of M on Foo, based on the runtime type of d, namely Bar. The result is again of type dynamic.<br />
<br />
<span style="font-size: large;"><b style="color: #0b5394;">The Dynamic Language Runtime</b></span><br />
<br />
An important component in the underlying implementation of dynamic lookup is the Dynamic Language Runtime (DLR), which is a new API in .NET 4.0.<br />
<br />
The DLR provides most of the infrastructure behind not only C# dynamic lookup but also the implementation of several dynamic programming languages on .NET, such as IronPython and IronRuby. Through this common infrastructure a high degree of interoperability is ensured, but just as importantly the DLR provides excellent caching mechanisms which serve to greatly enhance the efficiency of runtime dispatch.<br />
<br />
To the user of dynamic lookup in C#, the DLR is invisible except for the improved efficiency. However, if you want to implement your own dynamically dispatched objects, the IDynamicObject interface allows you to interoperate with the DLR and plug in your own behavior. This is a rather advanced task, which requires you to understand a good deal more about the inner workings of the DLR. For API writers, however, it can definitely be worth the trouble in order to vastly improve the usability of e.g. a library representing an inherently dynamic domain.<br />
<br />
<span style="font-size: large;"><b style="color: #0b5394;">Open issues</b></span><br />
<br />
There are a few limitations and things that might work differently than you would expect.<br />
• The DLR allows objects to be created from objects that represent classes. However, the current implementation of C# doesn’t have syntax to support this.<br />
• Dynamic lookup will not be able to find extension methods. Whether extension methods apply or not depends on the static context of the call (i.e. which using clauses occur), and this context information is not currently kept as part of the payload.<br />
• Anonymous functions (i.e. lambda expressions) cannot appear as arguments to a dynamic method call.The compiler cannot bind (i.e. “understand”) an anonymous function without knowing what type it is converted to.<br />
<br />
One consequence of these limitations is that you cannot easily use LINQ queries over dynamic objects:<br />
<br />
<pre class="brush: c-sharp;">dynamic collection = …;
var result = collection.Select(e => e + 5);
</pre><br />
If the Select method is an extension method, dynamic lookup will not find it. Even if it is an instance method, the above does not compile, because a lambda expression cannot be passed as an argument to a dynamic operation.<br />
There are no plans to address these limitations in C# 4.0.<br />
<br />
<span style="font-size: large;"><b style="color: #0b5394;">Named and Optional Arguments</b></span><br />
<br />
Named and optional parameters are really two distinct features, but are often useful together. Optional parameters allow you to omit arguments to member invocations, whereas named arguments is a way to provide an argument using the name of the corresponding parameter instead of relying on its position in the parameter list.<br />
<br />
Some APIs, most notably COM interfaces such as the Office automation APIs, are written specifically with named and optional parameters in mind. Up until now it has been very painful to call into these APIs from C#, with sometimes as many as thirty arguments having to be explicitly passed, most of which have reasonable default values and could be omitted.<br />
<br />
Even in APIs for .NET however you sometimes find yourself compelled to write many overloads of a method with different combinations of parameters, in order to provide maximum usability to the callers. Optional parameters are a useful alternative for these situations.<br />
<br />
<span style="color: #6fa8dc; font-size: small;"><b>Optional parameters</b></span><br />
A parameter is declared optional simply by providing a default value for it:<br />
<pre class="brush: c-sharp;">
public void M(int x, int y = 5, int z = 7);
Here y and z are optional parameters and can be omitted in calls:
M(1, 2, 3); // ordinary call of M
M(1, 2); // omitting z – equivalent to M(1, 2, 7)
M(1); // omitting both y and z – equivalent to M(1, 5, 7)
</pre>Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com0tag:blogger.com,1999:blog-222398532458575360.post-48781111019652904842009-10-26T13:27:00.000-07:002010-04-16T17:06:24.544-07:00New features in C# 4.0<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXwqmOX16iC1CFUEL8Zv5CzFlo5KmS08uyvNePg4fq58atVH7BBZ87y7IJdtVpfp-hmUJAQj7ukV2FP52_2cKJjD-D6ufON3fDYQHjFZxWvIHzxGtDgsMPoWqWqp3aKcWo0Rhn7dYRP0o/s1600-h/C%23.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXwqmOX16iC1CFUEL8Zv5CzFlo5KmS08uyvNePg4fq58atVH7BBZ87y7IJdtVpfp-hmUJAQj7ukV2FP52_2cKJjD-D6ufON3fDYQHjFZxWvIHzxGtDgsMPoWqWqp3aKcWo0Rhn7dYRP0o/s1600/C%23.jpg" /></a></div>The major theme for C# 4.0 is dynamic programming. Increasingly, objects are “dynamic” in the sense that their structure and behavior is not captured by a static type, or at least not one that the compiler knows about when compiling your program.<br />
<br />
<br />
<br />
Some examples include<br />
a. objects from dynamic programming languages, such as Python or Ruby<br />
b. COM objects accessed through IDispatch<br />
c. ordinary .NET types accessed through reflection<br />
d. objects with changing structure, such as HTML DOM objects<br />
<br />
While C# remains a statically typed language, we aim to vastly improve the interaction with such objects.<br />
A secondary theme is co-evolution with Visual Basic. Going forward we will aim to maintain the individual character of each language, but at the same time important new features should be introduced in both languages at the same time. They should be differentiated more by style and feel than by feature set.<br />
<br />
The new features in C# 4.0 fall into four groups:<br />
<br />
<div style="color: #0b5394;"><b>Dynamic lookup</b></div>Dynamic lookup allows you to write method, operator and indexer calls, property and field accesses, and even object invocations which bypass the C# static type checking and instead gets resolved at runtime. <br />
<br />
<div style="color: #0b5394;"><b>Named and optional parameters</b></div>Parameters in C# can now be specified as optional by providing a default value for them in a member declaration. When the member is invoked, optional arguments can be omitted. Furthermore, any argument can be passed by parameter name instead of position.<br />
<br />
<div style="color: #0b5394;"><b>COM specific interop features</b></div>Dynamic lookup as well as named and optional parameters both help making programming against COM less painful than today. On top of that, however, we are adding a number of other small features that further improve the interop experience.<br />
<br />
<div style="color: #0b5394;"><b>Variance</b></div>It used to be that an IEnumerable<string><string> wasn’t an IEnumerable<object>. Now it is – C# embraces type safe “co-and contravariance” and common BCL types are updated to take advantage of that.</string>Pranav Naiduhttp://www.blogger.com/profile/15477871340578415861noreply@blogger.com0