Archive | SharePoint 2010 RSS feed for this section

sharepoint 2010 related

SharePoint2010 – Get TimeZone Value from UserProfileManager

I want to grab the timezone value from User Profile but seem like i got the an object return from API instead, Snippet code below will help you to get the actual value.

SPServiceContext context = SPServiceContext.GetContext(SPContext.Current.Site);
UserProfileManager uprofileManager = new UserProfileManager(context);

if (uprofileManager.UserExists(sUserName))
{
UserProfile up = uprofileManager.GetUserProfile(sUserName);

SPTimeZone spTimeZone = up[PropertyConstants.TimeZone].Value as SPTimeZone;

lblTimeZone.Text = spTimeZone.Description;
}

Incoming search terms:

SharePoint2010 – SPClaimProviderManager i:0#.w|

Recently received a task to develop a custom side menu webpart for SharePoint 2010 – MySite.
The webpart working well in my local machine but not Development Server because it is using Claims Based Authentication. You may see some syntax like “i:0#.w|” infront of your account name (http://localhost/my/person.aspx?accountname=i:0#.w|local/admin)

To solve this problem, you need to decode the account name.


using Microsoft.SharePoint.Administration.Claims;

SPClaimProviderManager mgr = SPClaimProviderManager.Local;
string strDecodedLoginName = "";
if (mgr != null)
{
      try
      {
             strDecodedLoginName = mgr.DecodeClaim(strLoginName).Value;

       }
       catch (Exception ex)
       {
         System.Diagnostics.Debug.WriteLine(" Failure decoding claim for user: " + strLoginName);
         System.Diagnostics.Debug.WriteLine(ex.ToString());
         }
}
else
{
       strDecodedLoginName = SPContext.GetContext(HttpContext.Current).Web.CurrentUser.LoginName;
}

Incoming search terms:

SharePoint 2010 – Mapping AD Field to User Profile Properties Programmatically

A simple code to map AD field to User Profile fields programmatically.

using (SPSite site = new SPSite("http://localhost"))
{
SPServiceContext context = SPServiceContext.GetContext(site);
//Initialize user profile config manager object.
UserProfileConfigManager upcm = new UserProfileConfigManager(context);
ConnectionManager cm = upcm.ConnectionManager;

Connection connection = cm["ADConnection"];
PropertyMapCollection pmc = connection.PropertyMapping;
pmc.AddNewMapping(ProfileType.User, "Title", "givenName");
}

Incoming search terms:

SharePoint 2010 – Creating Group, TermSet and Term Programmatically

a snippet code to create Group, TermSet and Term programmatically for SharePoint 2010.

            using (SPSite site = new SPSite("http://localhost"))
            {
                try
                {
                    SPServiceContext context = SPServiceContext.GetContext(site);
                    TaxonomySession session = new TaxonomySession(site);
                    TermStore termStore = session.TermStores[0];
                    Group group = termStore.CreateGroup("testGroupName");
                    TermSet tSet = group.CreateTermSet("testTermSet");

                    List<string> terms = new List<string>();
                    terms.Add("hello");
                    terms.Add("world");

                    AddTerms(tSet, terms);
                }
                catch (Exception ex)
                {
                   //  throw exception
                 }
            }

        public static void AddTerms(TermSet termSet, List<string> terms)
        {
            int lcid = CultureInfo.CurrentCulture.LCID;

            foreach (string termName in terms)
            {
                bool exist = false;
                foreach (Term t in termSet.Terms)
                {
                    if (t.Name == termName)
                    {
                        exist = true;
                        break;
                    }
                }

                if (exist)
                {
                    continue;
                }
                termSet.CreateTerm(termName, lcid);
            }
            try
            {
                termSet.TermStore.CommitAll();
            }
            catch (Exception ex)
            {
                   //  throw exception              

            }
         }

Incoming search terms:

SharePoint 2010 – User Profile Property Reordering

Last 2 weeks I m received an assignment to find a tool to reorder the SharePoint 2010 User Profile Property.
I found a tool from http://mossprofileordering.codeplex.com/ but it only support SharePoint 2007.
So I m decided to modify the code to support SharePoint 2010.

If you wish to test out the application, you may download it from [here].

Incoming search terms:

SharePoint 2010 – Create User Profile Programmatically

To Create User Profile Programmatically, check out the code below.
I will update 3 fields (Manager, Department and Job Title) to SharePoint 2010

Please add 2 references in the Project

using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
SPSite site = new SPSite(UserProfileController.GetConfigEntry(sServer));
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileManager uprofileManager = new UserProfileManager(context);

if (uprofileManager.UserExists(sAccount))
            {
                UserProfile up = uprofileManager.GetUserProfile(sAccount);
                up[PropertyConstants.Manager].Value = Constants.sDomain + info.Manager;
                up[PropertyConstants.Department].Value = info.Department;
                up[PropertyConstants.JobTitle].Value = info.JobTitle;
                up.Commit();
             }
site.Dispose();

Incoming search terms:

SharePoint 2010 – Create Custom User Profile Properties Programmatically Part 2

In my previous post to [create custom user profile section property].

In this post, will show a some code to create the custom Property for User Profile in SharePoint 2010 programmatically.

SPSite site = new SPSite("localhost");
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileConfigManager upcm = new UserProfileConfigManager(context);

ProfilePropertyManager ppm = upcm.ProfilePropertyManager;

CorePropertyManager cpm = ppm.GetCoreProperties();

if (cpm.GetPropertyByName(propertyname) == null)
{
CoreProperty cp = cpm.Create(false);
cp.Name = propertyname;
cp.DisplayName = displayname;
cp.Length = int.Parse(length);
cp.Type = ptype.Name;

if (type.ToLower() == "string (Multi Value)".ToLower())
{
cp.IsMultivalued = Convert.ToBoolean(ismultivalue);
if (ismultivalue.ToLower() == "true".ToLower())
cp.Separator = MultiValueSeparator.Semicolon;

TaxonomySession taxonomySession = new TaxonomySession(site);
TermStore termStore = taxonomySession.TermStores[termstore];
Group group = termStore.Groups[termstoregroup];
TermSet termSet = group.TermSets[termset];

cp.TermSet = termSet;
}

cpm.Add(cp);

ProfileTypePropertyManager ptpm = ppm.GetProfileTypeProperties(ProfileType.User);
ProfileTypeProperty ptp = ptpm.Create(cp);
ptp.IsVisibleOnViewer = true;
ptp.IsVisibleOnEditor = true;

ptpm.Add(ptp);

ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));

ProfileSubtypePropertyManager pspm = ps.Properties;

ProfileSubtypeProperty psp = pspm.Create(ptp);
psp.PrivacyPolicy = PrivacyPolicy.OptIn;
psp.DefaultPrivacy = Privacy.Public;
psp.UserOverridePrivacy = true;
psp.IsUserEditable = true;

pspm.Add(psp);
}

Incoming search terms:

SharePoint 2010 – Create Custom User Profile Properties Programmatically Part 1

In this post, I will post some snippet code to create custom user profile properties using Microsoft Visual Studio 2010.

Before you create Custom User Profile Properties, you might want to know how to create the “New Section”.


SPSite site = new SPSite("localhost");
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileConfigManager upcm = new UserProfileConfigManager(context);

ProfilePropertyManager ppm = upcm.ProfilePropertyManager;

CorePropertyManager cpm = ppm.GetCoreProperties();

if (cpm.GetSectionByName(propertyname) == null)
{
           CoreProperty cp = cpm.Create(true);
           cp.Name = propertyname;
           cp.DisplayName = displayname;
           cpm.Add(cp);

           ProfileTypePropertyManager ptpm = ppm.GetProfileTypeProperties(ProfileType.User);
           ProfileTypeProperty ptp = ptpm.Create(cp);
           ptpm.Add(ptp);

           ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
           ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));

           ProfileSubtypePropertyManager pspm = ps.Properties;
           ProfileSubtypeProperty psp = pspm.Create(ptp);
           pspm.Add(psp);

}

Incoming search terms:

Configure Maximum File Upload Size (PowerPivot for SharePoint)

*Got this from Microsoft website, for reference purpose.

You must be a SharePoint administrator to change the maximum file upload size.

Configure maximum file size for Excel Services
1.In Central Administration, in Application Management, click Manage service applications.

2.Click Excel Services Application.

3.Click Trusted File Locations.

4.Click the location. By default, Excel Services considers the default web application a trusted site. If you are using the default web application, click http:// to open the configuration page for this location.

5.Scroll to Workbook Properties.

6.In Maximum Workbook Size, increase the file size from 10 (the default value) to 2000 or a larger size that accommodates the files you are working with.

By default, 50 megabytes is the maximum file upload size for SharePoint web applications. If you set Maximum Workbook Size to a number larger than 50 megabytes, follow the steps in the next procedure to increase the Maximum Upload Size for your SharePoint web application to the same value.

7.Click OK.

Configure maximum file size for a SharePoint web application
1.In Central Administration, in Application Management, click Manage web applications.

2.Select the application (for example, SharePoint – 80).

3.On the Web Applications ribbon, click the down arrow on the General Settings button.

4.Click General Settings.

5.Scroll to Maximum Upload Size.

6.Set the property to the same number as the Maximum Workbook Size in Excel Services.

7.Click OK.

Incoming search terms:

Get Adobe Flash player