Archive | SharePoint 2010 RSS feed for this section

sharepoint 2010 related

SharePoint 2010 – return XmlDocument with WCF Rest WebService

Objective: to return XmlDocument from WCF REST WebService via URL.

Creating a WCF WebService is straight forward, but to create a WCF WebService to host under SharePoint 2010 you need extra steps to accomplish.
This is my first time to develop WCF RestFul WebService. Many of you may familiar with REST if you are the SharePoint Developer.

I will attach a zip file of a working solution at the end of this post.

To Create WCF Service

  • New Project -> WCF -> WCF Service Library
  • it will create 2 class files for you. (we need these 2 files)

To Create SharePoint WCF Service

  • New Project -> SharePoint -> Empty SharePoint Project
  • Map ISAPI SharePoint Folder
  • Create a text file and rename it to “BuckOfficesService.svc”
  • Create another text file and rename it to “web.config”
  • Copy 2 cs files from WCF Service Project (Rename them as BuckOfficeService.cs and IBuckOfficesService.cs)
  • Make sure those references added in the project as well
  • Microsoft.SharePoint
  • Microsoft.SharePoint.Client.Runtime
  • Microsoft.SharePoint.Security
  • System.ServiceModel
  • System.ServiceModel.Web


Click it for clear view

 

So I wanted to return a XmlDocument from Rest WCF WebService.
You need to make sure you add [XmlSerializerFormat] in your Interface class (it will return error when you try to run the service) before or after [ServiceContract]

Deploy the solution to your SharePoint Server.
Launch IE with http://localhost/_vti_bin/buckofficesservice.svc/getbuckoffices


You may download the full working source code for HTTP only [here]

To cater for HTTPS, you need to add extra line in web.config (those red highlighted)
Click the image for better view

Incoming search terms:

  • sharepoint 2010 custom web service rest return xml
  • wcf rest xmldocument
  • sharepoint 2010 webservice return xml
  • sharepoint web service endpoint documents
  • sharepoint with wcf rest
  • unable to return xmldocument from wcf
  • asp net xml webservice return int
  • wcf return xmldocument
  • wcf service return xmldocument
  • wcf to send xml document

SharePoint 2010 – Create Custom Central Admin Menu

Usually the development team create some application pages to park under _layouts directory.

When an application page involved User Profile Services or Deletion, the application just can’t work properly without Service Account.

Fortunately, One of the solution is deploy those applications under Central Admin Page.

That’s 2 custom applications under ’Bucknet 2.0 Support Application’.

This is what I have in Visual Studio 2010, click the image for bigger size so that you able to see xml script in Elements.xml

First you need to create ‘Element’ with above xml script.

Map the admin folder, and create new folder for each applications.

Also, do not forget to set the ‘scope’ to ‘Site’ or ‘Farm’ in Webpart’s feature then deploy to SharePoint server.

if you want to know how to deploy an application page to Central Administration with steps. Click http://msdn.microsoft.com/en-us/library/ff798467.aspx for more information.

Incoming search terms:

  • sp 2010 custom central administration
  • sharepoint 2010 create central admin page
  • customize sharepoint 2010 central admin
  • sharepoint 2010 diary
  • custom menu sharepoint 2010
  • sharepoint central admin add new menu scope
  • sharePoint 2010 createing new central admin
  • sharepoint 2010 custom admin page
  • sharepoint 2010 custom central admin page
  • sharepoint 2010 custom central administration page

SharePoint 2010 – GetAllTerms by Group

Recently received an assignment to retrieve all the terms belong to a specific group.
Here a snippet code to achieve the objective.

For Instance, I want to retrieve all terms under “SMR”


                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPSite site = SPContext.Current.Web.Site;
                    TaxonomySession session = new TaxonomySession(site);

                    Group termGroup = session.TermStores[0].Groups["SMR"];
                    List<string> colSMRTerm = new List</string><string>();
                    if (termGroup != null)
                    {
                        foreach (TermSet ts in termGroup.TermSets)
                        {
                            foreach (Term t in ts.GetAllTerms())
                            {
                                colSMRTerm.Add(t.Name.ToLower());
                            }
                        }
                    }
                }); 

Incoming search terms:

  • sharepoint get all terms from group
  • sharepoint 2010 get all terms
  • retrieving taxonomies sharepoint 2010 get all terms
  • c# sharepoint get all terms termset
  • sharepoint get terms site c#
  • sharepoint group by terms
  • sharepoint termcollection order terms c#
  • sharepoint terminology c#
  • taxonomy custom order getallterms sharepoint c#
  • Taxonomy Session runwithelevatedprivileges

SharePoint 2010 Programmatically Get Activities That I Following

Received an assignment to create a view page for mysite profile, one of the challenge is to get the checkboxlist value from database.

Found this (http://madalina.blog.com/2011/02/09/sharepoint-2010-programmatically-change-activities-that-i-follow/) from google search result.

Article above saved my time to get a list of data from “Activity That I m Following” but to get the checkboxlist value of “Activity That I m Following” seem not very straight forward.

2 API you need to pay attention in order to get those checkboxlist value, which are ActivityManager and ActivityPreferencePerType

Here some snippet code to retrieve the checkboxlist value, as for updating the value, you may refer the above URL for more information.

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

                        if (uprofileManager.UserExists(GetDecodedAccountName(hAcctName.Value)))
                        {
                            UserProfile up = uprofileManager.GetUserProfile(GetDecodedAccountName(hAcctName.Value));

                            ActivityManager activityManager = new ActivityManager(up, context);

                            List<activitypreferencepertype> activityPrefsPerTypes = activityManager.ActivityPreferences.GetActivityPreferencesPerType();

                            foreach (ActivityPreferencePerType ab in activityPrefsPerTypes)
                            {
                                foreach (ActivityType a in activityManager.ActivityTypes)
                                {
                                    if (ab.ActivityType.Equals(a))
                                    {
                                        if (!a.ActivityTypeName.ToLower().Contains("internal_"))
                                        {
                                            string source = String.Concat("$Resources:", a.ActivityTypeNameLocStringName);

                                            string resourceFile = a.ActivityTypeNameLocStringResourceFile;

                                            string displayName = SPUtility.GetLocalizedString(source, resourceFile, SPContext.Current.Web.Language);
                                            lblActivity.Text += string.Format("<input type=\"checkbox\" {0} disabled=\"disabled\" />" + displayName + "<br />", ab.IsSet ? Constants.YES : Constants.NO);
                                        }
                                    }
                                }
                            }
                        }

Enjoy.

Incoming search terms:

  • activities i am following sharepoint 2010
  • powershell activitymanager
  • sharepoint 2010 activitymanager
  • ActivityManager PowerShell
  • sharepoint activities i am following
  • sharepoint activitymanager
  • sharepoint 2010 activity manager
  • sharepoint 2010 activity events values
  • powershell sharepoint 2010 activityManager
  • sharepoint 2010 programmatically get current user

SharePoint2010 – MySite’s Email Notification

Location: MySite – Edit Profile – Newsfeed Settings – Email Notification

To know what is the value return for the combination of the check boxes it will return an integer with semicolon, “0;” for instance.

0 – All Checked
1 – Second and Third check box
2 – First and Third check box
3 – Third check box
4 – First and Second check box
5 – Second check box
6 – First check box
7 – no checked

Hope it helps.

Incoming search terms:

  • mysite notification email
  • mysite email alerts
  • my site e-mail notifications sharepoint 2010
  • custom email notification sharepoint 2010 using c
  • sharepoint 2010 My Site E-mail Notifications
  • sharepoint 2010 my site notification
  • sharepoint 2010 news feed settings email notifications
  • sharepoint 2010 newsfeed settings email notifications
  • sharepoint 2010 notification c#
  • sharepoint 2010 notification mail c

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:

  • sharepoint userprofilemanager
  • c# sharepoint timezone
  • propertyconstants timezone value
  • timezone from user profile to sptimezone
  • sharepoint 2010 sptimezone profile
  • sptimezone
  • sharepoint 2010 get sptimezone by id
  • sharepoint server timezone C#
  • sharepoint timezon taipei
  • sharepoint timezone user profile get value

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:

  • SPClaimProviderManager
  • i:0# w|
  • i:0# w
  • decodeclaim
  • SPClaimProviderManager Local
  • SPClaimProviderManager Local DecodeClaim
  • SPClaimProviderManager DecodeClaim
  • sharepoint 2010 i:0# w
  • sharepoint 2010 i:0# w|
  • sharepoint 2010 0# w|

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:

  • PropertyMapping AddNewMapping
  • UserProfileConfigManager connectionmanager
  • sharepoint 2010 property mapping ad programmatically
  • user profile property mapping title
  • userprofileconfigmanager connectionmanager propertymapping
  • sharepoint 2010 user profile property mappings programmatically
  • sharepoint 2010 user profile property mapping using asp net
  • sharepoint 2010 user profile property mapping code
  • sharepoint 2010 user profile property mapping
  • sharepoint 2010 user profile manager field

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 lcid
  • c# sharepoint 2010 add terms
  • c# sharepoint create term
  • sharepoint 2010 create terms programmatically
  • updating terms in term set c#
  • sharepoint 2010 programatically create term group
  • sharepoint 2010 new term group
  • sharepoint 2010 how to test if a termset exist
  • sharepoint 2010 get termset list programmatically
  • SharePoint 2010 creating 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].

Related Posts with Thumbnails

Incoming search terms:

  • sharepoint 2010 reorder user profile properties
  • re-order sharepoint 2010 user profile properties
  • edit user properties order sharepoint 2010
  • sharepoint 2010 user properties order
  • user profile properties reordering 2010
  • sharepoint 2010 reorder user properties
  • sharepoint 2010 user property order tool
  • sharepoint 2010 user properties order display
  • sharepoint reorder user profile properties quickly
  • sharepoint termset client object model
Get Adobe Flash playerPlugin by wpburn.com wordpress themes