Saturday, March 31, 2012

SharePoint Alerts Report for a List or Library

End-User's Requirement: I want to see all people who subscribed for my Project site's "Lessons Learn" List.

Solution: Wrote object model code to retrieve all alerts created on a specific list.


C# Object Model Code to Get All Alerts Created on a SharePoint List or Library & Generate Report:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.IO;

namespace SharePoint.AdminReports
{
    class GetAlertsForList
    {
        static void Main(string[] args)
        {
            string site;
            string web;
            string list;
            long alertCounter=0;
            StreamWriter SW;

            try
            {
                //Get the site collection , Sub-site, Lists
                if (args.Length != 3)
                {
                    //Site collection
                    Console.WriteLine("Enter the Site collection URL (E.g.) http://intranet.company.com/sites/sales :\n");
                    site = Console.ReadLine();

                    //Sub-Site
                    Console.WriteLine("\nEnter the Sub-Site URL (E.g.) regions/us/  (Press \"Enter\" key for root web): \n");
                    web = Console.ReadLine();

                    //List
                    Console.WriteLine("\nEnter the List/Library Name(Title): (E.g) Announcements: \n");
                    list = Console.ReadLine();
                }
                else
                {
                    site = args[0];
                    web = args[1];
                    list = args[2];
                }

                //objects for the CSV file generation
                SW = File.AppendText("c:\\AlertsOnList.csv");
                //Write the CSV Header
                SW.WriteLine("List URL \t Alert Name \t User Name \t Frequency \t Alert Event");

                using (SPSite tmpSite = new SPSite(site))
                {
                    using (SPWeb tmpWeb = tmpSite.OpenWeb(web))
                    {
                        SPList tmpList = tmpWeb.Lists[list];
                            foreach (SPAlert tmpAlert in tmpWeb.Alerts)
                            {
                                if (tmpAlert.List.Title == tmpList.Title)
                                {
                                    SW.WriteLine(tmpWeb.Url + "/" + tmpList.RootFolder.Url + "\t" + tmpAlert.Title + "\t" + tmpAlert.User.Name + "\t" + tmpAlert.AlertFrequency + "\t" + tmpAlert.EventType.ToString());
                                    alertCounter++;
                                }
                            }
                    }
                }
                //Close the File object
                SW.Close();

                //Display the message to the user
                Console.WriteLine("Found {0} Alerts! Report has been generated! Press a key to Exit.", alertCounter);
                Console.ReadLine();
            }

            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                System.Diagnostics.EventLog.WriteEntry("Get Alerts for List:", ex.Message);
                Console.ReadLine();
            }
        }
    }
}

Output? CSV file like the below screen:

sharepoint alerts report


You can Retrieve All alerts created on a SharePoint list or Library using PowerShell also. Refer my post : Create - Edit - Find - Delete SharePoint Alerts using PowerShell


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, March 30, 2012

"Navigation to the webpage was canceled" Error in .CHM File

Just downloaded a PowerShell Help file (.chm) from Microsoft site. When I open the CHM file, It just displayed an error message "Navigation to the webpage was canceled"

Whatz wrong? Well, Since the file was downloaded from internet, by default it was blocked.

Solution: Go to the properties of the file (Right click on the file, and choose Properties) and then click on Unblock button. That's it.



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, March 28, 2012

Security Trimmed Top Navigation Menu Using Custom Sitemap Provider for SharePoint

Some time back shared my experience on creating consistent top navigation in SharePoint. Now, added with that, there is a requirement to make the Top navigation Security Trimmed!

Alright, to fulfill this requirement all we need to do is: Create our own sitemap provider which does the job of security trimming. Lets get started!

Brief: Create a Class project in Visual studio, Add references to SharePoint, System.web, System.Configuration. Place the following code in the .CS file, Strong Name it, Compile, Place the DLL to GAC, Update the web.config file. Place your own .sitemap file, Change your master page to link with the custom site map.

SharePoint Security Trimmed Navigation Provider - Source Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Navigation;
using System.Web;
using System.Xml;

namespace BpCustomNavProvider
{
    public class CustomNavProvider : SPXmlContentMapProvider
    {

        public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
        {
            try
            {
                if (node == null)
                {
                    throw new ArgumentNullException("node");
                }
                if (context == null)
                {
                    throw new ArgumentNullException("context");
                }
                if (!base.SecurityTrimmingEnabled)
                {
                    return true;
                }
                if (string.IsNullOrEmpty(node.Url))
                {
                    return this.IsGranted(context, node.ChildNodes);
                }
                return this.IsGranted(context, node);
            }
            catch
            {
                return false;
            }
        }


        private bool IsGranted(HttpContext context, SiteMapNode node)
        {
            bool isGranted = false;
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPWeb web = new SPSite(SPContext.Current.Site.MakeFullUrl(node.Url)).OpenWeb())
                {
                    SPUser user = web.AllUsers[context.User.Identity.Name];
                    if (user != null)
                    {
                        try
                        {
                            if ((node.Roles != null) && (node.Roles.Count > 0))
                            {
                                foreach (string str in node.Roles)
                                {
                                    isGranted = (str == "*") || (user.Groups[str] != null);
                                    if (isGranted)
                                    {
                                        break;
                                    }
                                }
                            }
                            isGranted = web.DoesUserHavePermissions(user.LoginName, SPBasePermissions.EmptyMask | SPBasePermissions.ViewPages);
                        }
                        catch
                        {
                        }
                    }
                }
            });
            return isGranted;
        }

        private bool IsGranted(HttpContext context, SiteMapNodeCollection childNodes)
        {
            bool flag = false;
            foreach (SiteMapNode node in childNodes)
            {
                flag = this.IsGranted(context, node);
                if (flag)
                {
                    return flag;
                }
                this.IsGranted(context, node.ChildNodes);
            }
            return false;
        }
    }
}

Web.config Change:
In web.config file, Under the <siteMap>   <providers> section add an entry to our custom site map provider:
<add name="BPCorpProvider" siteMapFile="_layouts/BPCorp.sitemap" type="BpCustomNavProvider.CustomNavProvider, BpCustomNavProvider , Version=1.0.0.0, Culture=neutral, PublicKeyToken=c7b63f4b9c6ca821" securityTrimmingEnabled="true"  />


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, March 27, 2012

Configuring SSL Certificates in SharePoint 2010 - Step by Step

Introduction

SSL certificates provides secure connectivity between client-server. Setting up HTTPS in SharePoint 2010 sites is an security addition. Generally its a best practice to secure SharePoint Central Administration and External web applications with SSL (HTTPS access).

This article covers: How to configure SSL certificates in SharePoint 2010 for HTTPS access. There are different types of SSL certificates available. We can pick one among them whichever applicable to our environment.
  

Steps overview

  1. Get the SSL Certificate
    1. Obtain from Trusted Certificate authority or
    2. Create a Self-signed SSL certificate
  2. Edit the Binding of the web application in IIS
  3. Change the alternate access mapping(AAM)
Important: Certificates should be imported and Bindings to be updated in All the WFEs in the environment.

 

1.     Get the SSL Certificate

To start with SSL certificates either we have to obtain the certificates from any trusted certificate provider like
    Or we need to create our own certificate, known as “Self Signed Certificate”.

    1(a). Obtain The Certificate from Trusted Certificate Authority

    If you have the .PFX file already, just import the .pfx file in "Server Certificates" under IIS, and skip the following steps
    There are two steps involved in provisioning the certificates from trusted certificate authority:
    1.  Create Certificate Signing Request
    2.  Complete the CSR by Installing the Certificate in IIS

    Create Certificate Signing Request
    (For Windows 2003 follow steps at: http://www.serverintellect.com/support/windowsserver2003/create-certificate-request.aspx)
    The First step to obtain the Certificate from Trusted certificate authority is to create certificate signing request. Follow these steps to create SSL certificate request : 
    1.   Click on the Start menu >> Administrative Tools >> Internet Information Services (IIS) Manager.
    2.  Click on the Server name in the Connections column on the left. Double-click on Server Certificates.
    sharepoint 2010 configure ssl certificate

    3. In the Actions column on the right, click on Create Certificate Request... Link
    IIS Server Certificates Console

     4. Enter all of the information about your company and the domain you are securing and then click Next.
    How to create ssl certificate for sharepoint 2010

     5. Select the Cryptographic provider and bit length
    Certificate Request Bit length

     6. Give a Name for the CSR file and click on Finish.
    sharepoint 2010 ssl certificate request
    To validate CSR, use the online tool at: http://www.sslshopper.com/csr-decoder.html

    Complete the CSR by Installing the Certificate in IIS
    Once we generated a CSR, We can send it to a certificate authority, Pay and then get the SSL certificate file. Next step is completing the request by installing the certificate.

    1. Click on the Start menu >> Administrative Tools >> Internet Information Services (IIS) Manager.

    2. Click on the Server name in the Connections column on the left. Double-click on Server Certificates.

    3. Click on “Complete Certificate Request” under Actions tab at right.

    complete certificate request CSR

     4. Browse to the location where the .cer file is located (The one you received from Certificate authority), click on OK
    generate certificate Signing Request - CSR

     5. You should see your certificate appear in the list of server certificates once completed successfully!
    applying certificate in sharepoint
    Done! We have installed SSL certificate in IIS.

    1(b). Creating Self-signed SSL certificate:

    On development/Intranet servers we can use Self signed certificates. By default, Self-signed SSL Certificates have expiry date of 1 year. You can further provide custom parameters to SelfSSL.exe and generate Self-signed SSL certificates.

    Steps to Create Self-Signed Certificate:
    1. Logon to your Web Front End Server

    2. Click on the Start menu >> Administrative Tools, and then click on Internet Information Services (IIS) Manager.
    3. Click on the server in the Connections column on the left, Double-click on Server Certificates.
    4. In the Actions column on the right, click on Create Self-Signed Certificate... 

    generate Self-Signed ssl certificate for sharepoint in IIS

     5. Enter any friendly name (e.g.  “Intranet Certificate” and then click OK.
    sharepoint add ssl certificate friendly name

     6. This will now create a New Self Signed Certificate valid for 1 year listed under Server Certificates. The certificate common name (Issued To) will be the server name.
    sharepoint 2010 apply ssl certificate

    2. Edit the Binding of the web application in IIS

    1. The next step is to: install SSL certificate in IIS of SharePoint site. In the IIS Manager Console: Expand the Server and Site nodes and click the website you want to assign the certificate to. Click on Bindings... in the right column.
    sharepoint edit iis bindings

     2. Click on the Add... button in Site Bindings dialog box
    Add new HTTPS binding for digital certificate in sharepoint 2010

     3. Change the Type to https and select the SSL certificate that you just created. Click OK. You can also replace SSL certificate for your SharePoint site by choosing from the drop-down.
    sharepoint change Bindings for ssl certificate Association

     4. Now, you will see the binding for port 443 listed. Optionally, you can remove the HTTP binding in order to tighten the security. Click Close.
    Edit Bindings in IIS

     We can force the website to use ONLY HTTPS protocol by selecting SSL Settings of the website and then choose “Require SSL”
    sharepoint 2010 ssl certificate installation in IIS

    Fixing the Common Name in self-signed SSL

    Once we open the site with Self SSL, it will display an error message: The security certificate presented by this website was issued for a different website's address”. This is because of the common name mismatch.

    Self-Signed Certificate wizard uses the server name as the common name when it creates a self-signed certificate. So when we have a different host name other than the server name, this causes the mismatch. In fact, this isn't a problem. We can just ignore this error and click "Continue to this web site" each time.
    sharepoint ssl certificate warning Certificate Error: There is a problem with this website's security certificate. Navigation Blocked

    To completely get rid of the error message
    To get rid of the warning message displayed because the common name on the self-signed certificate doesn't match the website's host name. In order to resolve this problem, we'll need to create the self-signed certificate using the SelfSSL.exe which comes with instead of through IIS.

    1. Download and install the Internet Information Services (IIS) 6.0 Resource Kit Tools from http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=17275


    2. Once installed, open the command prompt, Navigate to "C:\Program Files (x86)\IIS Resources\SelfSSL\"  - CD "C:\Program Files (x86)\IIS Resources\SelfSSL\"

    3. Execute the command line:
    3.
    SelfSSL /T /N:CN=migration.crescent.com /V:365 /k:2048

    Where
    /T – Adds the Self-Signed certificate to the "Trusted Certificate" list. If you don’t use the /T key, you have to manually copy the certificate from Personal node to “Trusted Certificates” folder from Certificates MMC.
    /N – Common name, Must be as same as our custom host header, Otherwise you will see error!
    /V – Validity in days
    /K - Key size, by default 1024 bit
    How to Create Self Signed SSL Certificate for sharepoint 2010

     4. Now, assign the new certificate to the Web application.(Follow the steps under: Edit the Binding of the web application in IIS)

     

    3. Configuring Alternate Access Mapping for SSL

    So, we have configured IIS to allow SSL connections, but we need to instruct SharePoint to map the requests to the correct web application. As final step, let’s configure the alternate access mapping by changing URL from HTTP to HTTPS. 

    1. Navigate to Central Administration >> Application Management >> Configure Alternate access mappings     
    configure alternate access mappings

     2. Click on “Edit Public URLs”
    install ssl certificate on sharepoint 2010

     3.  Select the desired web application
    sharepoint 2010 Alternate access mapping

     4. Change the HTTP to HTTPS and click on Save button. Once done, this will automatically change the HTTP to HTTPS.
    sharepoint AAM Setup

    Other considerations:

    SSL Offloading:
    It’s a good Idea to offload the SSL at the firewall or Publishing servers (like F5) so that you can reduce the burden on the Web Frond Ends.

    If you have SSL enabling Central Admin: don’t forget to Change Central Administration Port:
    STSADM -o setadminport -port 443 –ssl

    Intermediate Certificates
    Some of the SSL providers issue server certificates with an Intermediate certificate, so you will need to install this Intermediate certificate to the server as well. Otherwise users will receive a Certificate Not Trusted Error. Just double click the certificate and choose install.

    Unit Test

    Alright, we are done with configure HTTPS in SharePoint 2010. Browse to the site by typing the URL in browser. Make sure it doesn’t give any certificate errors.

    Here is the output: SharePoint 2010 site configured with https! That's all! We've successfully configured SSL Certificate with SharePoint 2010 site.
    sharepoint 2010 secure site

    Tail: Different Types of SSL Certificates:

    Domain Validated Certificates:
    Only the domain owner is validated using an email to an address at the domain using WHOIS record of your domain. It’s simple and fast and cheap.

    Extended Validation Certificates
    This is the highest level of authentication available with an SSL Certificate. They are more expensive than other types of certificates. Web browsers will display the organization’s name in a green address bar and show the name of the Certificate Authority that issued.

    Wildcard Certificates
    Wildcard certificates can be used to secure an unlimited number of subdomains on a single domain name. For example, a certificate for *.domain.com will work on my.domain.com, www.mydomain.com, intranet.mydomain.com, etc.

    SAN Certificates
    Subject Alternative Names let you protect multiple host names with a single SSL certificate. It allows you to specify a list of host names to be protected by a single SSL certificate.

    Code Signing Certificates
    To provide protection of software code and content for the software publishers and the users downloading. It allows you to sign an application or executable so that users know the identity of the organization that made the application.

    Self-Signed Certificates
    Can be created by our self, Users will receive warning if the certificate is not trusted (or expired!).



    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    Monday, March 26, 2012

    Create Pie Chart from SharePoint Task list using Fusion Charts

    Two years back, I posted an article on Creating Fusion Charts in SharePoint.(Refer this article for step by step instructions to create Fusion charts, Just replace the below given XSL)  There is a similar request today, But this time, I had to create a Pie Chart from SharePoint Task List. Requirement is just to display the Chart based on the Task Status counts.

    Here is my XSL

    <xsl:template name="dvt_1.body">
      <xsl:param name="Rows"/>
     
        <xsl:variable name="varNotStarted" select="count(/dsQueryResponse/Rows/Row[normalize-space(@Status) = 'Not Started'])" /> 
        <xsl:variable name="varInProgress" select="count(/dsQueryResponse/Rows/Row[normalize-space(@Status) = 'In Progress'])" /> 
        <xsl:variable name="varCompleted" select="count(/dsQueryResponse/Rows/Row[normalize-space(@Status) = 'Completed'])" /> 
     
       <xsl:variable name="varDataset">
                     &lt;set name=&apos;Not Started&apos; color=&apos;FF6666&apos; value=&apos;<xsl:value-of select="$varNotStarted"/>&apos;  /&gt;
                     &lt;set name=&apos;In Progress&apos; color=&apos;66A866&apos; value=&apos;<xsl:value-of select="$varInProgress"/>&apos;  /&gt;
                     &lt;set name=&apos;varCompleted&apos; color=&apos;0B9CFD&apos; value=&apos;<xsl:value-of select="$varCompleted"/>&apos;  /&gt;
       </xsl:variable>
       
       
     <xsl:variable name="varChartData">
          &lt;graph caption=&apos;&apos; showPercentValues=&apos;1&apos; decimalPrecision=&apos;0&apos; showValues=&apos;1&apos;  showLegend=&apos;1&apos; showNames=&apos;1&apos;  &gt;
          <xsl:value-of select="$varDataset" />
          &lt;/graph&gt;  
          </xsl:variable>
          <tr>
          
      <td>
             <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="600" height="500">
              <param name="movie" value="http://intranet.company.com/sites/IT/itsm/Charts/Pie2D.swf?chartWidth=600&amp;chartHeight=500" >
                <xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:whitespace-preserve="yes" xml:space="preserve">
                    </xsl:text>
                <param name="FlashVars" value="&amp;dataXML={$varChartData}&amp;chartWidth=500&amp;chartHeight=400"><param name="quality" value="high" /></param></param>  </object>
          </td>
    </tr>
          </xsl:template>

    and my Chart with data:
    Related Fusion Chart Articles:


    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    Sunday, March 25, 2012

    SharePoint Database Consistency Check and Repair

    Another fine evening, SCOM reported an IO issue in SQL Server box where SharePoint DBs residing. At the same time, End-users started getting errors: "Cannot complete this action. Please Try again."
    SCOM Alert:
    Alert: Logical consistency error after performing I/O on page
    Source: MSSQLSERVER
    Path: DBserver.domain.org
    Last modified by: System
    Last modified time: 3/21/2012 7:20:55 PM Alert description: SQL Server detected a logical consistency-based I/O error: incorrect checksum (expected: 0x4c2c50d1; actual: 0x4c6650b5). It occurred during a read of page (1:2505989) in database ID 25 at offset 0x000004c7a0a000 in file 'S:\Microsoft SQL Server\MSSQL.1\MSSQL\Data\WSS_Content.mdf'.  Additional messages in the SQL Server error log or system event log may provide more detail. This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.
    
    
    Try the soft repairs first:
    stsadm -o databaserepair -url http://site-coll-url -databasename "Content_Database_Name"

    PowerShell equivalent to repair a SharePoint database would be:
    $database = Get-SPDatabase "Content_Database_Name"
    $database.Repair($false);
    $database.Update();

    If its not successfully repaired, Check the Database's consistency by disconnecting database from SharePoint:
    stsadm -o Deletecontentdb -url <URL-of-my-Web-App> -databasename wss_content

    Log into SQL Server, Get into SSMS. Run these commands:

    USE WSS_CONTENT
    GO

    ALTER DATABASE WSS_CONTENT SET SINGLE_USER
    GO

    DBCC CHECKDB ('WSS_CONTENT') WITH NO_INFOMSGS

    DBCC CHECKDB ('WSS_CONTENT') WITH NO_INFOMSGS
    SQL Server told me to run DBCC CHECKDB with "Repair_Allow_Data_Loss". O.K, Let me try this before using repair_allow_data_loss:

    DBCC CHECKDB('WSS_Content', REPAIR_REBUILD)

    Nope, It didn’t Help, it returned the same error.

    Alright, tried:
    DBCC CHECKDB('WSS_Content', REPAIR_ALLOW_DATA_LOSS)
    luckily it fixed the issue.

    Verified the database consistency by running
    DBCC CHECKDB ('WSS_Content') WITH NO_INFOMSGS
    again. This time, no issues. we are done.

    Set the database mode to Multi & add it back to SharePoint:
    ALTER DATABASE WSS_CONTENT SET MULTI_USER

    Added the DB back to SharePoint:
    stsadm -o addcontentdb -url <URL-of-my-Web-App> -databasename wss_content

    Same kind of issue happened recently with PAGE error. Tried Repair, Allow data Loss, But none worked.
    DBCC CHECKDB ('WSS_Content') WITH NO_INFOMSGS

    finally, I got to restore the database from backups and figured out the root cause: Server hardware failure :-(

    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    Find Most Active SharePoint Sites of a Web Application

    Requirement is fairly straightforward. Get me the list of SharePoint sites which are most active (Where updates made quite often)

    PowerShell? Yes. Lets get the SPWeb's Last Item Modified Date and log it to a CSV file to generate the most active sites report.

    #Set-ExecutionPolicy RemoteSigned
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
    $url="http://sharePoint.company.com"
    $site = New-Object Microsoft.SharePoint.SPSite($url)
    $spWebApp = $site.WebApplication
    
    $OutputFN = "c:\ActiveSitesReport.csv"
    "Site Name `t URL `t Last Modified" > $OutputFN
    
    # Iterate through all sites:
     foreach ( $spSite in $spWebApp.Sites )
      {
             foreach ($spWeb in $spSite.AllWebs)
            {
                      if ($spWeb.IsRootWeb)
                      {
                        $siteName = $spWeb.Title +" - Root";
                      }
                      else
                      {
                      $siteName = $spSite.RootWeb.Title + " - " + $spWeb.Title;
                      }                           
    
                  $siteName + "`t" + $spWeb.Url + "`t" + $spWeb.LastItemModifiedDate >> $OutputFN
                 $spWeb.Dispose() 
            }
        $spSite.Dispose() 
      }
    

    and the .CSV Report file output:
    Most Active SharePoint Sites Report


    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    Tuesday, March 20, 2012

    Create Event Handler to Force Unique in MOSS 2007 with WSP Builder

    Long back, I did an Event handler to prevent duplicates in a SharePoint list. There is a another requirement of same kind now. This time, Let me do it with WSP builder. Requirement is simple - Prevent duplicate titles from a List. Hmm.., But in SharePoint 2010 this is an instinct feature, we don't need to do any event handlers.

    Lets get started.

    Create an Event handler for SharePoint 2007 with WSP Builder - Step by step:

    Step 1:  Open the Visual studio, Create a New Project, Choose WSP Builder Project type
    Create Event Handler for MOSS 2007 with WSP Builder

    Step 2: Add a new item to the Project
    create event handler moss 2007

    Step 3: Choose Event Handler under WSP Builder node, Name it and click "Add"
    sharepoint 2007 wspbuilder event handler

    Step 4: In the Event Handler code, place this code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.SharePoint;
    
    namespace PreventDuplicateEventHandler
    {
        class PreventDuplicates : SPItemEventReceiver
        {
            public override void ItemAdding(SPItemEventProperties properties)
            {
                base.ItemAdding(properties);
                  try
                    {
                        using(SPSite oSPSite= new SPSite(properties.WebUrl))
                        {
                            SPWeb oSPWeb = oSPSite.OpenWeb();
                            SPList oSPList = oSPWeb.Lists[properties.ListId];
    
                            SPQuery oSPquery = new SPQuery();
                            oSPquery.Query = @"<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + properties.AfterProperties["Title"] + "</Value></Eq></Where>";
                            SPListItemCollection oListItemColl = oSPList.GetItems(oSPquery);
                            if (oListItemColl.Count > 0)
                            {
                                properties.Cancel = true;
                       properties.ErrorMessage = "There is already an item with the title " + properties.AfterProperties["Title"] + " in this list";
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.EventLog.WriteEntry("Error encountered in Event Handler", ex.Message);
                }
    
            }
    
        }
    }
    

    Step 5: Build the project, Build the WSP, Deploy the WSP.

    Step 6: Navigate to the site, go to Site settings >> Site features >> and then activate "Prevent Duplicate" feature.

    Activate Feature in Site Features

    Step 7: Now, we have feature ready. We have to associate the event handler with our List. To do that there are lot of tools available. Here is one of them: SharePoint Event Explorer. Download and run the executable. (By the way, You can write your own  code to register the event handler)

    Step 8: Register the event handler to the desired list.
    Event Handler Manager to Regiter Unregister Event Handler with SharePoint List or Library
    Update:
    Found a bug in the above tool! use http://speventreceiverman.codeplex.com/ instead!!!

    That's all. We are done, See it in action!!
    Force Unique in MOSS 2007 with event handler


    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    Monday, March 19, 2012

    Workflow Actions are Empty in Nintex Workflow Designer

    Problem:
    Workflow actions are missing in Nintex workflow designer 2010.
    Troubleshooting:
    • Tried de-activating and re-activating the Nintex Workflow 2010 feature at site collection and site level.
    • Tried adding user to Full permission/Tried Re-adding the user to the site.
    Solution:
    Follow these steps to get workflow actions in Nintex workflow designer: 
    • Open SharePoint Central Administration site as a Farm Administrator.
    • Click on Manage allowed actions link under Nintex Workflow Management.
    • Tick All activities you need and Click on OK to save your changes.
    • Now, Navigate to your SharePoint site, you'll see Workflow Actions available.
    Also make sure, the allowed workflow actions settings are set at the site collection and site levels.

    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    Sunday, March 18, 2012

    'Edit Document' Requires a Windows Sharepoint Services-compatible application and Microsoft Internet Explorer 6.0 or higher

    When trying to edit documents in SharePoint from the context menu item "Edit in Microsoft Office Excel" , users received error message: "'Edit Document' Requires a Windows SharePoint Services-compatible application and Microsoft Internet Explorer 6.0 or higher"

    Edit in Microsoft Office Excel
    Error:
    'Edit Document' Requires a Windows Sharepoint Services-compatible application and Microsoft Internet Explorer 6.0 or higher

    Troubleshooting:
    1. This functionality works only on 32 bit version of IE and not with IE 64 bit version. So use IE 32 bit version. You can access it from: C:\Program Files (x86)\Internet Explorer\iexplore.exe  even though you installed 64 bit version.
    More info: http://technet.microsoft.com/en-us/library/cc263526.aspx refer ActiveX controls section

    2. Make sure all the SharePoint add-ons are enabled in IE. Refer this screenshot.

    Go to Internet explorer >> Tools >> Manage Add-ons to enable the add-ons.

    3. This functionality doesn't work in Firefox (Found it works with Google Chrome!)

    4. Try adding SharePoint site to the trusted sites list in IE.

    5. Register the Owssupp.dll file as per the KB:
    http://support.microsoft.com/kb/833714/en-gb

    6. Check Web client service is enabled and started.

    7. Try Running Microsoft Office Diagnostic: Microsoft Office Tool >> Microsoft Office Diagnostic

    8. Repair/Re-install  Ms-Office. Make sure, You care Installing "Windows SharePoint Services Support"during Microsoft Office Installation.


    9. Don't forget to check  Microsoft Office installed on the client machine! Also check whether the compatible application is installed to open the document (E.g. Client may have Ms-Word 2003, and the document stored may be in Ms-Word 2007 Format.)

    10. Last but not least: Make sure that the URL doesn't exceed 260 characters.

    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    Thursday, March 15, 2012

    Configuring My Sites & User Profile Synchronization in SharePoint 2010 - Step by Step

    Introduction:
    This article provides step by step instruction on Configuring My Sites and user profile synchronization for SharePoint 2010.

    Overview
    1. Create My Site Host web application
    2. Create User Profile Service Application
    3. Configure Synchronizations connections with AD-Domains
    4. Configure Synchronization Schedules
    Before we begin:  
    • Create/Obtain the domain account that will be used for profile synchronization. This account should have the “Replicate Directory Changes” permission on a domain. (This rights for query changes in the directory. This permission does not allow an account to make any changes in the directory.) Refer: http://technet.microsoft.com/en-us/library/hh296982.aspx#RDCdomain for more info and steps. This domain account must be a Farm Admin account and should have Administrator rights on the All the SharePoint servers.
    • Make sure you have all the SharePoint 2010 updates at-least till August 2011 CU is installed.
    Get the updates from URL: http://technet.microsoft.com/en-us/sharepoint/ff800847/
    • Make Sure Managed Metadata service is properly configured and started.

    1. Creating My Site Host web application

    We begin by creating a Web Application that will host our My Site.
    Navigate to Central Administration >> Application Management >> Manage Web Applications >> Click “New”
    Create My Site Host web application

    Enter the New web application details such as Web application Name, Port, Host header, Setup the Managed Account, Database name etc.
    configuring my sites on sharepoint 2010 - Creating My Site Host web application

    Wait for the successful creation of the web application popup dialog box
    configuring user profile synchronization service sharepoint 2010

    Create Top Level My Site Site collection:
    Create a My Site Host Top level site collection by clicking “Create Site collection” Link. Make sure you are selecting “My Site Host” Template from Enterprise tab.
    configure my site host sharepoint 2010
    configure my site host SharePoint 2010
    Wait for the “Top-Level Site successfully created” popup window. 
    setting up user profile synchronization sharepoint 2010
     
    Set up the My Site Web application’s General Settings:
    Navigate to:  Central Administration >> Application Management >> Manage Web Applications
    Click on our newly created “SharePoint 2010 – My Site” Web Application and click on General Settings. 
    my sites sharepoint 2010 quota - Web Application General Settings

    Configure the Time zone, Quota and other settings.

    2. Creating “User Profile Service Application”

    Navigate to Central Administration >> Application Management >> Manage Service Applications.
    Click New and select “User Profile Service Application”
    user profile synchronization sharepoint 2010 Create User Profile Service Application

    In the “Create New User Profile Service Application” window, enter the following details: such as Name, application pool, Etc
    Create New User Profile Service Application
      
      Enter the My Site Host web application URL (Which was created in Step 1)
    setting up my sites on sharepoint 2010

    Click “Create” to complete the User profile application creation.

    On successful creation of user profile application, it will be listed under service applications list
    user profile service application

    Start the User Profile Service and User Profile Synchronization services:
    Get into Central Administration >> System Settings >> Manage services on server.
    Start the User Profile Service and User Profile Synchronization services

    Scroll down to the User Profile Service and User Profile Synchronization Service and start both.
    Facing trouble? Refer User Profile Synchronization Service Stuck at "Starting"

    The User Profile Service should start without any further user interaction, however the User Profile Synchronization Service will ask for your SharePoint Farm credentials.
    configuring user profile synchronization sharepoint 2010

    Click Ok.
    Both services should now be listed as started.
    Start Forefront Identity Manager in Services Console

    If you don’t get these services started, try restarting the server!
    This in turn, will correctly configure and start our Forefront Identity Manager Windows Services (FIM).

    configuring user profile synchronization in sharepoint 2010

    Wait about 10 minutes and verify the both Forefront Identity Management services start up properly in services.msc. Once they start, do an IISRESET.

     3. Configure Synchronizations connections with AD-Domains
    We will now configure our User Profile Connection to our Active Directory Domain(s).
    Navigate to Central Administration >> Application Management >> Manage Service Applications.
    Click on User Profiles >> Manage.
    setting up user profile synchronization service sharepoint 2010

    Click on Configure Synchronizations connections >> Create New Connection.
    Create New Synchronizations Connection

    Get the Domain Connection Strings from your AD administrator:
    Eg.
    Name
    Type
    Source
    Search Base/Entity(Filter)
    us. domain. org
    Active Directory
    Dc01. us.domain. org
    DC=us, DC=domain, DC=org





    Create connections for your domains (such as the one above listed domain).
    Create connections for AD Domain

    Click on Populate Containers and select the relevant containers
    Select Active Directory container in Profile Sync.

    Click OK.
    Your connection should now be listed as follows upon successful creation.
     how to configure user profile synchronization sharepoint 2010
    Setup Filters on Connections:
    By default SharePoint will import all user accounts in the Domain containers you specify. If you only want to import only enabled accounts:

    User Profile Synchronization Connections

    On the Edit Connection Filters page, follow these steps:
    •  In Exclusion Filter for Users, change the Attribute drop-down to userAccountControl, Change the Operator drop-down to Bit on equals, In Filter box type 2.
    • Click Add and then OK.
    KB article on this regard: http://support.microsoft.com/kb/827754

    Specify any additional User or Group exclusions filters as per your requirements
    Filter Disabled users in Profile Synchronization Connections
      
    4. Configuring Synchronization Schedules
    Configure Synchronization Timer Job via Central Administration >> Application Management >> Manage Service Applications >> User Profiles.
    SharePoint Profile Synchronization Schedule

    Click Enable
    SharePoint Profile Synchronization Schedule - Daily

    Initiate FULL synchronization
    We will finish off by initiating a full synchronization via
    Central Administration >> Application Management >> Manage Service Applications >> User Profiles >> Start Profile Synchronization.
    Start SharePoint Profile Synchronization

    See "Profile Synchronization Status" has changed to "Synchronizing" state. Also the "Current Synchronization Stage" has changed to "Active Directory Import (0)". This is the number of objects being imported from Active Directory, Watch this for a while and make sure the number increases.
    configure sharepoint user profile synchronization sharepoint 2010

    Wait for the Sync to complete
    SharePoint Profile Synchronization in Progress

     In order to confirm that the import was a success, the Number of User Profiles should now be set to the number of users in your organization.
    You can get into Manage User Profiles and search for users
    Central Administration >> Application Management >> Manage Service Applications >> User Profiles >> Manager User Profiles.
    Search for a particular user: 
    setting up my sites in sharepoint 2010

    Edit a User Profile to ensure that all the necessary Active Directory attributes were successfully imported.
    sharepoint 2010 mysite active directory attributes

    We have now successfully completed a User Profile Synchronization which will form as a basis for User’s my sites.

    Unit Test

    After the Profile Synchronization job is finished, you can search for a known profile or for accounts that begin with a known domain name from the Manage User Profiles page and verify the properties.

    For testing My Site’s: Click on My Site from User’s Context Menu. My Site should appear as in below screen:
     my sites sharepoint 2010
    References:


    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    You might also like:

    Related Posts Plugin for WordPress, Blogger...