Archive for October, 2010

Create Custom Content Types in SharePoint 2010

Create Custom Content Types in SharePoint 2010

However, properties.Feature.Parent may not work for command line / stsadm / Visual Studio environment.

The following code snippet fix the problem


public static class Extensions
{
	public static SPWeb GetWeb(this SPFeatureReceiverProperties properties)
	{
	   SPWeb site;
	   if (properties.Feature.Parent is SPWeb)
	   {
		  site = (SPWeb) properties.Feature.Parent;
	   }
	   else if (properties.Feature.Parent is SPSite)
	   {
		  site = ((SPSite)properties.Feature.Parent).RootWeb;
	   }
	   else
	   {
		  throw new Exception("Error 192424234223442: Unable to retrieve SPWeb - this feature is not Site or Web-scoped.");
	   }
	   return site;
	}
}

Ref: 
http://blog.mattsmith.co.nz/Lists/Posts/Post.aspx?List=c7bdac80-1d4e-4732-9e67-cefde9c03d31&ID=51
http://msdn.microsoft.com/en-us/library/ff630942.aspx

Please noted that create custom content type for Workflow Task should inherit from “Workflow Task Task 0x010801” rather than “Task”

No Comments

SharePoint Define Custom Page for Custom Content Type Programatically

using (SPSite sitecollection = new SPSite("http://mysite"))
{
   using (SPWeb web = sitecollection.OpenWeb())
   {
      SPList list = web.Lists["mylist"];
      SPContentType ct = list.ContentTypes["my type"];
          
      ct.EditFormUrl = "_layouts/whatever/page.aspx";
      ct.DisplayFormUrl = "_layouts/whatever/page.aspx";
      ct.NewFormUrl = "_layouts/whatever/page.aspx";
      ct.Update();
      list.Update();
   }
}

No Comments

Creating Sequence Workflow for SharePoint 2010

Ref: http://msdn.microsoft.com/en-us/library/ee231590.aspx

Ref: http://msdn.microsoft.com/en-us/library/cc936631(v=office.12).aspx

Developing SharePoint 2007 Sequential and State Machine Workflows with Visual Studio 2008

Walkthrough_ Creating a Workflow with Association and Initiation Forms

No Comments

Turning off custom errors in _layouts Web.Config for debugging mode in SharePoint 2010

As a developer, one of the first things I do after I have setup a web application & site collection is:

Open the web.config (“C:\inetpub\wwwroot\wss\VirtualDirectories\<port>”) and set:

  1. Debug=”true” instead of the default of Debug=”false” (I do a find on “debug” in Visual Studio)
  2. CallStack=”true” instead of the default of CallStack=”false” (I do a find on “callstack” in Visual Studio)
  3. CustomErrors=”Off” instead of the default of CustomErrors=”On” (I do a find on “CustomErrors” in Visual Studio)

I would have expected this to be enough to catch all errors but when I tried to delete a content type that was probably in use, instead of getting the detailed message I was expecting, I ended up getting the infamous message telling me to change the customerrors setting in the web.config so that I can see the details:

Server Error in ‘/’ Application.


Runtime Error

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.
Details: To enable the details of this specific error message to be viewable on the local server machine, please create a <customErrors> tag within a “web.config” configuration file located in the root directory of the current web application. This <customErrors> tag should then have its “mode” attribute set to “RemoteOnly”. To enable the details to be viewable on remote machines, please set “mode” to “Off”.

As a refresher to anyone else that is running into this problem, there is another web.config in the _layouts directory (“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14”) where you need to turn the customErrors to be “Off”

Copied From: http://www.khamis.net/blog/Lists/Posts/Post.aspx?ID=12

No Comments

Resolving “the local SharePoint server is not available” Error

When doing development with SharePoint, it is pretty well-known that because you develop directly against the object model that the environment must have SharePoint present. However, at a client this morning I was helping to build some test and development environments and for some reason the error:
“the local SharePoint server is not available”
kept bubbling up, when clearly there was a local SharePoint instance present. This error can occur after a variety of actions, such as invoking SharePoint Explorer or in visual studio deployment steps.

The quickest way to resolve the error make sure that the account being used to run Visual Studio is a db_owner on the SharePoint config and SharePoint admin databases.

No Comments

十一國慶

難得一個long weekend, 係屋企做group project….
加油, KO 科 project management! 遲D仲要考PMP 的, 汗””

fiona 快D返黎喇 , 無你係度好唔慣 , 你掛住去玩啊!

No Comments