Monday, November 24, 2008

Unit Testing in Sharepoint

Typemock are offering their new product for unit testing SharePoint called Isolator For SharePoint, for a special introduction price. it is the only tool that allows you to unit test SharePoint without a SharePoint server. To learn more click here.
The first 50 bloggers who blog this text in their blog and tell us about it, will get a Full Isolator license, Free. for rules and info click here.

Tuesday, November 18, 2008

How to get physical path of 12 in code.

//use reference to below
using System.Web;


string strPAthTo12hive =HttpContext.Current.Server.MapPath(@"~\_layouts/1033/PurchaseLinks.js");

Sunday, November 16, 2008

Infopath form closes as soon as you open it in sharepoint workflows.

I had a strange error as soon as a VS 2005 workflow that I wrote for Sharepoint would try open an InfoPath form it would close without giving any errors. The only error was the following in the logs: EventType ulsexception12, P1 w3wp.exe, P2 6.0.3790.1830, P3 42435e74, P4 microsoft.office.infopath.server, P5 12.0.6219.0, P6 4845c8d9, P7 9573, P8 194, P9 fileloadexception, P10 82lz.
To resolve this issue ensure that there are no empty parameter floating around in the ItemMetadata.xml files that the InfoPath form is not using. Once I removed all unwanted parameters the issue was resolved.

ErrHow to resolve Error: ".asmx was not recognized as a known document type."

If you get an error below when trying to add a reference to webservice:
The document at the url http://localhost:81/PWA/_vti_bin/psi/project.asmx was not recognized as a known document type.The error message from each known type may help you fix the problem:- Report from 'DISCO Document' is 'Root element is missing.'.- Report from 'WSDL Document' is 'The document format is not recognized (the content type is 'text/html; charset=utf-8').'.- Report from 'XML Schema' is 'The document format is not recognized (the content type is 'text/html; charset=utf-8').'.- Report from 'http://localhost:81/PWA/_vti_bin/psi/project.asmx' is 'The document format is not recognized (the content type is 'text/html; charset=utf-8').'.
Type ?wsdl after the webservice URl and the error should be resolved or alternativly click on the service description in the summary window and the Error should be resolved. Below is image to describe the process.




Thursday, October 23, 2008

System.InvalidOperationException: The event receiver context for Workflow is invalid.

If the below error come up while creating sharepoint worflow:

System.InvalidOperationException: The event receiver context for Workflow is invalid. at Microsoft.SharePoint.SPEventReceiverDefinition.ValidContext() at Microsoft.SharePoint.SPEventReceiverDefinition.ValidReceiverFields() at Microsoft.SharePoint.SPEventReceiverDefinition.GetSqlCommandToAddEventReceivers(IList`1 erds) at Microsoft.SharePoint.Workflow.SPWinOESubscriptionService.CommitNewSubscriptions(Transaction txn, IList`1 erds)


The cause of this is either you didn't associate properties for TaskID, TaskProperties, or CorrelationToken activity to your createtask token. The other scenario that this comes up is when you don't assign a unique id to your Taskid. If you code looks like below:
public Guid createTaskInitiation_TaskId = default(System.Guid);
to
public Guid createTaskInitiation_TaskId = Guid.Newguid();
This should resolve the error.

Monday, October 13, 2008

How to prevent code from crashing when adding an event handler to a documentlibrary.

I had the follwing issue:

I added an event handler to a document library. Every time i added a new document the eventhandler would run fine but when a user had entered metedata againt a doucument and pressed ok, sharepoint would crash. The reason behind this was, I was tring to update an item when there was already an update in progress. I fixed the issue by running the follwing update code.

DisableEventFiring();
item.SystemUpdate(false);
EnableEventFiring();

Monday, August 18, 2008

Some issue with Title when generating a Excel file from a crystal report.

Two issues I spent some time resolving was:
  1. When an excel file was generated from crystal reports some times the assosciated title for the column does not appear correctly.
  2. Every time I generated an Excel file from crystal reports. The titles in the excel file were never in the same order as I had created them in crystal report.


Fig 1 : This will not work

Resolution to the issues above:
  1. For all the columns that you require to appear in excel they must touch the details section.
  2. For the Titles to be in the same order as in crystal,all fields must have the same height. For some reason the order seems to be based on height.
Below is the corrected crystal report Image.


Fig 2. This will work

Wednesday, August 6, 2008

How to view GAC Folders.

The following command will allow users to see the folders within the "c:\windows\assembly" or GAC folder.

regsvr32 /u c:\WINDOWS\mICROSOFT.net\Framework\v2.0.50727\shfusion.dll

Run the below command to restore your site back to GAC view.

regsvr32 c:\WINDOWS\mICROSOFT.net\Framework\v2.0.50727\shfusion.dll

Thursday, July 24, 2008

MOSS: Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))

This Error occurs when adding a wepart to page because the webpart is disposing the spsite or spweb object. If your code looks like below:


using (SPWeb web = SPContext.Current.Web)
{
//some coded here
}


Change it to the format below:


SPWeb web = SPContext.Current.Web;
// your code here

And the Exception (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION)) should be resolved.