Friday, September 12, 2008

Debug SharePoint

SharePoint Portal Server Support Report Tool (SPSReport)
The SPS Reporting Tool is utilized to gather detailed information regarding a systems current configuration. The data collected will assist the Microsoft Support Professional with fault isolation. The reporting tool DOES NOT make any registry changes or modifications to the operating system.
http://www.codeplex.com/spsreport/Release/ProjectReleases.aspx?ReleaseId=5706

WinDbg
http://www.microsoft.com/whdc/devtools/debugging/install64bit.mspx

Fiddler
HTTP traffic monitors for IE
http://www.fiddler2.com/fiddler2/

Live HTTP Headers 0.14
HTTP traffic monitors for FireFox
https://addons.mozilla.org/en-US/firefox/addon/3829

SharePoint SUSHI
http://www.codeplex.com/sushi

Logging Solution ( Multiple options )
http://hristopavlov.wordpress.com/sptraceview/
http://www.codeplex.com/wssmosslogfilereader/

SpsDev.Com ULS Log Reader
http://www.spsdev.com/ulsreader.aspx

SharePoint Log Viewer
http://www.codeplex.com/SPLogViewer

SharePoint Logging Spy
http://www.codeplex.com/sharepointloggingspy

Business Data Catalog Sample File

<LobSystem
Type="Database"
Version="1.0.0.01"
Name="AdventureWorks"
xmlns="http://schemas.microsoft.com/office/2006/03/BusinessDataCatalog">


<AccessControlList>
<AccessControlEntry Principal="domain\you">
<Right BdcRight="Execute"/>
<Right BdcRight="Edit"/>
<Right BdcRight="SetPermissions"/>
<Right BdcRight="SelectableInClients"/>
</AccessControlEntry>
<AccessControlEntry Principal="domain\BDCUsers">
<Right BdcRight="Execute"/>
<Right BdcRight="SelectableInClients"/>
</AccessControlEntry>
</AccessControlList>


<LobSystemInstances>
<LobSystemInstance Name="AdventureWorksDB">
<Properties>
<Property Name="AuthenticationMode" Type="System.String">PassThrough</Property>
<Property Name="DatabaseAccessProvider" Type="System.String">SqlServer</Property>
<Property Name="RdbConnection Data Source" Type="System.String">SQLServerMachineName</Property>
<Property Name="RdbConnection Initial Catalog" Type="System.String">AdventureWorks</Property>
<Property Name="RdbConnection Integrated Security" Type="System.String">SSPI</Property>
</Properties>
</LobSystemInstance>
</LobSystemInstances>

<Entities>
<Entity Name="Customer">

<Properties>
<Property Name="Title" Type="System.String">Name</Property>
</Properties>

<Identifiers>
<Identifier Name="CustomerID" TypeName="System.Int32"/>
</Identifiers>


<Methods>
<Method Name ="GetCustomers">
<Properties>
<Property Name="RdbCommandText" Type="System.String">
SELECT CustomerID,LastName + ', ' + FirstName as Name,Phone, EmailAddress
FROM Sales
</Property>

<Property Name="RdbCommandType" Type="System.String">Text</Property>
</Properties>

<Parameters>
<Parameter Direction="Return" Name="Customers">
<TypeDescriptor TypeName="System.Data.IDataReader, System.Data, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" IsCollection="true" Name="CustomerDataReader">
<TypeDescriptors>
<TypeDescriptor TypeName="System.Data.IDataRecord, System.Data,Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Name="CustomerDataRecord">
<TypeDescriptors>
<TypeDescriptor TypeName="System.Int32" IdentifierName="CustomerID" Name="customerID" />
<TypeDescriptor TypeName="System.String" Name="Name" />
<TypeDescriptor TypeName="System.String" Name="Phone" />
<TypeDescriptor TypeName="System.String" Name="EmailAddress" />
</TypeDescriptors>
</TypeDescriptor>
</TypeDescriptors>
</TypeDescriptor>
</Parameter>
</Parameters>

<MethodInstances>
<MethodInstance
Name="CustomerFinderInstance" Type="Finder" ReturnParameterName="Customers" ReturnTypeDescriptorName="CustomerDataReader" />

</MethodInstances>

</Method>
</Methods>
</Entity>
</Entities>

</LobSystem>
Articles:
http://msdn.microsoft.com/en-us/office/bb251754.aspx

What is Business Data Catalog ?

Business Data Catalog, a new feature introduced in Microsoft Office SharePoint Server 2007, provides an easy way to integrate business data from back-end server applications, such as SAP or Siebel, within Office SharePoint Server 2007 without writing any code.Business Data Catalog provides built-in support for displaying data from databases and Web services. That is, you can use Business Data Catalog to display data from your SAP, Siebel, or other line-of-business (LOB) application via Web services or databases.

Wednesday, September 10, 2008

Scripting STSADM commands

pushd %programfiles%\common files\microsoft shared\web server extensions\12\bin

//call the STSADM commands here

popd
OR
SET PATH=%PATH%;%programfiles%\common files\microsoft shared\web server extensions\12\bin

//call the STSADM commands here

Custom Content Page with Code

Scenario:
You want to add a new custom Content Page with some code. You have two different choices to do that, inline code or code behind.

Recommended:
Go for Code Behind. Content Page lives in SharePoint Content Database and can be customized using SPD. Inline script will only work when the page is uncustomized, but once it is customized, SharePoint's safe mode parser will block the page from being executed.

Article:
http://www.andrewconnell.com/blog/articles/UsingCodeBehindFilesInSharePointSites.aspx

Getting all the group for a particular web


public IList<string> GetAllUserGroups(string url)
{
IList<string> groupList = new List<string>();

using (SPSite site = new SPSite(url))
{
SPGroupCollection groups = site.RootWeb.SiteGroups;

foreach (SPGroup g in groups)
{
groupList.Add(g.Name);
}
}

return groupList;
}

Modifying Content Query Webpart programatically

Scenario:
You want to move your CQWP from one environment to another. Suggested way is to configure them in DEV environment and Export them. But painful aspect of this process is that with most of the Out of Box webparts they carry LISTGUIDs which are not available in next environment.

Steps:
1. Configure CQWP with filters and List you want to attach
2. Export the WEBPART file and open it using Visual Studio or Notepad
3. Look for ListGuid property and delete it all together.( Look for remarks )
4. Now Import it in new environment
5. Set List either manually in new environment or Set it programatically as shown , i created a layout page to configure the webparts )

ConfigureCQWP.ASPX ( 12/Template/Layouts/Client/):

<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, 
Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" %>

<%@ Import Namespace="Microsoft.SharePoint" %>

<script runat="server">
protected override void OnLoad(EventArgs e)
{

try
{
SPWeb web= SPContext.Current.Web;
lblSiteTitle.Text = site.Title;

string sDocumentLibraryName = "Shared Documents";
Guid listID = default(System.Guid);

bool bFound = false;

foreach (SPList list in web.Lists)
{
if (list.Title.ToLower() == sDocumentLibraryName.ToLower())
{
listID = list.ID;
bFound = true;
break;
}
}

if (bFound)
{

web.AllowUnsafeUpdates = true;

Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager WPMgr = web.GetLimitedWebPartManager("default.aspx", PersonalizationScope.Shared);

foreach (WebPart wp in WPMgr.WebParts)
{
ContentByQueryWebPart CQWPart = wp as ContentByQueryWebPart;
if (CQWPart != null)
{
CQWPart.WebUrl = site.ServerRelativeUrl;
WPMgr.SaveChanges(CQWPart);
//CQWPart.ListName = sDocumentLibraryName;
//CQWPart.ListGuid = listID;
//CQWPart.Title = "NewP";
}
}
lblSiteStatus.Text = "Configured Sucessfully...";
}
else
{
lblSiteStatus.Text = "Some Error occured during WebPart configuration, Please configure manually...";
}
}
catch (Exception ex)
{
lblSiteStatus.Text = "Error :" + ex.ToString();
}
}
</script>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<table border="1" cellpadding="4" cellspacing="0" style="font-size: 12">
<tr>
<td>
Site Title:</td>
<td>
<asp:Label ID="lblSiteTitle" runat="server" /></td>
</tr>
<tr>
<td>
Site ID:</td>
<td>
<asp:Label ID="lblSiteStatus" runat="server" /></td>
</tr>
</table>
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">Configure Content Query Webpart</asp:Content>
<asp:Content ID="PageTitleInTitleArea" runat="server" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea">Configure Content Query Webpart
</asp:Content>
Remarks:
The WebUrl property determines the ContentByQueryWebPart object's mode is determined by the WebUrl, ListGuid, and ListName properties.

-- If the WebUrl, ListGuid, and ListName properties are set, the mode is List.

-- If the WebUrl is set and ListGuid and ListName are empty, the mode is Web.

-- If WebUrl, ListGuid and ListName are empty, the mode is Site Collection.

-- If both ListGuid and ListName properties are set, ListGuid takes precedence.