Thursday, August 12, 2010

SharePoint 2007 CSS Bible

Click here for Heather Solomon's Sharepoint 2007 CSS bible
http://www.heathersolomon.com/content/sp07cssreference.htm

Wednesday, August 11, 2010

Get the GUID of a SharePoint List

I usually adopt this easy way of finding the GUID of a SharePoint List:
Go to the List or Library settings --> then right-click on the “Audience targeting settings” or “Information management policy settings” links and choose Copy Shortcut.

Paste this Copied Shortcut in a notepad.
You get a URL like this:

http://stdemo:36068/eaTest/_layouts/ListEnableTargeting.aspx?List={d50cb13c-4cf2-4569-9e5c-b9363c39bdb9}
The one in bold red between the braces is your List GUID

Updating a SharePoint List Item with a LookUp Column

I got this error
"Invalid data has been used to update the list item. The field you are trying to update may be read only" when I was trying to Update a List with a LookUp column called "Group".
This column looked up values from another list. The solution was to update the ID of the lookup column and it worked .
Here is the code snippet for the above:
SPList lst = listWeb.Lists[listName];
//Get the items of the list
SPListItem item = lst.Items.GetItemById(ItemID);

//Set the item of the list to the corresponding Group Name from the "LookUp" list .Note Group1 is the Internal name of the column Group
item["Group1"] = intGroupID;
listWeb.AllowUnsafeUpdates = true;
//The argument false for SystemUpdate informs the SPObject Model not to increment versions
item.SystemUpdate(false);
listWeb.AllowUnsafeUpdates = false;

Monday, August 2, 2010

Add Ajax 3.5 support in SharePoint

Here is an excellent link to add Ajax 3.5 support in SharePoint 2007. The author has detailedd the changes to the web.config

http://www.zimmergren.net/archive/2008/09/22/how-to-get-up-and-running-with-net-3-5-in-your-sharepoint-environment.aspx

Thursday, June 17, 2010

C# ,Impersonation for Cross Domain access

C# , Impersonation to write to a file outside the domain in a shared network location
I had a scene wherein I had to write to a file in a network location outside the domain using a domain Id.
The regular values for LogonUser() didn't work for me. So I changed the values for Cross Domain access.

This is the snippet that was different:
enum LogonType
{
Interactive = 2,
Network = 3,
Batch = 4,
Service = 5,
Unlock = 7,
NetworkClearText = 8,
NewCredentials = 9
}
enum LogonProvider
{
Default = 0,
WinNT35 = 1,
WinNT40 = 2,
WinNT50 = 3
}
LogonUser(
userName,
domain,
password,
(int)LogonType.NewCredentials,
(int)LogonProvider.WinNT50,

//LOGON32_LOGON_INTERACTIVE,
//LOGON32_PROVIDER_DEFAULT,
ref token) != 0)


Here is my complete code:
namespace Tools
{
#region Using directives.
// ----------------------------------------------------------------------

using System;
using System.Security.Principal;
using System.Runtime.InteropServices;
using System.ComponentModel;

// ----------------------------------------------------------------------
#endregion

/////////////////////////////////////////////////////////////////////////

///
/// Impersonation of a user. Allows to execute code under another
/// user context.
/// Please note that the account that instantiates the Impersonator class
/// needs to have the 'Act as part of operating system' privilege set.
///

///
/// This class is based on the information in the Microsoft knowledge base
/// article http://support.microsoft.com/default.aspx?scid=kb;en-us;Q306158
///
/// Encapsulate an instance into a using-directive like e.g.:
///
/// ...
/// using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) )
/// {
/// ...
/// [code that executes under the new context]
/// ...
/// }
/// ...
///
///
///

public class Impersonator :
IDisposable
{
#region Public methods.
// ------------------------------------------------------------------

///
/// Constructor. Starts the impersonation with the given credentials.
/// Please note that the account that instantiates the Impersonator class
/// needs to have the 'Act as part of operating system' privilege set.
///

/// The name of the user to act as.
/// The domain name of the user to act as.
/// The password of the user to act as.
public Impersonator(
string userName,
string domainName,
string password)
{
ImpersonateValidUser(userName, domainName, password);
}

// ------------------------------------------------------------------
#endregion

#region IDisposable member.
// ------------------------------------------------------------------

public void Dispose()
{
UndoImpersonation();
}

// ------------------------------------------------------------------
#endregion

#region P/Invoke.
// ------------------------------------------------------------------

[DllImport("advapi32.dll", SetLastError = true)]
private static extern int LogonUser(
string lpszUserName,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int DuplicateToken(
IntPtr hToken,
int impersonationLevel,
ref IntPtr hNewToken);

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool RevertToSelf();

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern bool CloseHandle(
IntPtr handle);

private const int LOGON32_LOGON_INTERACTIVE = 2;
private const int LOGON32_PROVIDER_DEFAULT = 0;
enum LogonType
{
Interactive = 2,
Network = 3,
Batch = 4,
Service = 5,
Unlock = 7,
NetworkClearText = 8,
NewCredentials = 9
}
enum LogonProvider
{
Default = 0,
WinNT35 = 1,
WinNT40 = 2,
WinNT50 = 3
}

// ------------------------------------------------------------------
#endregion

#region Private member.
// ------------------------------------------------------------------

///
/// Does the actual impersonation.
///

/// The name of the user to act as.
/// The domain name of the user to act as.
/// The password of the user to act as.
private void ImpersonateValidUser(
string userName,
string domain,
string password)
{


WindowsIdentity tempWindowsIdentity = null;
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero;

try
{
if (RevertToSelf())
{
if (LogonUser(
userName,
domain,
password,
(int)LogonType.NewCredentials,
(int)LogonProvider.WinNT50,

//LOGON32_LOGON_INTERACTIVE,
//LOGON32_PROVIDER_DEFAULT,
ref token) != 0)
{
if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
{
tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
impersonationContext = tempWindowsIdentity.Impersonate();
}
else
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
else
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
else
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
finally
{
if (token != IntPtr.Zero)
{
CloseHandle(token);
}
if (tokenDuplicate != IntPtr.Zero)
{
CloseHandle(tokenDuplicate);
}
}
}

///
/// Reverts the impersonation.
///

private void UndoImpersonation()
{
if (impersonationContext != null)
{ impersonationContext.Undo(); }
}

private WindowsImpersonationContext impersonationContext = null;

// ------------------------------------------------------------------
#endregion
}

/////////////////////////////////////////////////////////////////////////
}


For more details refer to :
http://www.cstruter.com/blog/270 which helped me .

Cheers!

Wednesday, June 16, 2010

Could not load type 'System.Web.UI.ScriptReferenceBase' from assembly 'System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf385

Ajax Error :
Could not load type 'System.Web.UI.ScriptReferenceBase' from assembly 'System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf385

I got this error while trying to use the Calendar control extender from the Ajax Control Toolkit for one of my textboxes.
First I got an error "sys.extended.ui is null or not an object" . To fix this, I changed the ScriptManager control to use the "ToolkitScriptManager" .
Once I did that I started getting this new error:Could not load type 'System.Web.UI.ScriptReferenceBase' from assembly 'System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf385
This got resolved once I installled .Net Framework 3.5 SP1.
That got my Ajax calendar control working like a charm ;)

Thursday, May 27, 2010

How to stop the !New icon from appearing in SharePoint Lists

I had this weird requirement from my client to remove the !New icon when a new document or item is added to a list.I followed these steps also outlined in the Microsoft support blog:

To stop the !New tag from appearing for new entries on your Windows SharePoint Services Web site, follow these steps, as appropriate for your version of SharePoint Services.
-Windows SharePoint Services 3.0 Web site
To stop the !New tag from appearing next to new entries on a Windows SharePoint Services 3.0 Web site, use the Stsadm.exe tool to change the "Days to Show New Icon" property to zero.

To do this, follow these steps:
1)Click Start, point to All Programs, point to Accessories, and then click Command Prompt.
2)Type the following commands, and then press ENTER after each command:
cd /d %programfiles%\Common Files\Microsoft Shared\Web Server Extensions\12\BIN
stsadm.exe -o setproperty -pn days-to-show-new-icon -pv 0 -url [Your Virtual Server's URL]

-Windows SharePoint Services Web site
To stop the !New tag from appearing next to new entries on a Windows SharePoint Services Web site, use the Stsadm.exe tool to change the "Days to Show New Icon" property to zero.

-To do this, follow these steps:
Click Start, point to All Programs, point to Accessories, and then click Command Prompt.
Type the following commands, and then press ENTER after each command:
cd /d %programfiles%\Common Files\Microsoft Shared\Web Server Extensions\60\BIN
stsadm.exe -o setproperty -pn days-to-show-new-icon -pv 0 -url [Your Virtual Server's URL]

-SharePoint Team Services Web site
To stop the !New tag from appearing next to new entries on a SharePoint Team Services Web site, use the Owsadm.exe tool to change the "New Item Display Cutoff" property to zero.

To do this, follow these steps:
Click Start, point to All Programs, point to Accessories, and then click Command Prompt.
Type the following commands, and then press ENTER after each command:
cd /d %programfiles%\Common Files\Microsoft Shared\Web Server Extensions\50\BIN
owsadm.exe -o setproperty -pn NewItemDisplayCutoff -pv 0 -p [Your Virtual Server's Port]

Tuesday, May 4, 2010

Setting up User Accounts in SharePoint 2007 :Useful Tips to share

  • A few years back,I was not sure of how User Accounts in SharePoint 2007 should be set up.
    Here is an useful extract I found to guide me:
    If you are installing SharePoint properly, you'll use the 'least privilege account principle'; this basically means that each distinct service inside the SharePoint farm will have its own domain user account. These accounts should have the minimum privileges that they need to perform their jobs. There is a great document which goes into detail on each different account (8+ accounts) here, however in summary, you should have the following accounts:
  • SQL Server Service Account: Account used by SQL to run all SQL services
  • Server Farm Account
  • SSP Service Account
  • Office SharePoint Server Search Account
  • Default Content Access Account
  • User Profile and Properties Content Access Account
  • Excel Services Unattended Account
  • One account per application pool: This is typically three accounts; SSPAdministration, MySite and your main 'Portal' or 'Intranet'.

For more information refer to this
http://technet.microsoft.com/en-us/library/cc263445.aspx

Tuesday, April 20, 2010

Infopath 2007 : Button Click event fired only once



I was trying to have multiple Rules on a Button on an InfoPath 2007 form. But I saw that only the rule on the first click is fired. All other rules don't get executed.

This is what I did to resolve the issue: Make that the checkbox that says "Stop Processing rules when this rule finishes " is checked for all the Rules to fire on Button click.

Make sure that on the Button properties --> Browser Forms you have the option of "Always" selected to send data to server on button click


This should make your button Rules fire on every click ! Happy Clicking!!

Infopath 2007 : Only first row of repeating table is committed to the database

This was a weird issue I came up with. Here is the background :

I was using Infopath 2007 to receive and submit data to a web service.

I had a repeating table bound to the receiving data and it displayed all the rows. But while submitting only the first row of the repeating table got committed.

Here is what I did to resolve the issue:

I had only one level in the receiving data schema a group called called TestData1 . Because of this the webservice was getting to the child level but not to the parent level. I added one more level in the webservice to change the schema to have TestData1 and then TestData1 again below it .

The web service was modified by adding a new class for the array which included one more level as below:


[WebMethod]

public TestDataArray getTestDataFilteredSorted(string USERNAME, string SORTCOLUMN, string SORTDIRECTION, string QUERY_NUM, string STUDY, string SITE, string QUERY_ID, string SUBJECT, string REVIEW_STATUS)
{
TestData filterTestData = new TestData();
filterTestData.QUERY_NUM = QUERY_NUM;

filterTestData.STUDY = STUDY;
filterTestData.SITE = SITE;
filterTestData.QUERY_ID = QUERY_ID;
filterTestData.SUBJECT = SUBJECT;
filterTestData.REVIEW_STATUS = REVIEW_STATUS;
TestDataArray filterTestDataArrayobj = new TestDataArray();
filterTestDataArrayobj.TestData1 = getTestDataFiltered2(USERNAME, filterTestData, SORTCOLUMN, SORTDIRECTION);

return filterTestDataArrayobj;
}
public class TestDataArray
{
public TestData[] TestData1;
}
Also note that while configuring the submit data connection make sure that you select the top group of TestData under field or group and Select "XML subtree" under include.
With all this configured you should be able to commit more than one row of the repeating table

Tuesday, March 16, 2010

SharePoint + InfoPath : An error occurred accessing data source

InfoPath forms and SharePoint are a deadly combination. Only with long association with these two does one understand how both need to be configured to work in harmony !

Here is an example of an error one gets many times while working with these two and webservices. I got "an error occurred while accessing a data source" while accessing my InfoPath forms on SharePoint 2007 site from any machine on the domain other than my SharePoint server where I had deployed my forms.

My forms were accessing a web service deployed onto the server and I was trying to access my SharePoint site from any other machine on the domain.

How I resolved it
Set the Security and Trust to "Domain" . It was set to "automatically determine security level".
you can do this by going to :
Tools -->Form Options -->Security and Trust

Cheers :)!

Friday, February 19, 2010

Portal Listings : migration nightmare from Sharepoint 2003 to 2007

A client of mine had extensively used a less known list of Sharepoint 2003 called "Portal Listings". I researched a lot and found that it was kind of an admin feature to regulate what content could be published and what should not be. A portal listing is typically a combination of a document library and a links list. The Link's list serves as the interface linking to documents and metadata at the back.

In our case, the portal listings were used in almost every page of the intranet we had to find a way to migrate it to the new SharePoint 2007. MOSS has nothing called portal listing, a partial replacement is the content by query webpart since it doesn't roll up content as easily as the portal listing.
We first used Quest to migrate the listings but it just wouldn't migrate.AvePoint from DocAve made progress by migrating the Portal Listing content to a Document Library and a link list.

So, now the challenge was to display the data the same way as the portal listing in 2003.

Since, the portal listing used to roll up content from sites and sub sites and have publishing features for every link (ie; start date,expiration date etc ) we needed a web part to have content roll up features and ability to filter on migrated metadata like start date, expiration date etc.

The Content By Query WebPart would roll up content by browsing to a list but the filters would work only if the columns are Site Columns. There is no way to directly make an existing column a Site Column so we had to find another way.

The Solution: Data View
  • Open the page in SharePoint Designer
  • Insert a Data View in a web part zone
  • Add a new data connection by connecting to the portal listing
  • You can change the UI, make it link to documents and have all the fun
The only change is that the UI is the SharePoint Designer interface and directly from the SharePoint Site.

However, it is a robust solution and replacement to the antiquated Portal Listing !#@@##

Monday, January 18, 2010

SharePoint element styles: a good link

http://sharepoint.microsoft.com/blogs/zach/Master%20Page%20Cheat%20Sheet/Forms/Master%20Page%20Elements.aspx