Creating custom service application proxy groups

February 15th, 2012 No comments

In SharePoint 2010 every webapplication can be connected to the default service application connection group. It is also possible to use the custom group which allows you to choose which service applications need to be connected to the webapplication. In this post I will show how you can create a custom group, connect service applications to this group and how you connect you webapplication to your custom group.

So first let us see where we will find the connection group in Central Administration. Go to Central Admin and then to Manage Webapplications. Select a webapplication and select Service Connections

We see that this webapplication is connected to the “Default Proxy Group’

We can only change this to the custom value and choose each Service Application.

There is no place in the GUI where we can create our own group and connect Service Applications. So Powershell to the rescue.

In my example I am going to create a new group called “My Custom Service Group”.  I will add the the Search Service Applications to the group

This is the script that I ran.

</code>

$groupName = 'My Custom Service Group'

Remove-SPServiceApplicationProxyGroup -Identity $groupName -Confirm:$false -ErrorAction SilentlyContinue

$newProxyGroup = New-SPServiceApplicationProxyGroup -name $groupName
 Write-Host New Proxy Group: $groupName created  -foregroundcolor cyan

$searchProxy  = Get-SPServiceApplicationProxy | Where{$_.DisplayName.StartsWith("Search Service")}

Add-SPServiceApplicationProxyGroupMember -identity $newProxyGroup -member $searchProxy
 Write-Host ServiceApplication proxy $searchProxy.DisplayName connected to proxy group $groupName  -foregroundcolor cyan

<code>

Download script here

So now we see that out own group is shown

Categories: Powershell, Sharepoint, Sharepoint 2010 Tags:

Adding your own custom columns to the Sharepoint SPBuiltInFieldId class

January 26th, 2012 No comments

When coding for SharePoint I always use the class “SPBuiltInFieldId” in code when retrieving fields. When creating my own fields I miss the ability to use the same class to
get my own field id’s. I created a text template file that gets all fields from a certain group and creates a class for me that I can access to get the id’s for my fields.

Here is the first text template that connects to SharePoint. I use the client model because the template engine doesn’t support x64 assemblies.

<#@ template language="C#v3.5" #>
<#@ output extension="cs" #>
<#@ Assembly Name="System.Core" #>
<#@ Assembly Name="Microsoft.SharePoint.Client" #>
<#@ Assembly Name="Microsoft.SharePoint.Client.Runtime" #>
<#@ Import Namespace="Microsoft.SharePoint.Client" #>

using System;
using Microsoft.SharePoint.Client;

namespace Danny.SharePoint
{
  /// <summary>
  /// Custom class like SharePoint SPBuiltinFieldId with you own columns
  /// </summary>
  public static partial class MySPBuiltinFieldIds
  {
<#
	string groupName = "MyCustonColumns";
	string siteUrl = "http://localhost";
	ClientContext clientContext = new ClientContext(siteUrl);
	Web web = clientContext.Web;
	FieldCollection fields = web.Fields;
	clientContext.Load(fields);
	clientContext.ExecuteQuery();
	foreach (Field f in fields)
	{
	  if (f.Group.StartsWith(groupName))
	  {
#>
	/// <summary>
	/// <para>Title: <#= f.Title #></para>
	/// <para>InternalName: <#= f.InternalName #></para>
	/// <para>Id: <#= f.Id.ToString() #></para>
	/// </summary>
	public static Guid <#= f.InternalName #> = new Guid("<#= f.Id.ToString() #>");
<#
	  }
	}
#>
  }
}

Here is the second version that does the same based on a XML file with site columns.

<#@ template language="C#v3.5" hostspecific="true" #>
<#@ output extension="cs" #>
<#@ Assembly Name="System.Core" #>
<#@ Assembly Name="System.Xml" #>
<#@ Assembly Name="System.Xml.Linq" #>
<#@ Assembly Name="Microsoft.SharePoint.Client" #>
<#@ Assembly Name="Microsoft.SharePoint.Client.Runtime" #>
<#@ Import Namespace="System.Xml.Linq" #>

using System;
using System.Xml.Linq;
using Microsoft.SharePoint.Client;

namespace Danny.SharePoint
{
/// <summary>
/// Custom class like SharePoint SPBuiltinFieldId with you own columns
/// </summary>

public static partial class MySPBuiltinFieldIds
{
<#
	XDocument fields = XDocument.Load(Host.ResolvePath(@"Elements.xml"));
		XNamespace ns = "http://schemas.microsoft.com/sharepoint/";

foreach (var field in fields.Descendants(ns + "Field"))
{
string Type = field.Attribute("Type").Value;
string DisplayName = field.Attribute("DisplayName").Value;
Guid FieldId = new Guid(field.Attribute("ID").Value);
string StaticName = field.Attribute("StaticName").Value;

#>
/// <summary>
/// <para>Title: <#= DisplayName #></para>
/// <para>InternalName: <#= StaticName #></para>
/// <para>Id: <#= FieldId.ToString() #></para>
/// </summary>
public static Guid <#= StaticName #> = new Guid("<#= FieldId.ToString() #>");
<#
}
#>
}
}

Inspired by http://blog.mastykarz.nl/generate-spbuiltinfieldid-class/

Change the SharePoint 2010 PassPhrase

January 25th, 2012 No comments

Open a SharePoint Management shell and execute the following command

$passphrase = ConvertTo-SecureString -asPlainText -Force

Set-SPPassPhrase -PassPhrase $passphrase -Confirm:$false

SharePoint 2010 Audience compilation hangs on status compiling

January 25th, 2012 No comments

Sometimes the audience compilation job seems to hang on the status compiling. Manually compiling audiences will no longer work until this status is gone.
There is a trick to stop the audience compilation with Powershell.

In the SharePoint management shell type in “audiencejob.exe”

You will see the id of the user profile service application. Copy this id and run this:

Audiencejob.exe [GUID] 0 (0 means stop / 1 means start)

SharePoint 2010 FullTextSQl shows wrong date

November 28th, 2011 No comments

In a project that I am working on we used FullTextSql query’s. After a while we noticed that dates coming from FullTextSql where a day before actual date. We use Dutch culture so this looked like the obvious reason. After investigating sulution was simple. Sharepoint stores all its dates in UTC time.

So when I add a date field date = 12-12-2011 : 00:00:00, Sharepoint stores this as 11:12:2011 : 23:00:00

Lets take a look at the method below. When we display the DateFieldValue field the date is not showing correct on my Dutch site.


		public List GetResultItems()
		{
			ResultTableCollection queryResults;

			try
			{
				queryResults = new FullTextSqlQuery(SPContext.Current.Site)
				{
					QueryText = @"SELECT ID, Title, Url, DateFieldValue",
					ResultTypes = ResultType.RelevantResults,
					TrimDuplicates = false
				}.Execute();
			}
			catch (Exception ex)
			{
				return new List();
			}

			var queryResultsTable = queryResults[ResultType.RelevantResults];
			var ResultItems = new DataTable();
			ResultItems.Load(queryResultsTable, LoadOption.OverwriteChanges);
			var listOfResultItems = new List();

			try
			{
				// assembly list of Result from the FullTextSqlQuery
				listOfResultItems = (from DataRow row in ResultItems.Rows
										  select new ResultItem
										  {
											  Id = !(row["ID"] is DBNull) ? int.Parse(row["ID"].ToString()) : 0,
											  Title = !(row["Title"] is DBNull) ? (string)row["Title"] : "",
											  Url = !(row["Url"] is DBNull) ? (string)row["Url"] : "",
											  DateFieldValue = !(row["DateFieldValue"] is DBNull) && row["DateFieldValue"] is DateTime ? ((DateTime)row["DateFieldValue"]) : DateTime.MinValue,

										  }).ToList();
			}
			catch (Exception ex)
			{
			}

			return listOfResultItems;
		}

But when we add this: .ToLocalTime() to our datetime the date is converted to correct date and time


DateFieldValue = !(row["DateFieldValue"] is DBNull) && row["DateFieldValue"] is DateTime ?
((DateTime)row["DateFieldValue"]).ToLocalTime() : DateTime.MinValue,

Sharepoint 2010 Taxonomy not synchronized after value change

April 22nd, 2011 No comments

I was having the following problem:

I have a Taxonomy term store with a couple of term groups with in them a couple of term sets with terms. I created several pages and added terms from term store. I now change the term in  the term store. I expect that the terms in my site collections are modified becase every site collection contains a timer job (“Taxonomy Update Scheduler”) for term sync. However the terms are not synced. When I open my page in edit mode I do see the new value. But this is because the label is retrieved from term store based on its reference. When you save page the old value is shown.

When a Taxonomy term is used in your site collection, a copy of this term is placed in de “TaxonomyHiddenList” on your site collection with a reference to the term in the term store. It looks like there is a problem in the synchronisation of terms. Microsoft has released some information and an work arround:

http://blogs.msdn.com/b/joerg_sinemus/archive/2011/03/03/terms-and-how-to-update-taxonomyhiddenlist-when-the-timer-job-was-not-able-to-update.aspx

VMWare Could not create anonymous paging file

April 22nd, 2011 No comments

When working with multiple VMWare images at the same time you can sometimes get the following error while starting a VM

“Could not create anonymous paging file” this error occurs for one of the following reasons

  • Not enough free RAM
  • Host page file is very small

 

Categories: VMWare Tags:

Sharepoint 2010 run with elevated privileges

April 22nd, 2011 No comments

When I was programming for MOSS 2007 I often used the “Run with Elevated Privileges” delegate.

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.Url))
                {
                   using (SPWeb web = site.OpenWeb())
                    {
                    }
                }

            });

But I am now developing for Sharepoint 2010 and sometimes (for no clear reason) this code doesn’t work. I found another way to do this. This is by passing a sys token during creation of SPSite.

            SPUserToken sysToken = SPContext.Current.Site.SystemAccount.UserToken;

            using (var site = new SPSite(SPContext.Current.Site.ID, sysToken))
            {

                using (var web = site.OpenWeb(SPContext.Current.Web.ID))
                {

                }

            }

VMWare workstation freezing issues

April 22nd, 2011 No comments

I use VMWare for my development environment. I was having performance issues. VMWare was freezing and I could not power off my virtual machine.
It turns out that VMWare creates a file on disk that the virtual machine uses as ram. So if you give your VM a mem size like 8gb, a file (.vmem) of 8 gb is created.
My virus scanner was scanning this file. There is a option that you can set in the config file of your VM.

Power ooff your VM end close VMWare

Open the config file of your VM (.vmx)

Add this line at the bottom:

mainMem.useNamedFile = “FALSE”

Now delete the .vmem file and start VMware  and boot your VM

If you use this VMWare no longer creates a file on disk for VM ram. Your VM now uses RAM of host directly.
Also you should ad an exception in your virus scanner for .vmdk files. This prevents freezing during shut down

Enable Sharepoint installer to install on Windows 7 client

April 20th, 2011 No comments

When you try to install Sharepoint 2010 on a Windows 7 client you get the error that you can not install on a Windows client. To fix this copy the content of your disc to your hard drive and edit the files below:

Edit config.xml in

  • Root of Sp2010 cd\Files\setup\config.xml
  • Root of Sp2010 cd\Files\setupfarm\config.xml

Add this setting

<Setting Id=”AllowWindowsClientInstall” Value=”True”/>