Wednesday 12 November 2008

The form has been closed. Xmlformview web part

When addding the xmlformview web part to a sharepoint page, you may get an error that fills the full page saying "The form has been closed". Since this error fills up the full page you will not be able to edit the properties of the web part that you have just added.

To fix this problem follow the steps below.

1. Navigate to the page library where the web part page is located
2. Click on the options on the page and click "Edit Properties"
3. At the bottom of the properties page, click on "Web Part Page Maintenance".
4. Using the web part maintenance page close the xmlformview web part
5. Go back to the page where you added the web part and click on add a webpart
6. Instead of choosing the xmlformview web part from the web part list click on advanced and select the xmlformview web part from the "Closed Web parts" list
7. Now the web part would be added and the web part properties displayed
8. Edit the web part properties and add the url of the infopath form in the xsn location field in the Data category
9. In the Feature Catergory set the editing status dropdown value to "editing"

Other websites recommend you to add the xmlformview web part again from the main list after closing the web part that you added first but that did not work for me.

Tuesday 11 November 2008

Console Configuration File Error: XML Exception: Object reference Sharepoint

If you get the error below in your event viewer
Console Configuration File Error: XML Exception: Object reference not set to an instance of an objet

and the message Object reference not set to an instance of an object! at the area where you would expect your page editing toolbar then the reason is that the xml files in Editing Menu folder in the Master Page gallery are not in the Published state.

To fix this, just publish all the xml files in the folder Editing Menu and approve them!

Tuesday 23 September 2008

Customising Ontolica Search

As you know when you instal Ontolica on a Moss box it overrides the default sharepoint delegate search control with ID "SmallSearchInputBox", this is the searchbox that we are customising below.

To customise ontolica search, i.e. to change the search magnifying image button or to change the css classes you just need to modify the xslt file that ontolica uses.

This can be found in the location RootSite/OntolicaStyles/Forms/Allitems.aspx and open the folder SearchBox and edit the default.xslt file in here...you can change the images, change the borders around the search boxes etc.

You do not need to do an IISRESET but it seems to take a while before the changes are reflected on the page so if it is a dev box do an IISRESET to see the changes immediately.

Monday 22 September 2008

SharePoint Search Customisation (Ontolica)

If you want to modify the basic search in SharePoint just edit the properties in the SearchArea.xml file located at C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\OSearchEnhancedFeature and C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\OSearchBasicFeature

You can easily customise the Show Scope dropdown, show advanced search option, width of the textbox etc. Only a few properties are set in the xml file but more properties are available and can be added...have a look at the website below for a complete list of properties.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.portal.webcontrols.searchboxex_members.aspx

If you have installed ontolica search and want to modify the dropdown and advanced search option then you can do that by going to Site Actions - Site Settings - Modify All Site Settings - Ontolica Search Box Scopes and clicking on the settings button on the toolbar

Thursday 18 September 2008

Multiple levels of SharePoint menu

By default only the main sites and sub sites are displayed in the top harepoint menu, if you want further level of sites to appear on the top navigation you just need to modify the SharePoint menu option in the master page.


Before doing this open the default master page in sharepoint designer and take a copy of it and play with the copy just in case if you mess it up can you always revoke back.
Edit the master page in Sharepoint designer and find the tag and change the contents of it to look something like below, the key value is the MaximumDynamicDisplayLevels changing it to 1 or more will give you additional sub menus


DynamicHorizontalOffset="0"

DynamicVerticalOffset="0"

StaticEnableDefaultPopOutImage="false" Runat="server"

DataSourceID="LeaveThisValueUntouched"

Orientation="Horizontal"

StaticDisplayLevels="2"

MaximumDynamicDisplayLevels="2" //this sets the number of levels

StaticSubMenuIndent="0" //you can indent the sub menu as you wish

ItemWrap="false"

SkipLinkText="<%$Resources:cms,masterpages_skiplinktext%>"

CssClass="topNav">


Save the modified master page and that's it!


If you have taken a copy and have changed the copy then you need to go to Site Settings - Master Page option in your sharepoint site and from the drop down choose the new master page.

keywords: dynamic menu sharepoint, multi level menu, advanced menu, top navigation sharepoint

Tuesday 16 September 2008

Sharepoint site templates

When creating a new sub site in SharePoint, you can restrict users on what kind of site template they can use to create the sub site.

You can specify which individual site templates users can see when they create sub sites, for instance you can enable just the publishing site template so that all subsites are of type publishin site.

This option can be set by modifying the Root level site settings and choosing the option "Page Layout and Site Template Settings" under the heading "Look and Feel".

Adding a pdf icon to MOSS 2007

MOSS 2007 does not display icons for pdf documents OTB.

To add this icon follow the steps below

1. Download a pdf icon, there are a few ones on the site, for consistence sake choose the one with a 16 x 16 resolution, http://www.adobe.com/misc/linking.html
2. Save the icon to 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Images' folder
3. Edit DOCICON.XML found in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML
4. Add the line to the document and save it

Thursday 7 August 2008

XmlFormView used in a Sharepoint Environment Error

When following the tutorial on deploying an infopath form in asp.net web page into sharepoint you might get the strangest of errors saying

"The type 'Microsoft.Office.InfoPath.XmlForm' is defined in an assembly that is not referenced."

If you get this ensure that the web.config file for the SharePoint contains the Infopath Assemblies

-----web.config ----








---web.config----

This is the url that walks thru the hosting of the infopath forms in a custom page. Please be aware that the tutorial only caters for situations where you are hosting the .net page in the root site collection.

http://msdn.microsoft.com/en-us/library/aa701078.aspx#infopathxmlformviewcontrolcustomwebpage_deployingnonroot

Using query string with InfoPath forms

Sometimes it is necessary to accept query string for browser enabled info path forms. This can be done by hosting the Infopath form in a asp.net page and hosting that page within Sharepoint using the XmlFormView class.

This technical guide explains the process

http://msdn.microsoft.com/en-us/aa701078.aspx

The code behind for the asp.net page will contain a method like the one shown below..

protected void XmlFormView1_Initialize(object sender, InitializeEventArgs e)
{
string positionAppliedFor = Request.QueryString["Position"];
string jobID = Request.QueryString["JobID"];
string appURL = Request.QueryString["AppURL"];

if (!string.IsNullOrEmpty(positionAppliedFor) && (!string.IsNullOrEmpty(jobID)))
{
// Create an XPathNavigator positioned at the root of
// the form's main data source.
XPathNavigator xNavMain = XmlFormView1.XmlForm.MainDataSource.CreateNavigator();
// Create an XmlNamespaceManager and add the "my" namespace
// alias from the form's main data source.
XmlNamespaceManager xNameSpace = new XmlNamespaceManager(new NameTable());
xNameSpace.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-07-08T12:49:29");
// Create an XPathNavigator positioned on the form's field2.
XPathNavigator fTextBoxPosition = xNavMain.SelectSingleNode(
"/my:myFields/my:gpRecommendation/my:txtPositionAppliedFor", xNameSpace);
// Set the form's job Position Value to the value passed in the query strings
fTextBoxPosition.SetValue(positionAppliedFor);

XPathNavigator fTextBoxJobID = xNavMain.SelectSingleNode(
"/my:myFields/my:gpRecommendation/my:txtJobID", xNameSpace);
fTextBoxJobID.SetValue(jobID);

if (!string.IsNullOrEmpty(appURL))
{
XPathNavigator fTextBoxAppURL = xNavMain.SelectSingleNode(
"/my:myFields/my:gpRecommendation/my:txtAppURL", xNameSpace);
fTextBoxAppURL.SetValue(appURL);
}
}
}

Installing SharePoint on a simple farm

Very comprehensive guide on installing SharePoint on a simple farm

http://technet.microsoft.com/en-us/library/cc262243.aspx

Validating Currency fields regular expression

Expression: ^\d{0,2}($|\.\d{0,2}$)
Example of valid values:
20.09
1.99
1.2
3
.5

Example of invalid values:
120.09
1.991
x

Wednesday 14 May 2008

Validating Custom Web Part Properties - the proper way!

Adding validation to custom web part properties (the proper way!) Thanks Ken Josling for this info!

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.IO;
using System.Resources;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace YourNamespace
{

public class YourWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
private bool invalidConfiguration;
private string exceptionMessage;
private ResourceManager resourceManager;

public YourWebPart()
{
invalidConfiguration = false;
exceptionMessage = string.Empty;
resourceManager =
new ResourceManager("YourNamespace.Resource", GetType().Assembly);
}

private void invalidateConfiguration(string message)
{
invalidConfiguration = true;
exceptionMessage = message;
}

protected void AddInitializeControl()
{
bool hasRights = ((ISecurableObject)SPContext.Current.Web).DoesUserHavePermissions((SPBasePermissions)Microsoft.SharePoint.SPPermissionGroup.WebDesigner);

if (!hasRights)
return;

string editLink = Microsoft.SharePoint.WebPartPages.ToolPane.GetShowExtensibleToolPaneEvent(string.Format(@"'{0}'", this.UniqueID));
this.Controls.Add(new LiteralControl(
string.Format(exceptionMessage + resourceManager.GetString("WebPartHelpMessage"), editLink.Replace(@"ExtensibleView", @"Edit"))
));

}

protected override void CreateChildControls()
{
//Add your validation logic here
if(x)
{
invalidateConfiguration(resourceManager.GetString("SomeErrorMessage"));
}
if (y)
{
invalidateConfiguration(resourceManager.GetString("SomeOtherErrorMessage"));
}

if (invalidConfiguration)
{
AddInitializeControl();
}
else
{
//Render Web Part Here
}
}

protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
}
}

Monday 12 May 2008

Trying to use an SPWeb object that has been closed or disposed and is no longer valid

Trying to use an SPWeb object that has been closed or disposed and is no longer valid

When you get the error message above it is most likely that you have got a reference to the SPWeb object by using the SPContext as shown below

SPWeb web = SPContext.Current.Web;

There is no problem with using this method but you need to make sure that you do not close or dispose this SPweb object becase the SPContext.Current.Web is used by the Page and all the controls on the page.

So you should not use this web object in Using statements also.

Wednesday 30 April 2008

Working with SharePoint Groups

This is a nice article that talks about working with SharePoint groups programmatically.

The only problem I had was I had to replace the lines
SPRoleDefinitionBindingCollection roleDefBindings = roleAssignment.RoleDefinitionBindings;

with SPRoleDefinition and added this role definition directly to the SPweb as shown below

SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)group);
def = web.RoleDefinitions["Full Control"];
roleAssignment.RoleDefinitionBindings.Add(def);
web.RoleAssignments.Add(roleAssignment);
web.Update();

http://www.emptycache.com/blog/2008/04/18/working-with-users-and-groups-in-sharepoint-2007/

Tuesday 22 April 2008

SharePoint Admin webservice

The Admin web service that SharePoint exposes _vti_adm/Admin.asmx can be used to create new SharePoint Sites, etc..the catch is you cannot just append this webservice url to any sharepoint site but only to the web app that hosts central admin..

For instance if you have a number of SharePoint sites at the following ports
1. http://servername:1233/CollaborationSite
2. http://servername:4545/TeamSite
3. http://servername:1066 - Central Admin

To connect to the Admin webservice you cannot do something like http://servername:1233/_vti_adm_Admin/asmx but you have to use the port that Central Admin is hosted so it will be http://servername:1066/_vti_adm/Admin.asmx

Tuesday 15 April 2008

Changing default text in Sharepoint

When you try to edit SharePoint pages like AccessDenied.aspx that sit in the Layouts folder in Sharepoints 12 folder hive you will notice that the text is not stored there.

They just reference resource files that sit under Inetpub under the location C:\Inetpub\wwwroot\wss\VirtualDirectories\portnumber\App_GlobalResources\wss.en-US.resx

So to change the Access Denied message to Access has been Denied or something like that you just need to change the value of the property accessDenied_pagetitle


Error: Access has been Denied

Thursday 27 March 2008

Working with PDF's Dot Net

The PDFSharp open source Dot Net classes make working with PDF's in .Net very easy.
http://sourceforge.net/projects/pdfsharp

Friday 7 March 2008

Create Page gives Access Denied error on Sharepoint

Came accross this problem where users with Full Control rights of a Sharepoint site were getting the Access Denied message when they clicked on the "create page" button.

The reason was that the users who create pages need to have read rights to the "Master Page Gallery"!

Thursday 6 March 2008

Add custom Styles to Rich Text Editor Sharepoint - content editor web part

To add custom styles to the Rich Text Editor in SharePoint (both the ones accessed through the content editor web part and the inbuilt page content web part), just add styles in the format ms-.ms-rteCustom-nameofclass to your css style sheet that your master page uses. It's as simple as that.

If you are not using custom master pages style sheets, then just add the styles in the format rteCustom-Title (rteCustom- should appear before the style name) to a stylesheet and upload the stylesheet css file to the style library of the site collection, then go to site settings - master page settings and choose the override style sheet option and point to the style sheet that you just uploaded to. That's it, now when you open the rich text editor in sharepoint, type in some text, highlight the text you typed and from the styles dropdown choose the style you want.

Example of custom style that would appear in the css class .ms-rteCustom-TitleRed{Font-family: arial;Font-size: 14pt;Color: Red;}

Tuesday 19 February 2008

Set "Show Subsites" option in Sharepoint Modify Navigation to False

Programatically set the "Show Subsites" checkbox in the Modify navigation section of a sharepoint site to false using the code below

spweb.AllProperties["__IncludeSubSitesInNavigation"] = "False";
spweb.Update();

Friday 15 February 2008

Modify the Edit HTML Toolbar in Sharepoint

Modifying the Edit HTML toolbar that appears in Sharepoint Publishing pages is very easy.

In your page layout you could add attributes like AllowFonts="false", AllowImages="false" and so on..here is an example of disabling fonts and html editing



That's it!

Publishing InfoPath Forms connecting to Webservices into Sharepoint

The following applies to attaching a certificate to an infopath form and deploying it to sharepoint. This certificate is necessary because the infopath form that we use connects to an external webservice so "full control" level security must be applied to the form.

Thanks Kieran Toon for the below..:-)

To deploy an Infopath form to SharePoint with code behind publish the form to a common network location(the wizard will take care of this - first option on first screen). Have the administrator upload the form using Central Admin and then activate it for your site collection. This form will then appear a content type which you can use as you wish in any document or forms library



That is correct, forms with .Net enabled code can be deployed as web enabled forms but they need to be deployed through central administration.

http://spsfactory.blogspot.com/2007/01/walkthrough-publishing-administrator.html
http://technet2.microsoft.com/Office/en-us/library/8285b82e-19db-4408-859f-1430830fe0fb1033.mspx?mfr=true
BlackPearl now publishes the InfoPath form but this does not seem to be accomodated. Maybe there could be an option added to the wizard which would deploy the InfoPath form to central administration and performing the other actions needed.




Excellent pointer. From this information, it allowed me to find this excellent article - Creating InfoPath Form Templates That Work With Forms Services (http://msdn2.microsoft.com/en-us/library/aa945450(VS.80).aspx) which contains the following.

Note:
After publishing a browser-enabled form template that contains managed code to Microsoft Office Forms Server 2007, to Office SharePoint Server 2007 with InfoPath Forms Services, or to a shared location, the form template must be uploaded and approved by a server administrator before it will be allowed to run.
These other links were also pretty useful in understanding the limitations of Web Enabled InfoPath forms.

InfoPath features that are supported in InfoPath Forms Services (http://office.microsoft.com/en-us/infopath/HA102040851033.aspx?pid=CH100211501033)
InfoPath 2007 features that are unavailable in InfoPath Forms Services (http://office.microsoft.com/en-us/infopath/HA102105871033.aspx)




http://k2underground.com/forums/thread/18335.aspx

Tuesday 29 January 2008

KB934525 Troubleshooting "Cannot start service SPAdmin on computer '.'."

If when running the sharepoint upgrade wizard you get the error KB934525 Troubleshooting "Cannot start service SPAdmin on computer '.'." follow step 4 in the following link which is

"Option # 4

On the machine where psconfig failed to start the SPAdmin service run:
%commonprogramfiles%\Microsoft Shared\Web Server Extensions\12\BIN\psconfig -cmd upgrade -inplace b2b -wait -force
Modify the service timeout values in the Registry:

HKLM\SYSTEM\CurrentControlSet\Control add/modify DWORD value ServicesPipeTimeout to 60000 (60 seconds)

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control add/modify STRING value WaitToKillServiceTimeout to 120000 (120 seconds)
Restart the server machine.

"


This fixes the problem

http://blogs.technet.com/wbaer/archive/2007/10/15/kb934525-troubleshooting.aspx

Remotely Reboot server using Computer Management Console

This is a very useful way of rebooting a server if you know the box is up and running but are not able to connect to it through remote desktop.

Thanks Priyabrata Lahiri (Priyo) http://blogs.msdn.com/priyo/archive/2007/11/20/remotely-reboot-windows-server-2003.aspx for pointing us to this resource..(The below is copied and pasted from the mentioned url)

1. Open Computer Management (Local)

2. In the console tree, right-click Computer Management (Local), and then click Connect to another computer.

3. In the Select Computer dialog box, click Another computer, type the name of the computer that you want to restart or shut down, and then click OK. You can also click Browse to search for the name of the computer.

4. In the console tree, right-click Computer Management (Remote computer name), and then click Properties.

5. On the Advanced tab, click Startup and Recovery.

6. Click Shut Down to open the Shut Down dialog box.

7. Under Action, select the actions you want to perform on the computer to which you are connected.

8. Under Force Apps Closed, select the circumstances under which you want to force applications to close when you shut down or restart the computer, and then click OK.


Note

• To open Computer Management, click Start, and then click Control Panel. Click Performance and Maintenance, click Administrative Tools, and then double-click Computer Management.

• You must be recognized as an administrator or a member of the

Tuesday 15 January 2008

Save Site as Template Link does not appear in Sharepoint

If the Save Site as Template link does not appear under the Look and Feel tab of site settings, then go to the site settings of the site that you want to save as a template and replace the page name to savetmpl.aspx.

for Example

Change http://ServerName/SiteName/_layouts/settings.aspx
to
http://ServerName/SiteName/_layouts/savetmpl.aspx

ListViewWebPart - Adding Announcements List programatically to sharepoint page

While working with a listviewwebpart in sharepoint the name property should be set to the GUID of the List. The key thing to note is it i s not enough to set the value as GUID.Tostring() but as it is case sensitive it should be set as spListGuid.ToString("B").ToUpper();

The full code is below

ListViewWebPart listWebPart = new ListViewWebPart();
listWebPart.ListName = spListGuid.ToString("B").ToUpper();
webPartManager.AddWebPart(listWebPart, "RightColumnZone", 0);

Monday 14 January 2008

Cannot open database requested in login '' Error in Moss 2007

The error message below is displayed when trying to view a page in MOSS 2007 that is checked out by another user.

Server Error in '/' Application.
--------------------------------------------------------------------------------

Cannot open database requested in login 'MOSS2007_SSP1_DB_DEV'. Login fails.
Login failed for user 'EC\WMSPSGBWA001003$'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Cannot open database requested in login 'MOSS2007_SSP1_DB_DEV'. Login fails.
Login failed for user 'EC\WMSPSGBWA001003$'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[SqlException (0x80131904): Cannot open database requested in login 'MOSS2007_SSP1_DB_DEV'. Login fails.
Login failed for user 'EC\WMSPSGBWA001003$'.]
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +437
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.SqlClient.SqlConnection.Open() +111
Microsoft.Office.Server.Data.SqlSession.OpenConnection() +621
Microsoft.Office.Server.Data.SqlSession.ExecuteNonQuery(SqlCommand command) +214
Microsoft.Office.Server.Administration.SharedObjectStore.Initialize() +269
Microsoft.Office.Server.Administration.SharedObjectStore.GetObject() +384
Microsoft.Office.Server.Administration.SharedResourceProvider.Microsoft.Office.Server.Administration.ISharedObjectStore.GetObject() +122
Microsoft.Office.Server.Administration.SharedApplicationCollection`1.GetValue(SharedResourceProvider sharedResourceProvider) +118
Microsoft.Office.Server.Administration.SharedApplicationCollection`1.get_Item(SharedResourceProvider sharedResourceProvider) +30
Microsoft.Office.Server.ServerContext.GetApplication(String name) +174
Microsoft.Office.Server.ServerContext.GetApplication() +87
Microsoft.Office.Server.ServerContext.get_UserProfileApplication() +42
Microsoft.Office.Server.UserProfiles.UserProfileManager.get_m_Site() +49
Microsoft.Office.Server.UserProfiles.UserProfileManager.get_IsSiteAdmin() +62
Microsoft.Office.Server.UserProfiles.UserProfileManager..ctor(ServerContext serverContext, Boolean IgnoreUserPrivacy, Boolean backwardCompatible) +348
Microsoft.Office.Server.UserProfiles.UserProfileManager..ctor(ServerContext serverContext) +55
Microsoft.SharePoint.Publishing.WebControls.ConsoleUtilities.GetPageCheckedOutMessage(String userLoginName, String userName, String userEmail) +923
Microsoft.SharePoint.Publishing.WebControls.ConsoleDataSource.OnPreRender(EventArgs e) +1025
System.Web.UI.Control.PreRenderRecursiveInternal() +77
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42