Friday, October 03, 2008

IsInteger Function in C#

        public bool IsInteger(string strNumber)
        {
            Regex objNotIntPattern = new Regex("[^0-9-]");
            Regex objIntPattern = new Regex("^-[0-9]+$|^[0-9]+$");
            return !objNotIntPattern.IsMatch(strNumber) &&
                    objIntPattern.IsMatch(strNumber);
        }

Wednesday, September 03, 2008

Access is denied. Check that the Default Content Access Account has access to this content

This is one of most common issue reported by people on the internet. I also came across this issue and able to solve after doing deep dive into MOSS search.
If you are facing this issue, look for following:

1. Check default content account have read permission to the site. Go to Central Admin-> Application Management -> Policy for web application. Confirm that the default content account have full read permission to the web application

2. Try changing the host file to crawl the local server to eliminate network issues. This is just for testing and should not be done in live environment

3. Make sure none of Web front end server have spaces in their custom headers. Seems crawler don't like spaces in custom headers

4. Finally, this took us a weekend to note. Someone removed the following site permissions "Use Remote Interfaces" and "Use Client Integration Features" to stop developer to connect to MOSS site using SharePoint Designer. This BROKE THE SEARCH CRAWL. So, make sure for your application these permission are enabled. Go to Central Admin-> Application Management -> User Permissions for Web Application to verify this.

Saturday, August 16, 2008

Issue searching for custom profile property

You have added a custom property "Location" in User Profile. When you try to do a search with keyword "india" (there are some users having India as their location), it does not return the people records we expect. However, if you do a by property search by "location:india", it can return the people records.

Resolution:

Turn back on the option "Include values for this property in the search index" option behind "Location" crawled property

1. Open SSP Admin home page
2. Go to Search settings
3. Click Metadata property mappings
4. Click Crawled Properties link
5. Choose the People category (folder)
6. Locate Expertise, Edit/Map Property
7. At the bottom of the page, there should be check box saying "Include values for this property in the search index", click to select it.
8. Force an incremental crawl. If this does not help, please try to do a full crawl.

Monday, June 30, 2008

LDAP User Profile Connection Horror

Whenever you go to Edit Connection page while editing an import connection, make sure to re-enter the password of user again. MOSS for some reason changes the password and you will be prompted with error like--

The query is not valid based on the specified search base and search filter.

:-(

LDAP Connection in UserProfile

To create an import connection to LDAP, modify the web.config file of your SSP web site.
Under section add,



Make changes as per your enviornment.

Now, on Edit Connection page in MOSS, Enter provider name as LdapMembership and press ok

CustomWebPart Web Part: Cannot import CustomWebPart Web Part.

Check if the webpart class is declared public and any assembly referenced by project exists

Tuesday, June 24, 2008

People Crawl: Error in PortalCrawl Web Service

When I tried to crawl my content, I received following error:

sps3://SERVERNAME
Error in PortalCrawl Web Service

So people aren't crawled.


If I create an "root" site collection, so in http://SERVERNAME, the error disappears and people is crawled again.

Monday, June 23, 2008

Fix for Content type '0x01010007FF3E057FA8AB4AA42FCB67B453FFC100E214EEE741181F4E9F7ACC43278EE811' not found

While creating a new page in a collbartion portal, you might come with this error.

This ContentTypeID points to the "PublishingResources" feature.

You will need to activate this feature by running STSADM. The command is

STSADM -o activatefeature -name PublishingResources -url http://MOSS_URL

Tuesday, April 15, 2008

SharePoint administrative and development Tool

SharePoint SUSHI

SUSHI is a powerful, user-friendly SharePoint application enabling you to accomplish common SharePoint administrative and development tasks. You can think of SUSHI as a Swiss army knife for SharePoint.
What does the name SUSHI stand for?
SUSHI = SharePoint Utility with a Smart, Helpful Interface

Link

Wednesday, April 09, 2008

Display raw XML returned by SharePoint Search

On Search page, modify the XSLT of "Search Core Results" web part to

#?xml version="1.0" encoding="UTF-8"?>
#xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
#xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
#xsl:template match="/">
#xmp>
#/xsl:template>
#/xsl:stylesheet>


Replace # with <

Thursday, April 03, 2008

NumberToWord Function

private string[] _englishDigitMatrix = new string[]{"", "Second", "Third", "Fourth","Fifth", "Sixth", "Seventh", "Eighth","Nineth"};

public string changeNumericToWords(int number)

{

      string ret = _englishDigitMatrix.GetValue(number - 1).ToString();

       return ret;

}

 

Wednesday, April 02, 2008

Using Database Mirroring with Office SharePoint Server and Windows SharePoint Services

Database mirroring is a new technology in Microsoft® SQL Server™ 2005 database software that can deliver high availability and high performance solutions for database redundancy. In database mirroring, transactions are sent directly from a principal database and server to a mirror database and server whenever the principal database’s transaction log buffer is written to disk. This technique can keep the mirror database nearly up to date with the principal database. You can optionally use a third server, a witness server, to enable automatic failover from the principal server to the mirror server.
The update includes more prescriptive information on the type of supported topologies. It also recommends SQL connection aliasing for failover within a farm.

http://go.microsoft.com/fwlink/?LinkId=83725&clcid=0x409

SharePoint Branding Tool (Themes, Master pages, Site Logos...)

This tool can be used apply the following actions for multiple Site Collections, and Child Sites:

modify Themes
modify MasterUrl (Master Page)
modify CustomMasterUrl (System Master Page)
modify SiteLogoUrl (Site Logo)
modify SiteLogoDescription (Site Logo Alternative Text)
modify AlternateCssUrl (Custom CSS Style Sheet)
view various properties of sites and themes at a glance
Selection of sites can be filtered by the Site Template used.

http://www.codeplex.com/BrandingTool

Tuesday, April 01, 2008

Add White space in XSLT

Add and display Custom Column in SharePoint Search Result

The results in SharePoint Search are displayed by Search Core Results Web Part. This web part have “Selected Columns” property under “Results Query Options” category which contains an XML string that defines all of the columns that are to be displayed in the search results.

The following is the default list of columns shown in the search results:



Now, we will create a new mapped property named “ListItemId”. Managed properties map to one or more of the crawled properties. They group together the related crawled properties and expose them to the user

The Search Settings in the administrative site of the Shared Services Provider has a Metadata Property Mappings link. Clicking on it brings you to the Metadata Property Mappings page




Now, click on “New Managed Property”
Enter, the property name as: “ListItemId” and make sure you select “Integer” and “Allow this property to be used in scopes”
Note: By default “Type of Information “is set to Text




Now, you need map to the crawled properties. The Add Mapping button pops up a dialog box where you can navigate through all of the crawled properties and select the ones you want to map to the managed property
Enter ows_id and press Find, select the property and click OK.




Note: If you didn’t selected “Type of Information “as Integer, SharePoint is not able to search this property.
Now, start a full Crawl of your content and you should now see your List Item in search results

Wednesday, March 26, 2008

Use of Today field in SharePoint Formula

You can't use Today field in Sharepoint calculated field. The workaround is:

Create a custom column named "Today" with type as Date
Now, create a custom field and use above created field in formula
Delete the above created "Today" field.

The Sharepoint will work fine as it start using inbuild Today value for the formula

Install SharePoint workflow without MSI

To install a custom workflow developed using Visual studio, follow the steps given below-

-- Build your assembly
Drag and drop assembly to C:\Windows\Assembly. Right click and select the properties. Note down the pubclickeytoken for your assembly

-- Create a Feature.xml



-- Create a Workflow.xml



Change Association_FormURN based on your InfoPath Properties


-- Create a feature in SharePoint

Create a folder say "CUSTOM_WORKFLOW" in "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATES\FEATURE"
Copy workflow.xml and feature.xml to this folder

-- Install and Activate the feature

Create a batch file with following content in your FEATURE folder
@ECHO OFF

ECHO.
ECHO Activiating and installing the feature...
ECHO.

SET STSADMDIR="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN"

%STSADMDIR%\STSADM.EXE -o installfeature -filename CUSTOM_WORKFLOW\feature.xml -force
%STSADMDIR%\STSADM.EXE -o activatefeature -filename CUSTOM_WORKFLOW\feature.xml -url http://SHAREPOINT_URL

ECHO.
ECHO Resetting IIS
ECHO.

IISRESET

-- Run the batch file

Hurry, you could now see your workflow in Workflow settings of List

Thursday, March 20, 2008

Testing XSLT using VS2005

In past, I use to write code using XMLTransform to test an xslt. I found a better way last night, where you could use ASP.NET 2.0 XML control.
Steps:
Create a new ASP.NET web application using VS2005
Add your source xml file to the project
Add a new xslt file to the project using ADDITEM
On the default page, add the XML control from the toolbox
Set the TransformSource property of xml control to xml file
Set the TransformSource property of xml control to xslt file

Make changes in the xslt file and run the web application and check the result

Wednesday, March 19, 2008

Failed to determine definition for Feature with ID

I recently replicated my development server from the production server where changes are done by end users using STSADM back and restore process.

When I tried to edit my search page on development machine, I got error "An unexpected error has occurred."
To diagnosis this, I look at the log file created at "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS".
The error logged was “Failed to determine definition for Feature with ID 'd75b8655-0098-40ac-aad6-7578d9d93901'. Skipping this feature for element querying consideration.”

Search this feature ID on production server at location “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES” and found that it is for old custom workflow which was still on Production as there are existing items using it. But this has been replaced with new one on development and as such was not found.

This error will also occur if you have an Enterprise license on Production and Standard on Development as there will be some of the feature not available on the Development

"Search Scope" not visible in SharePoint 2007

You created a new search scope in SharePoint 2007 using Shared Services Administration -> Search Settings -> Scopes and found that its not visible on the site.
This new scope NEED to be visible via the Site Settings. Go to your site collection, click on Site Actions -> Site Settings -> Search Scopes.
Click on "Display Group" and select the display scope


Wednesday, March 05, 2008

Expose Readonly public property of DataContract in WCF

To expose readonly property in WCF using DataContract, add DataMember to the private property

[DataMember]
private string name;

public string Name
{
get{ return name;}
}

SharePoint Web part error "Object reference not set to an instance of an object"

I was getting "Object reference not set to an instance of an object" error while previewing a web part in web part gallery area.
Found that web part's CreateChildControls function is called even when you are previewing. This function was throuwing an error as in the code accesssing value of current list item using SPContext.Current.ListItem.

Added the following code and it worked fine
base.CreateChildControls();
if (SPContext.Current.ListItem == null)
return;

Wednesday, February 20, 2008

Start a SharePoint workflow using code

Imagine you already have a SharePoint list with thousands of items and now want to associate a custom workflow with the list.
How will you go and run Workflow on all the existing items as Microsoft SharePoint don't provide any option to run workflow on existing items.
The solution: Run the workflow against each list item via the code

First Get the Workflow Guid and then Create a workflow association object. Start the workflow from the site passing the list item and the workflow association object.

To get a workflow Guid:
Go to List Settings- Workflow Setting and click on the workflow. From URL get the targetId value.

Create a Visual Studio 2005 Console project
Add Reference to SharePoint Library
Replace content of program.cs with the following code--


using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;

using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;

class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Started...");
Console.WriteLine("Read value from config list");
// Read from App.Config file
// Site URL
string SiteName = ConfigurationManager.AppSettings["SiteName"];
// Workflow Guid
string WorkFlowGuid = ConfigurationManager.AppSettings["WorkflowGuid"];
// List Name
string ListName = ConfigurationManager.AppSettings["ListName"];
// Query used to filter the items on which WorkFlow needs to be run
string Query = ConfigurationManager.AppSettings["Query"];
// Get Html Decoded Guid
string decode = ConfigurationManager.AppSettings["DecodeGuid"];
if (decode == "1")
WorkFlowGuid = DecodeString(WorkFlowGuid);


Console.WriteLine("Read site details");
SPSite site = new SPSite(SiteName);
SPWeb web = site.OpenWeb();
SPList list = web.Lists[ListName];

Console.WriteLine("Read workflow details");
SPWorkflowAssociation workflowAssociation = list.WorkflowAssociations[new Guid(WorkFlowGuid)];

Console.WriteLine("Get items");
SPListItemCollection items = null;
if(Query.Length > 0) // filtered
{
SPQuery query = new SPQuery();
query.Query = Query;
items = list.GetItems(query);
}
else
items = list.Items; // all items

Console.WriteLine("Looping items");

foreach (SPListItem item in items)
{
if(item.Workflows.Count == 0)
{
// Start if already not started
site.WorkflowManager.StartWorkflow(item, workflowAssociation,
workflowAssociation.AssociationData, true);
}
}
Console.WriteLine("Done");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
finally
{
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
}
}

static string DecodeString(string sStr)
{
string sChars = " ,',!,#,$,%,&,(,),/,:,;,[,\\,],^,`,{,|,},+,<,=,>,-";
string sANSICodes = "+,%27,%21,%23,%24,%25,%26,%28,%29,%2F,%3A,%3B,%5B,%5C,%5D,%5E,%60,%7B,%7C,%7D,%2B,%3C,%3D,%3E,%2D";
string[] aChars = sChars.Split(",".ToCharArray());
string[] aANSICodes = sANSICodes.Split(",".ToCharArray());
for (int i = 0; i <= aChars.GetUpperBound(0); i++)
{
if (sStr.IndexOf(aANSICodes[i]) > -1)
sStr = sStr.Replace(aANSICodes[i], aChars[i]);
}
return sStr;
}
}

********************Config File*********************


*****************************************

The code logic-

Read values from the app.config file
If WorkflowGuid is encoded as in the config file, decode the Guid
Get workflowassociated with this WorkFlowGuid
Based on SharePoint Query, get the items
Loop through the items and if no workflow started for that item. Start the workflow

Monday, February 18, 2008

Singleton Class WinForm\WebForm

If you use static object in ASP.NET application, this works as Application object and is shared across all sessions. To create a user visible properties, we use session objects. A better way of using this is to use Singelton class. This class creates only one object and same object is refeneced again without new creation. The following code could be used to create a common Singleton class for windows and web application.

using System;
using System.Data;
using System.Configuration;
using System.Web;

namespace Common
{
///


/// Summary description for SessionConfig
///

public class StateData
{

#region PROPERTIES
string currentUser;
public string CurrentUser
{
get { return this.currentUser; }
set { this.currentUser = value; }
}
#endregion

private static StateData oInstance;

protected StateData()
{
}


public static StateData Instance
{
get
{
// If called from windows, this would be null. Use Static object then
if (System.Web.HttpContext.Current == null)
{
if (oInstance == null)
{
oInstance = new StateData();
}
return oInstance;
}
if (HttpContext.Current.Session == null || HttpContext.Current.Session["SharedData"] == null)
HttpContext.Current.Session.Add("SharedData", new StateData());


return (StateData)System.Web.HttpContext.Current.Session["SharedData"];
}
}

}
}

Hide\Show Column in Sharepoint Form

You don't need desugner to hide or show a column in Display, Edit and New form of Sharepoint List. You could use Sharepoint Objects to set this programmatically-

Create a console application and Reference SharePoint Library-
The code will be
SPSite site = new SPSite(SiteName);
SPWeb web = site.OpenWeb();
SPList list = web.Lists[ListName]; // Get teh list
// Colname = Column to hide\show
list.Fields[ColName].ShowInEditForm = ShowInEditForm;
list.Fields[ColName].ShowInDisplayForm = ShowInDispForm;
list.Fields[ColName].ShowInNewForm = ShowInNewForm;
list.Fields[ColName].Update();