Wednesday, September 28, 2016

How to add Rating Control on SharePoint Designer List Display Page

It's relatively simple to add the rating control on display if you follow these steps:
  • Edit the Display Form
  • Add the following Register Tag at the last Register Tag at the top:
    <%@ Register TagPrefix="SharePointPortalControls" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %> 
  • Add the following control to the layout where you want to place the rating control:<SharePointPortalControls:AverageRatingFieldControl FieldName="AverageRating" ControlMode="Display" runat="server"></SharePointPortalControls:AverageRatingFieldControl>
  • Save and open any existing item... :) 
  • Enjoy, but don't forget to enable the ratings from the list settings before doing these steps. 

 

Sunday, January 10, 2016

XSLT style for - First Row xslt using choose

  <xsl:for-each select="$Rows">
    <xsl:variable name="thisNode" select="."/>
    <xsl:variable name="ID" select="$thisNode/@ID"/>
    <xsl:variable name="Title" select="$thisNode/@Title"/>
    <xsl:variable name="Logo" select="$thisNode/@Logo"/>   
      <xsl:choose>
        <xsl:when test="position() = 1">
         <div class="first">
             <a href="#" onclick="openWindow();" ><img src="{$Logo}" alt="{$Title}" /></a>
         </div>   
        </xsl:when>
          <xsl:otherwise>
             <div class="others">
                <a href="#" onclick="openWindow();" ><img src="{$Logo}" alt="{$Title}" /></a>
              </div>       
          </xsl:otherwise>
      </xsl:choose>       
   </xsl:for-each>

Sunday, January 3, 2016

Adding Rating Control on SharePoint List Item Forms in SharePoint 2013

First of all, you need to enable the Ratings on the list from list settings page where you would like to include the ratings. You will be able to see Ratings column in the list views.

 I googled and read many blogs but most of them mentioned updating/creating a layout page. Now what I wanted to have is the rating column being available on the display item form of the list for a particular list item.

So to be precise, we need to:
  • Create a Visual/Custom web part
  • Add Reference to Microsoft.SharePoint.Portal
  • Register the SharePoint Portal Control
    <%@ Register Tagprefix="SharePointPortalControls" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
  •  Add the following Code in the .ascx:
      <asp:Panel ID="panelRating" runat="server">
        </asp:Panel>
  • On Page Load:

    HttpContext context = HttpContext.Current;
                SPList currentList = SPContext.Current.List;
                SPListItem currentItem = SPContext.Current.ListItem;
                AverageRatingFieldControl ratingCntrl = new AverageRatingFieldControl();
                ratingCntrl.ID = "RatingCntrl";
                ratingCntrl.ListId = currentList.ID;
                ratingCntrl.ControlMode = SPControlMode.Edit;
                ratingCntrl.FieldName = "AverageRating";
                ratingCntrl.ItemContext = SPContext.GetContext(context, currentItem.ID, currentList.ID, SPContext.Current.Web);
                panelRating.Controls.Add(ratingCntrl);
 This will get the rating of the current item and can be updated by the user and can be used on display/edit forms of the List.


 

References:

 

Tuesday, January 31, 2012

How to create Event Source using PowerShell Command in Microsoft Windows 2008 R2

In my previous Blog “Writing Event Logs for SharePoint 2010 Projectsin C#”, we looked at creating Event Logs using C# for SharePoint 2010. In order to use the event logs in specific “Source” first we need to create a source. It could be done using the code but I think it would be an added overhead to check for the source every time a log is written. Moreover, it would turn out to be a nightmare if you end up having security exceptions while creating the event source through the code :S You can easily create a source using the PowerShell Command as given below:

[System.Diagnostics.EventLog]::CreateEventSource(“MySource”, "Application")

Here you go, it is that simple …. This simple creates an event source with the name “MySource” under “Application” Log. Or you could also end up adding a new custom log by having “MyProject” instead of “Application” in the method above.

And of course don’t forget to run the power shell as Administrator ;)

Wednesday, January 4, 2012

Writing Event Logs for SharePoint 2010 Projects in C#

The Background


There are times when you track issues which may occur in the web parts you developed. You can use the Event logs for this purpose using C#.NET. You can write to SharePoint ULS which is also an ideal place to write logs but we will concentrate on Event Logs for now. I will write the post that will deal with the SharePoint ULS soon.


The Solution

Writing event logs in SharePoint 2010 projects are the same as you would typically do on a Classic ASP.NET Application, the only difference would be that you will need to run the CODE under Elevated Privileges. Let’s see it in the code now, shall we? Get ready it is HUGE!! ;)

 

SPSecurity.RunWithElevatedPrivileges(delegate()

            {             
                System.Diagnostics.EventLog.WriteEntry("MyWebparts", message, System.Diagnostics.EventLogEntryType.Error);
            });

 

Well, that is it! One thing that you may be thinking is I did not check for the “MyWebparts” Event Source, if its created or not. I purposely did not write it and here’s the code for it.

 

if (!EventLog.SourceExists(“MyWebparts”))

         EventLog.CreateEventSource(“MyWebparts”,”Application”);



Now the reason why I did not use this is because sometimes you don’t have the required permissions to create an Even Source on the Server in the context on which this code is running. For this purpose, I just create the Event Source on the Web Front End Servers by using PowerShell command. You can find the post under “How to create Event Source using PowerShell Command in Microsoft Windows 2008 R2”. Once the Event Source is set up, the above code will run without any glitches.

NOTE: It is important that you create Event Source on ALL the WEB FRONT END SERVERS in order to avoid any issues relating to writing Event Logs on SharePoint 2010 Multi Farm environments.

Also another fun part that I would like to share is that we can then create Custom Views in the Event Viewer so that You can see exactly what you would be looking for like for instance in this case it would be something like this…
All I did was created a custom view and queried against the Event Source which here is “.NET RunTime” or “MyWebparts” in our case. Hope you find this article useful. Thanks!!!
Some useful links related to Events log:

http://support.microsoft.com/kb/307024

 
http://www.codeproject.com/KB/trace/writing_to_system_event.aspx

Wednesday, June 29, 2011

Approval URL in Nintex 2010 on SharePoint 2010 Multi Web Farm environment

The Background
We were developing the Workflows around SharePoint 2010 with some custom forms for the workflow running on a list with Nintex 2010, a 3rd party workflow designing/developing tool for developing the workflow.

The Issue
We developed the system on a standalone SharePoint installation and UAT was also done on the same, but when it came to deploying it live, we had a web farm environment set up there. We had one application server, 2 web servers and 1 database server. All this went on fine until we setup the live environment and tested the workflow. The notification email for the task consisted of a workflow variable i.e. a builtin feature of Nintex saying “Approval URL” It contained the link to the URL that will show the Task. On clicking on it, one of two tasks were showing the right URL but the last one was giving a URL that was the server URL and it did not show the Alternate Access Mapping set in the Central Admin of SharePoint 2010.
For e.g. the URL should have been http://abc/pages/edittask.aspx?id=123, instead of which it was creating a link like http://webserver1:1111/pages/edittask.aspx?id=123 which was showing the web server name instead of the alternate URL set through Central Admin.

The Solution
I did some research on this issue and found out that this happens in Nintex in cases where we have a server farm. The only useful help that I could find on this issue on Nintex forums was on Nintex Connect.
As we had alternate access mapping configured on live, Nintex used the default zone to create the Approval URL for a workflow at runtime. So in order to create the link with respect to the access mapping declared in central admin, we need to configure nintex to the zone on which the URLs are to be created. Going through the NWAdmin Operations Manual, we were able to solve this problem using the configuration script provided by Nintex.

For this purpose we had to
- Run the NWAdmin.exe tool (Nintex Admin tool). It is located in the folder where Nintex is installed.
- For setting up the “Intranet” zone for the Approval URL, from the above example let us suppose we have defined the public URL for zone is “http://abc” which maps to an internal site url of “webserver1:1111”. For this purpose we need to run the script as:

nwadmin.exe -o AddZoneSetting -type WebApplication -url http://imach21:80 -zone Intranet

where parameters –type defines scope of the zone, -url is the URL for which the zone settings it to be added, -zone defines the zone which is to be used. For more details you can consult the NWAdmin Operations Manual of Nintex under the heading AddZoneSetting.

Tuesday, April 12, 2011

Encrypting Sections of Web.config of a SharePoint Site for Multi-Server environments

This is my first blog on technology, so sorry about me not being so much clear on things. I’m sure it will get better as I go along and share my experiences on various topics related to the technology

The Back Ground
It is always a Best Practice to encrypt sections of web.config that hold sensitive information like connectionstrings, appsettings and others. ASP.NET provides easy way to encrypt such sections of a web.config which does not need any code level changes where accessing the data of those encrypted sections.  You can find detailed articles on encrypting the sections on MSDN links below:
On this post, I would be discussing the encryption of the web.config that I had to do for a multi-server environment of a SharePoint 2010 project which had two web servers and one application server.

The Issue
It is relatively a simple task or configuration when it comes to encrypting the web.config sections on a single server environment where you can use the default protection providers without any hassle but when it involves more than one server, normal encryption operation have to be slightly modified to incorporate consistency of the encryption across all the servers.
The Protection provider that has to be used for a Multi-Server such as a Web Farm environment is RsaProtectedConfigurationProvider.

The Solution
Now cutting things short, for solving this dilemma all you need to do is, open the Visual Studio command prompt and do the following:

1. Create Key Container which will contain the key to be used for encrypting/decrypting the sections. This can be done using:
aspnet_regiis -pc "MyKey" -exp
Make sure that you use –exp switch, If you do not use the -exp switch which indicates that the keys are exportable, then you wouldn’t be able to export the keys later.

2. You would need to give the network service account access to key container we just created. Do this by:
aspnet_regiis -pa "MyKey" "NT AUTHORITY\NETWORK SERVICE"
3. Add the following section to the web.config specifying the Key Container and other related information that asp.net needs to know.

<configProtectedData>
      <providers>
         <add name="MyKeyProtectionProvider"             type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,processorArchitecture=MSIL"
              keyContainerName="MyKey"
              useMachineContainer="true" />
      </providers>
</configProtectedData>
4. Now all you need to do is encrypt the section of web.config file, here I am encrypting the appSettings section of a website by:
aspnet_regiis -pef "appSettings" "C:\inetpub\wwwroot\wss\VirtualDirectories\MyKeyWebsite"
5. Export the key to a file that will be needed to be imported across all the web servers where the website resides. This can be done by:
aspnet_regiis -px "MyKey" C:\MyKey.xml -pri
6. Copy this file to the other web servers where you would need to replicate the change and Import the key on those web servers by:
aspnet_regiis -pi "MyKey" C:\MyKey.xml
7. Now copy the web.config on the web servers that would make use of the configuration protection technique. In my case it was on the two servers where the sites were residing. Other operations like deletion of the key container and default providers for stand-alone is available on MSDN links I provided above and also on various other blogs. 

Happy Protection!!! ;)