Monday, March 16, 2009

Change the language of SharePoint Site(s)

Mirjam van Olst of Macaw (http://www.macaw.nl) explains how to update the language of existing SharePoint sites by running a sql statement on the content datbase.

http://www.sharepointblogs.com/mirjam/archive/2008/04/29/changing-the-language-of-an-existing-sharepoint-site.aspx

For changing the language of all sites in the content database to Dutch the query would be:

UPDATE dbo.Webs SET Language = 1043

Changing the language of one site collection can be done with:

UPDATE dbo.Webs SET Language = 1043 WHERE SiteId = [[SiteCollectionId]]

And for changing the language of a single web or subsite you can use:

UPDATE dbo.Webs SET Language = 1043 WHERE Id = [[WebId]]

Friday, March 13, 2009

‘Error in the application’ when configuring incoming e-mail on a list

When you try to configure incoming email on a list, you might receive the error ‘Error in the application’ when the ‘Central Admin’ application pool user differs from the ‘Web Application’ application pool user.

There might be other causes for the same symptom. For more information, see http://blogs.technet.com/jks/archive/2009/03/04/3209136.aspx

SharePoint outgoing e-mail with Exchange 2007

From fooshen’s blog: http://blogs.msdn.com/fooshen/archive/2006/10/08/SharePoint_2700_s-out_2D00_going-e_2D00_mail-with-Exchange-2007.aspx

Friday, March 6, 2009

Handling Postbacks using MenuItemTemplate

When using a MenuItemTemplate to perform a postback (instead of a navigate), handling the postback can be tricky. If you have several MenuItems, you will end up writing a lot of code to determine the menuitem that caused the postback and parsing the eventargument data.

Patrick Rodgers came up with a subclassed MenuItemTemplate in this post(http://www.thesug.org/blogs/patrickr/Lists/Posts/Post.aspx?ID=18) that targets itself for the postback and raises an event. You simply have to subscribe to the event and handle the postback there.

Here’s Patrick’s code:

using System;
using System.Web.UI;
using Microsoft.SharePoint.WebControls;

namespace Example
{
public class PostBackEventMenuItem : MenuItemTemplate, IPostBackEventHandler
{
public PostBackEventMenuItem()
: base() { }

public PostBackEventMenuItem(string text)
: base(text) { }

public PostBackEventMenuItem(string text, string imageUrl)
: base(text, imageUrl) { }

public PostBackEventMenuItem(string text, string imageUrl, string clientOnClickScript)
: base(text, imageUrl, clientOnClickScript) { }

protected override void EnsureChildControls()
{
if (!this.ChildControlsCreated)
{
base.EnsureChildControls();
if (string.IsNullOrEmpty(this.ClientOnClickUsingPostBackEvent))
{
this.ClientOnClickUsingPostBackEventFromControl(this);
}
}
}

#region IPostBackEventHandler Members

public void RaisePostBackEvent(string eventArgument)
{
EventHandler<EventArgs> handler = this.OnPostBackEvent;
if (handler != null)
{
handler(this, new EventArgs());
}
}

#endregion

public event EventHandler<EventArgs> OnPostBackEvent;
}
}

To use the control, register it in an aspx page, add the PostbackEventMenuItem and subscribe to the OnPostBackEvent.


<%@ Register TagPrefix="SharePoint" 
Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities"
Namespace="Microsoft.SharePoint.Utilities"
Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Example"
Namespace="Example" Assembly="Example, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=2bb7d29b4348a50b" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Control Language="C#" AutoEventWireup="true"
ClassName="Welcome" CompilationMode="Always" %>

<script runat="server">

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
this.ExplicitLogout.Visible = true;
}
else
{
this.ExplicitLogin.Visible = true;
this.ExplicitLogin.Attributes.CssStyle.Add("display", "block");
}
}

protected void HandlePostback(object sender, EventArgs e)
{
//remove all cookies, redirect to login with current page url
FormsAuthentication.SignOut();

Response.Redirect(string.Format("/_layouts/Authenticate.aspx?Source={0}", HttpUtility.UrlEncode(HttpContext.Current.Request.Url.AbsoluteUri)));
}

</script>

<SharePoint:PersonalActions AccessKey="<%$Resources:wss,personalactions_menu_ak%>"
ToolTip="<%$Resources:wss,open_menu%>" runat="server"
ID="ExplicitLogout" Visible="false">
<CustomTemplate>
<SharePoint:FeatureMenuTemplate
runat="server" FeatureScope="Site"
Location="Microsoft.SharePoint.StandardMenu"
GroupId="PersonalActions" ID="ID_PersonalActionMenu" UseShortId="true">
<SharePoint:MenuItemTemplate
runat="server" ID="ID_PersonalInformation"
Text="<%$Resources:wss,personalactions_personalinformation%>"
Description="<%$Resources:wss,personalactions_personalinformationdescription%>"
MenuGroupId="100" Sequence="100" ImageUrl="/_layouts/images/menuprofile.gif"
UseShortId="true" />
<example:postbackeventmenuitem
runat="server" id="Example_LoginAsDifferentUser"
text="<%$Resources:wss,personalactions_loginasdifferentuser%>"
description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"
menugroupid="200" sequence="100" useshortid="true" ononpostbackevent="HandlePostback" />
<SharePoint:MenuItemTemplate
runat="server" ID="ID_RequestAccess"
Text="<%$Resources:wss,personalactions_requestaccess%>"
Description="<%$Resources:wss,personalactions_requestaccessdescription%>" MenuGroupId="200"
UseShortId="true" Sequence="200" />
<SharePoint:MenuItemTemplate
runat="server" ID="ID_Logout"
Text="<%$Resources:wss,personalactions_logout%>"
Description="<%$Resources:wss,personalactions_logoutdescription%>" MenuGroupId="200"
Sequence="300" UseShortId="true" Visible="true" />
<SharePoint:MenuItemTemplate
runat="server" ID="ID_PersonalizePage"
Text="<%$Resources:wss,personalactions_personalizepage%>"
Description="<%$Resources:wss,personalactions_personalizepagedescription%>" ImageUrl="/_layouts/images/menupersonalize.gif"
ClientOnClickScript="javascript:MSOLayout_ChangeLayoutMode(true);" PermissionsString="AddDelPrivateWebParts,UpdatePersonalWebParts"
PermissionMode="Any" MenuGroupId="300" Sequence="100" UseShortId="true" />
<SharePoint:MenuItemTemplate
runat="server" ID="ID_SwitchView" MenuGroupId="300"
Sequence="200" UseShortId="true" />
<SharePoint:MenuItemTemplate
runat="server" ID="MSOMenu_RestoreDefaults"
Text="<%$Resources:wss,personalactions_restorepagedefaults%>"
Description="<%$Resources:wss,personalactions_restorepagedefaultsdescription%>"
ClientOnClickNavigateUrl="javascript:MSOWebPartPage_RestorePageDefault()" MenuGroupId="300"
Sequence="300" UseShortId="true" />
</SharePoint:FeatureMenuTemplate>
</CustomTemplate>
</SharePoint:PersonalActions>
<SharePoint:ApplicationPageLink runat="server" ID="ExplicitLogin" ApplicationPageFileName="Authenticate.aspx"
AppendCurrentPageUrl="true" Text="<%$Resources:wss,login_pagetitle%>" Style="display: none"
Visible="false" />

Wednesday, March 4, 2009

Hyper-V networking reset when copying VHD or creating ‘differencing VM’

Whenever you create a new Virtual Machine for an existing (previously configured) VHD (either by copying the VHD or using differencing disks), the networking configuration of the VM is reset.

This is because when creating a new VM, the Network Adapter(s) you assign receive a new Guid and are treated by the OS as new hardware.

The following post explains this behavior in detail:

http://blogs.technet.com/jhoward/archive/2008/07/22/hyper-v-why-is-networking-reset-in-my-vm-when-i-copy-a-vhd.aspx

Tuesday, March 3, 2009

MakeCab file length limitation

Apparently, there is a limitation to the maximum length of the source file in a DDF file that MakeCab can handle. When the file name exeeds 100 characters, you will receive a File not found error when running makecab.exe

See Michael Blumenthal's post at http://blumenthalit.net/blog/Lists/Posts/Post.aspx?ID=75 for full details.