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();