Tag Archives: SharePoint 2010

PowerShell – Delete Orphaned Database

When you trying to create the database with error,removed previously and you want to use back the database name.
script below might able to help you.

$orphanedDB = Get-SPDatabase | where{$_.Name -eq "MyContentDatabase"}

Incoming search terms:

SharePoint 2010 – Access Denied in Search Page


Access Denied for all SharePoint Search Pages suddenly.
You’re able to access with your service account but normal users just cant access it. You check all users with ‘READ’ permission.


  1. Access the Search top level site with Service Account, for instance.
  2. Site Actions -> View All Site Content -> Document Libraries -> Pages (http://localhost/sites/search/Pages/Forms/AllItems.aspx)
  3. Click on one of the page that users were not able to access. A context menu will appear and then click “Publish”
  4. Users able to access the page without permission problem.

Incoming search terms:

SharePoint2010 – Failed to publish Access Web Database to SharePoint2010

Seriously I had hard time to deal with this production issue.

Google around, found a lot of solutions such as, enable “SharePoint Server Enterprise Site Collection features”, Access Central Administration to make sure “Access Service is installed, and bind to the website”.

Unfortunately those wasn’t not able to solve the problem.

We came out a solution which is “save the Microsoft Access Web Database as template, and Create the site with the template”


To Save the Microsoft Access as “Local Database”

  1. Access the Microsoft Access Web Database
  2. Click” Options” -> “Open in Access”
  3. Microsoft Access Launched -> Click “File” -> “Save & Publish” -> “Save Database As” -> “Save as Local Database”

To Save the “Local Database” as Template

  1. Open the file you just saved
  2. Click “File” -> “Save & Publish” -> “Save Database As” -> “Template (*.accdt)”
  3. A window pop up -> Name it “testDB” (will be great without space between the filename), check “Application Part” & “Include Data in Template”
  4. Click OK

Upload Template & Activate the solution

  1. Launch IE, log on to “http://ServerName/sites/test/_catalogs/solutions/Forms/AllItems.aspx
  2. Upload and Activate the solution

Create the Sub Site with uploaded template

  1. Launch IE, log on to “http://ServerName/sites/test/
  2. More Options -> Filter By -> Site -> “testDB”
  3. Enter Site Name and URL and Save

Lastly, deactivate and delete the solution you just created.

Incoming search terms:

SharePoint 2010 – Avoid to use SPContext with SPSecurity.RunWithElevatedPrivileges

Access Denied when accessing properties in SPWeb with SPSecurity.Elevated Privileges as a visitor?
You may need to scan your code if you use “SPContext.Current.Site” or “SPContext.Current.Web” in your program.

To avoid access denied when you use RunWithElevatedPrivileges block, you need to create new instance of SPSite and SPWeb inside SPSecurity.RunWithElevatedPrivileges

SPSite siteColl = SPContext.Current.Site;
SPWeb site = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate() {
  using (SPSite ElevatedsiteColl = new SPSite(siteColl.ID)) {
    using (SPWeb ElevatedSite = ElevatedsiteColl.OpenWeb(site.ID)) {
      string SiteCollectionOwner = ElevatedsiteColl.Owner.Name;
      string Visits = ElevatedsiteColl.Usage.Visits.ToString();
      string RootAuditEntries = 

Incoming search terms:

SharePoint 2010 – Save & Restore Site Template

To save site as template

  1. Site Actions
  2. Site Settings
  3. Site Actions -> Save Site as Template
  4. It will save it at “http://yoursite/_catalogs/solutions/Forms/AllItems.aspx”

To create a site based on a template (create a subsite)

  1. Download the template from “http://yoursite/_catalogs/solutions/Forms/AllItems.aspx”
  2. Upload the site template to another site, “http://yoursite/subsite1/_catalogs/solutions/Forms/AllItems.aspx”
  3. Browse “http://yoursite/subsite1/
  4. Site Actions
  5. More Options
  6. Filter By Site, then select the template you just uploaded.

Incoming search terms:

SharePoint 2010 – Move SharePoint Designer Workflow from a library to another library

Problem: want to re-associate the SharePoint Designer Workflow to another document library.

Solution: using SharePoint Designer to edit “workflowfilename”.xoml.wfconfig.xml .

<association ListID="..." TaskListID="..." ... ></association>

How to find out the ListID?

  • Go to the List/Document Library
  • List Setting/Document Library Setting
  • You will to get the List ID from the Internet Browser URL
  • URL looks like “http://URL/listedit.aspx?List=%7B532E2F14%2DF3B5%2D4BE9%2DA14A%2DE0DBD10E0935%7D”
  • Go to “http://meyerweb.com/eric/tools/dencoder/”
  • Paste the %7B532E2F14%2DF3B5%2D4BE9%2DA14A%2DE0DBD10E0935%7D
  • the website will decode to “{532E2F14-F3B5-4BE9-A14A-E0DBD10E0935}”

Use that DECODED List ID to update the workflow XML file.

NOTE: if you having problem when you try to publish the workflow using SharePoint Designer,
you may delete the webcache at “C:\Users\loginnames\AppData\Local\Microsoft\WebsiteCache”

Incoming search terms:

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 – 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”

                    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())

Incoming search terms:

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);


Incoming search terms:

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.

Related Posts with Thumbnails

Incoming search terms:

Get Adobe Flash player
%d bloggers like this: