Tuesday, January 27, 2015

Issue in SharePoint 2013 Rating field

Problem:


I have added the rating field to a page layout and created a page using that layout. Then the star images of the rating field does not applier.



Solution


I have added the following JavaScript to the page layout and the “pagerating” class to the Rating field

JavaScript:


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript">
 </script>
            <script type="text/javascript">//<![CDATA[
                function fixIE10StarRatingIssue() {
                    if (SP.UI.Reputation != null) {
                        SP.UI.Reputation.RatingsHelpers.$c(false);
                        jQuery('.pagerating > script').each(function () {
                            eval($(this).text());
                        });
                    }
                }
                _spBodyOnLoadFunctionNames.push('fixIE10StarRatingIssue');
</script>

Rating field:


<div class="pagerating">

         <!--CS: Start Page Field: Rating (0-5) Snippet-->
         <!--SPM:<%@Register Tagprefix="PageFieldAverageRatingFieldControl" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>-->
          <!--MS:<PageFieldAverageRatingFieldControl:AverageRatingFieldControl FieldName="5a14d1ab-1513-48c7-97b3-657a5ba6c742" runat="server">-->
            <!--PS: Start of READ-ONLY PREVIEW (do not modify)--><div align="left" class="ms-formfieldcontainer"><div class="ms-formfieldlabelcontainer" nowrap="nowrap"><span class="ms-formfieldlabel" nowrap="nowrap">Rating (0-5)</span></div><div class="ms-formfieldvaluecontainer">1,234.56</div></div><!--PE: End of READ-ONLY PREVIEW-->
           <!--ME:</PageFieldAverageRatingFieldControl:AverageRatingFieldControl>-->
           <!--CE: End Page Field: Rating (0-5) Snippet-->


</div>

Tuesday, December 23, 2014

Run a PowerShell script in windows scheduler

Once I had a client requirement to run a PowerShell script for a SharePoint 2010 web application to download web analytic reports in a scheduled time. This is how I scheduled the automation of PowerShell script

1.       Go to task scheduler
2.       Click in “Create Task”

3.       Give a name to the task
“Generate Web Analytic Reports”

4.       In Triggers tab, give the date and time which need to Schedule the task


5.       In Actions tab add a new Action
·         Select the Action as “Start a program”
·         In “Program/Script” text box give the following path


C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

·         In “Add Arguments (optional)” text box add following


-psconsolefile "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\psconsole.psc1" -command "C:\ShawCor\WebAnalitics\Reports.ps1"


Report.ps1 is the PowerShell script which I need to run

·         Then click OK

Click Ok to set the task scheduler. The script will run at the given date and time.

Monday, December 22, 2014

Activate the “SharePoint 2010 User Code Host” service.

Activate Sandbox Solutions


From SharePoint 2010 top-level site, logged in as a Site Collection Administrator do the following:

  • Click Site Actions à Site Settings.
  • Under Galleries, choose Solutions.
  • Under the Solutions tab, click Upload Solution. Browse to .wsp package and click OK.
  • Click the Activate button to activate the solution in the site collection. 

If the Activation Button is disabled we need to activate the “SharePoint 2010 User Code Host” service.

Activate “SharePoint 2010 User Code Host” service


Following are the steps to activate “SharePoint 2010 User Code Host” service:

1.       From Central Admin à Security à Configure Service Account



2.       select the Windows Service - Microsoft SharePoint Foundation Sandboxed Code Service option from the drop down and add the account which need to activate the service




3.       After configuring the service account for Sandbox, navigated to “Central Admin à Application Management à Manage Services”




4.       Start the service “Microsoft SharePoint Foundation Sandboxed Code Service”.





5.       Navigate to services and check for the service “SharePoint 2010 User Code Host” had started.





User Profile Synchronization in SharePoint 2010

In following steps I have described how to set up User Profile Synchronization in SharePoint 2010

Service Applications

Service Applications are individual services that can be configured independently and can be shared across other sites within the farm or across farms.


Create User Profile Service Applications


Bellow I have described 2 ways of configuring service applications

1.       Configure service applications through Farm configuration wizard

In Central Admin, under farm configuration, click on Launch the Farm configuration wizard

                There we can select and automatically configure all service applications

2.       Configure service applications manually

1.       Go to central admin à Application Management à Manage Service Applications


2.       Click on Newà User Profile Service Application


3.       Give a name and other properties for the User Profile Service Application

4.       There are 3 databases created in this step

·         Profile DB– Stores user information and activity feed
·         Social DB– Stores tags and notes
·         Sync DB– Staging area for FIM while it’s syncing between AD and SharePoint

If we go and check in SQL server there we can see 3 databases which created in above step

Start the User Profile Synchronization service


After creating the user profile service application we need to start the “User Profile Synchronization Service”

1.       Go to Application Managementà manage services on Server

2.       Start following services


Configure connections and import data from directory services


Create a synchronization connection to a directory service


To import user profiles from Active Directory we need to create a synchronization connection

  1. Go to Central Administration àApplication Management à Manage service applications.
  2. Click on User Profile service application.
  3. On the Manage Profile Service page, in the Synchronization section, click Configure Synchronization Connections.
  4. On the Synchronizations Connections page, click Create New Connection.
  5. On the Add new synchronization connection page, type the synchronization connection name in the Connection Name box 
  1. Select a directory service From the Type list, which you want to connect. 
  1. Fill in the Connection Settings section according to the directory service to which you are creating a connection 
  1. Select the Container and click OK. Then the connection will be created


Define exclusion filters for a synchronization connection


To import user profile information of user accounts that are enabled in Active Directory to SharePoint Server 2010, follow these steps: 

1.     On the Synchronization Connections page, click the Active Directory connection that you want to edit, and then click Edit Connection Filters.



2.     On the Edit Connection Filters page, follow these steps:

In the Exclusion Filter for Users section do following

a.     In Exclusion Filter for Users, change the Attribute drop-down to userAccountControl.
b.     In Exclusion Filter for Users, change the Operator drop-down to Bit on equals.
c.     Select Filter box type to 2.
d.     Click Add.



3.     Click OK.

 

Start profile synchronization


Go to Manage Profile Service page. There in right hand side we can see the profile details. The Number of user profiles are 0. We need to start profile synchronization service.


1.     On the Manage Profile Service page, in the Synchronization section click “Start Profile Synchronization”



2.     Select Start full Synchronization and click OK

We can see the synchronization has started





From couple of minutes if you refresh the page we can see the “Number of user profiles” are changed.


References

Wednesday, January 23, 2013

Security Trim of a Data View Web Part


I have a data view web part which has a link to add pagers to the pagers library. But this link should be hidden to anonymous users.


This can be done by using built in XSLT function called ddwrt:IfHasRights(<Permission Mask>))

Example:
<xsl:if test="ddwrt:IfHasRights(262144)">
      <div class="GridAddNewLink">
              <a href="../Pages/Forms/Upload.aspx">Add new item</a>
      </div>
</xsl:if>

Permission
permissionMask
ViewListItems
1
AddListItems
2
EditListItems
4
DeleteListItems
8
ApproveItems
16
OpenItems
32
ViewVersions
64
DeleteVersions
128
CancelCheckout
256
PersonalViews
512
ManageLists
2048
ViewFormPages
4096
Open
65536
ViewPages
131072
AddAndCustomizePages
262144
AppleThemeBorder
524288
ApplyStyleSheets
1048576
ViewUsageData
2097152
CreateSSCSite
4194314
ManageSubwebs
8388608
CreateGroups
16777216
ManagePermissions
33554432
BrowseDirectories
67108864
BrowseUserInfo
134217728
AddDelPrivateWebParts
268435456
UpdatePersonalWebParts
536870912
ManageWeb
1073741824
UseRemoteAPIs
137438953472
ManageAlerts
274877906944
CreateAlerts
549755813888
EditMyUserInfo
1099511627776
EnumeratePermissions
4611686018427387904
FullMask
9223372036854775807
This table of values can be found under:
C:\Program Files\Microsoft Office\Office14 \CAML2XSL.XSL

Friday, April 27, 2012

Business Connectivity Services

Create an external list in SharePoint 2010 using SharePoint designer 2010

Following example explains how to create a Business Connectivity Services (BCS) with an external content type using SharePoint Designer. An external list is a list based on data from an external system outside of SharePoint. Here I’m using a table in SQL database. 

·         Go to SharePoint Designer
·         Click on the External Content Types menu on the left pane and click the External Content Types icon on the top.  

·         The Connection window appears. Click on “Click here to discover external data source and define operations” link

·         Click on Add Connection button

·         Select Data Source Type as SQL Server

·         Type Database Server and Database Name à Click OK

·         The database is shown on Data Source Explorer as below. Select a Table and right-clicking Table Name and selecting Create All Operations

·         A Parameter Configuration wizard is shown after that. Then select columns which need and click the Finish button to complete and click save button 

Create External list

Now it’s time to create the external list using the external content type which is created above using SharePoint designer. 

·         Go to sharepoint site and g to  All site Actions and click on “Create” button 

§  If "External List" option doesn't appear in the "Create" menu then need to activate “Team Collaboration Lists”
§  Go to: "Site Actions à Manage Site Features" and activate "Team Collaboration Lists" feature.

·         Select external list and click on Create button
·         Give a Name and select the External content type created in previous step using SharePoint designer 2010  

·         Then it will navigate to the list. If it gives following error then follow bellow steps. The error only means that you have not yet assigned access privileges for the current logged-in user. 
·         Go to the Central Admin Page àApplication Management and select Manage service applications
·         Click on the [Business Data Connection Services]
·         After clicking on BDC Services, then you can see the external content type which created earlier. Click on the external content type Name to expand the context menu and select Set Permissions: 

·         Add users and assign access permissions for them and click ok.  
·         Go to the list and refresh page. If still it gives the Access Denied message, reset IIS. Then it will show the list.
·         Now you can Add, Edit, Delete list items. Then it will affect to the table in the given database in the external content type

 

Create External List using Visual Studio 2010


Following example explains how to create a Business Connectivity Services (BCS) with an external content type using Visual Studio and apply this content type in a SharePoint external list.

Create BDC model.

·         Add new BDC model to the project. Right click the project à Add à new Item.
·         From SharePoint Templates select Business Data Connectivity Model. Give a name and click Add 

·         Give the SharePoint site url and select “Deploy as a farm solution” and click ok. 

·         Now I’m deleting the default entity Entity, Entity1.cs and Entity1Service.cs which are created by Visual Studio 2010. After deleting the entity, we can develop the solution from the scratch.
·         Click on “Toolbox” link. Drag and drop the Entity.  Rename Entity1 as Student. 

·         Every entity needs a unique identifier. So right click on Identifier and click on “Add new identifier”. Type “ID”. This should be the same as the “ID” field in student table on SQL Database. 
·         The type of ID is defined as System.Int32 in the database. So, change its Type Name as System. Int32.

Add Methods 


·         There are two methods that we required to enable this scenario. 
    • Specific finder method.
    • Finder method.
Specific finder method
·         Go to the BDC model designer and right click on "Methods" >> Click on "Add new Method" 

·         It will open the window "BDC Method Details". Click on "Add a Method" and click on Create Specific Finder Method.  

·         It will add a new method “ReadItem”. It has a return parameter (student) and input parameter (ID).  

·         The return parameter student has the type as String. But it should be an object with fields’ ID and Name. We have to define an object for student. This means that we have to define a class that holds data fields of student.   

·         Using following method, it will generate a class with fields in it:

Create a class for the return parameter Student 

·         GO to SQL Server and copy the server name
·         Go to VS2010 à Tools à Connect to database à give Server name and database names as shown below. 

·         In the solution explorer, right click on the project and Add à New Item.
·         In “Data”, choose "LINQ to SQL Classes" Give a Name and Click Add button. 

·         Go to Server Explorer and drag and drop the "Student" table to "StudentClasses.dbml"

·         The class which needs for the return parameter Student has been created.
·         Now need to change the Type name of return parameter student from string to newly created object
·         Go to BDC Explorer àStudentBdcModel à Student à ReadItem à student à Student. Click on Student.
·         In Type Name, click on the drop down à Current Project tab à EmployeeBDC àStudent.

·         Now, we get our newly created object

Add Type descriptors

·         By Adding Descriptors, we are giving visual studio 2010 to create fields using a designer interface.
·         Right click Student à Add Type Descriptor

·         Now need to change the name and the Type name. The Identifier for the Student is ID. First we deal with ID field.  Here need to set the identifier only for the ID as ID.
·         Add descriptors for all the fields as given in following table
Name
Type name
Identifier
ID
System. Int32
ID
Name
System.String


Add Code

·         Now it’s time to add some code to ReadItem Method.
·         In Student entity right click  Methods à ReadItem à view code.

·         Add following code in ReadItem method: 

public static Student ReadItem(Int32 iD)
{
string ServerName = @"CTRSRCDEVSQL";
StudentClassesDataContext dataContext = new StudentClassesDataContext("Data Source=" + ServerName + ";" + "Initial Catalog=TestDB;Integrated Security=True");

Student studentobject = (from studenin dataContext.Students.AsEnumerable().Take(20)
where studen.ID == iD
select studen).Single();
return studentobject;
}

 Finder method
·         We want to create a finder method which will return a list of Students.
·         Go to StudentBdcModel.bdcm à Click <Add a Method> and click on “Create Finder Method”.
·         It will add “ReadList” method

·         Go to BDCExplorer you can see all the fields are added automatically to the ReadList we do not need to add them manually

·         Go to StudentBdcModel.bdcm à Methods à ReadList à view code.

public static IEnumerable<Student> ReadList()
{
string ServerName = @"CTRSRCDEVSQL";
StudentClassesDataContext dataContext = new StudentClassesDataContext("Data Source=" + ServerName + ";" + "Initial Catalog=TestDB;Integrated Security=True");

IEnumerable<Student> student1 =
from student in dataContext.Students.Take(20)
select student;
return student1;
}

 ·         Now build and Deploy the solution.
·         Go to SharePoint site and create an External list using the above created external content type.
Deploying an External List via Feature

In the previous step I created an external content type using Visual studio 2010. Now I’m going to create an external list via feature using Visual studio 2010.

Learn from existing solution


·         First I’m going to learn how to create an external list by using existing solution.
·         First I create an external list using previously created StudentBDC.
·         Then save the site as a site template to generate a .wsp file for us. We can use this wsp file to learn the schema of an external list
·         Go to Site Settings à Save Site as Template. Fill in the fields and it will save a solution package in your solution gallery of your site collection.  Save the .wsp file to disk and we’re ready to begin. 
·         Open Visual Studio 2010, create a new project, and use the Import SharePoint Solution Package project template. 
·         You will be prompted for what site to use and where the package file is. 

·         On the next step, you will be prompted for what you want to import. Here all are selected we need only the Student list instance. So deselect (There isn’t a select all button, so press Ctrl+A, and then unclick a checkbox to deselect everything.) all others and select only the Student list instance.
·         It will give a warning about dependencies.  Just say yes and your project will import.

·         Open the Element.xml file
    o   The important parts of the List instance are TemplateType = “600” and the DataSource element
·         Open the Schema.xml file.

It again uses the Type of 600. There are two new elements XslLink and Method
Create new List Definition

·         I create a new project and create a new List Definition. I remove list definition and keep only the instance.
·         Open the Element.xml file
·         I removed some of the unnecessary attributes such as FeatureId and CustomSchema.  I gave it a new Title so that we know this is a different list.  Here is what my new elements.xml looks like.

·         Open the Schema.xml file.
·         I used the Schema.xml file as is.  I did change the Title and Url attributes at the top but that is it. 
·         Here is what it looks like in Visual Studio.

·         Build and deploy the solution. Go to the sharepoint site and you can see the newly created student list