Pages

Search This Blog

Showing posts with label User Profile. Show all posts
Showing posts with label User Profile. Show all posts

Sunday, December 25, 2011

Resolving Service Application Errors In Sharepoint 2010 Installed on Windows 7

If you have installed Sharepoint 2010 on Windows 7, You may also encounter following issue while working on Service applications. The details of the error are below:

An exception of type Microsoft.Office.Server.UserProfiles.UserProfileException was thrown.  Additional exception information:

The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+msbin1).

If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<html>
 <head>
 <title>An item with the same key has already been added.</title>
 <style>
 body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
 p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
 b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
 H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
 H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
 pre {font-family:"Lucida Console";font-size: .9em}
 .marker {font-weight: bold; color: black;text-decoration: none;}
 .version {color: gray;}
 .error {margin-bottom: 10px;}
 .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
 </style>
 </head>


This occurs because some features of Microsoft .NET Framework are not enabled by default in Windows 7. These features are required for WCF services used in Service applications. To resolve this, navigate to Control Panel -> Program and Features -> Turn Windows Features on or off


Expand the node "Microsoft .NET Framework 3.5.1" and check all the options.


Click OK and check your Service Application again.

Monday, November 21, 2011

Redirecting to a custom user profile page:SharePoint 2007

By default, whenever we click on a user name like <DomainName>\UserName in a sharepoint site, it redirects us to the sharepoint user profile page  i.e.'/_layouts/userdisp.aspx'which in turn redirects to the page in 'MySite' which displays the user details.

Many a times, we come across a requirement where in we need to redirect the user to a custom user profile page which might contain any other business specific information for the user as well as a picture and other details etc.This page can reside in the 'Pages' library of the site or in the 'layouts' folder in the 12 hive.

In order to do this, we can use a feature to substitute our own webpart in the delegate control already present on the userdisp.aspx page.

This delegate control has the controlid 'ProfileRedirection' with the scope = "Farm".

Therefore, the feature that we develop will have to be a 'Farm' scoped feature.If we need to selectively enable this behaviour for only a particular site,we can filter for that site in the webpart code (as is shown below).

The feature.xml, elements.xml as well as the webpart code is given below:

<?xml version="1.0" encoding="utf-8"?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
         Id="11E746AC-377D-4a5c-8B1D-46D67FF3B25E"
         Title="Custom User Profile Redirection Control"
         ActivateOnDefault="FALSE"
         Description="Registers the delegate control to redirect user to custom Profile page."
         Scope="Farm"
         Hidden="False"
         Version="1.0.0.0">
 
  <ElementManifests>
    <ElementManifest Location="elements.xml"/>
  </ElementManifests>
 
</Feature>

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 
  <!-- set redirect to the new profile page on pages such as userdisp.aspx -->
  <Control Id="ProfileRedirection"
           Sequence="50"
           ControlAssembly="ProfileRedirectionTest.WebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5"
           ControlClass="ProfileRedirectionTest.WebParts.UserProfileRedirect"/>
</Elements>

The webpart code is as follows:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;

namespace ProfileRedirectionTest.WebParts
{
    public class UserProfileRedirect:SPControl
    {
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(SPContext.Current.Site.Url))
                    {
                        using (SPWeb web = site.RootWeb)
                        {
                            string sourceUrl = string.Empty;

                            if (HttpContext.Current.Request.QueryString["Source"] != null)
                            {
                                sourceUrl = HttpContext.Current.Request.QueryString["Source"].ToString();
                            }
                            if (HttpContext.Current.Request.QueryString["ID"] != null)
                            {
                                SPUser spUser = web.AllUsers.GetByID(int.Parse(HttpContext.Current.Request.QueryString["id"]));
                                ServerContext cntx = ServerContext.GetContext(site);
                                UserProfileManager profileManager = new UserProfileManager(cntx);
                                if (profileManager != null)
                                {
                                    bool userExists = profileManager.UserExists(spUser.LoginName.ToString());
                                    if (userExists)
                                    {
                                      
                                      if (web.Title.Equals("My Test Site"))
                                        {
                                            string userProfileUrl = "/_layouts/TestProject/ViewUserProfileFull.aspx?" + "un=" + spUser.LoginName.ToString() + "&source=" + Microsoft.SharePoint.Utilities.SPHttpUtility.HtmlEncode(sourceUrl);
                                            //to redirect to a custom page
                                            HttpContext.Current.Response.Redirect(userProfileUrl, true);
                                       }
                                        else
                                        {
                                            // to redirect to my site page
                                            HttpContext.Current.Response.Redirect(profileManager.MySiteHostUrl + "/Person.aspx?accountname=" + spUser.LoginName.ToString() + "&Source=" + sourceUrl);
                                        }
                                     
                                    }
                                }

                            }
                        }
                    }
                });
                
            }  
            catch(Exception ex)
            {
               throw ex;
            }

           
        }
    }
}

Monday, May 9, 2011

Monitor User Profile Changes

Hi,

Recently , I have visited a good post for tracking the user profile changes.SharePoint does not support out of box any functionality to monitor the changes happens in the user profile. This need coding and custom development.The below details will help you for retrieve the changes done in the user profile.

UserProfileManager objuserProfileManager = new UserProfileManager(ServerContext.Default);
UserProfile userProfile = objuserProfileManager.GetUserProfile("Login name");

DateTime startDate = DateTime.Today - 5;

UserProfileChangeQuery userProfileChangeQuery = new UserProfileChangeQuery(true, true);
UserProfileChangeToken userProfileChangeToken = new UserProfileChangeToken(startDate);
userProfileChangeQuery.ChangeTokenStart = userProfileChangeToken;
userProfileChangeQuery.UserProfile = true;
userProfileChangeQuery.PersonalizationSite = true;
userProfileChangeQuery.SingleValueProperty = true;
userProfileChangeQuery.MultiValueProperty = true;
userProfileChangeQuery.Colleague = true;
userProfileChangeQuery.Update = true;
userProfileChangeQuery.Add = true;
userProfileChangeQuery.Delete = true;
userProfileChangeQuery.SiteMembership = true;
userProfileChangeQuery.Anniversary = true;

UserProfileChangeDictionary userProfileChangeDictionary = userProfile.GetColleagueChanges(userProfileChangeQuery);

Dictionary.Enumerator userProfileChangeCollection = userProfileChangeDictionary.GetEnumerator();
while (userProfileChangeCollection.MoveNext())
{
UserProfileChangeCollection userProfileChanges = userProfileChangeCollection.Current.Value;
foreach (UserProfileChange userProfileChange in userProfileChanges)
{
if (userProfileChange is UserProfileSingleValueChange)
{
UserProfileSingleValueChange propertyChange = (UserProfileSingleValueChange)userProfileChange;
//propertyChange will have the new and old value of profile fileds
}
else if (userProfileChange is UserProfileMultiValueChange)
{
UserProfileMultiValueChange propertyChange = (UserProfileMultiValueChange)userProfileChange;
//propertyChange will have the new and old value of profile fileds
}
else if (userProfileChange is UserProfileWebLogChange)
{
UserProfileWebLogChange listChange = (UserProfileWebLogChange)userProfileChange;
//listChange will have the newly added/modifed list item url
}
}
}

Monday, March 28, 2011

Code to delete user form sharepoint, membership provider and web stie

While developing user registration in an sharepoint form authentication site we need to test the user registration process so i have create a small code to delete the user from sharepoint site, member ship provider and sharepoint site if already added.

Microsoft.Office.Server.ServerContext context = Microsoft.Office.Server.ServerContext.GetContext(new SPSite("http://mysite:8888"));

Microsoft.Office.Server.UserProfiles.UserProfileManager profileManager = new Microsoft.Office.Server.UserProfiles.UserProfileManager(context);
try
{
objWeb.SiteUsers.Remove(sLoginName);
objWeb.Update();
}
catch { }
try
{

profileManager.RemoveUserProfile(sLoginName);

}
catch { }
try
{

Membership.DeleteUser(sLoginName);

}
catch { }
Add a connection string for your membership provider in app.config in case of windows application
Add the reference to microsoft.sharepoint.dll and Microsoft office server dll.