Tuesday, May 3, 2011

Monday, April 25, 2011

Sharepoint Tips

1. During people search if there are multiple result for same user. Check “sps3://SERVERNAME/” entry, there may be chances of multiple entries for this.
2. For displaying people result use “People Search Core Result” web part
3. During click on “My Site” link, personal site for user is created if “import connections” is configured in SSP otherwise it will be redirected to WSS “/_layouts/userdisp.aspx” page.
4. For getting documents inside folders in SharePoint document library use
”query.ViewAttributes = "Scope=\"RecursiveAll\" in CAML query.
5. For deploying SharePoint web service using WSP use following tag


Wednesday, April 20, 2011

SharePoint Custom List – Custom ASPX Page

This article provides the details to use custom ASPX pages when new Item is created\ Modified \viewed using SharePoint custom list. We will create List Item Content Types that refers to the custom ASPX pages. These list item content types are associated with list using SharePoint feature.
• Create the ASPX Pages
CustomNewForm.ASPX
CustomEditForm.ASPX
CustomDisplayForm.ASPX
• Write the complete code in the CS files for these pages.
• Signed the project using strong key.
• Deploy the DLL in the GAC and ASPX pages in the Layouts Folder <12 Hive>
• Add the assembly reference in the pages

Create three XML files as
CUSTOMNEW.XML
CUSTOMEDIT.XML
CUSTOMDISPLAY.XML






Once XML files are ready create a new feature and in feature.XML file refer these XML files.
• Install\Activate the feature
• Navigate to the SharePoint list and set “Allow management of content types” Yes
• Add the newly created content type from “Add from existing site content types”
• Click “Change new button order and default content type” and set new content type as default.
• Create new list item, it will navigate to custom ASPX page.

How to attach SharePoint workflow task with custom ASPX page

Create New ASPX Page
1. Open the VS 2008 and create new web Page. e.g. “WebForm1.aspx”
2. Design the page by adding the web controls in it.
3. Replace the Page Directive





4. Assign the strong key name to the project
5. Build the project. Deploy the DLL in the GAC and place the ASPX page in the Layout folder [12 Hive]


Create Visual Studio Workflow Task

1. Open the VS and create the new project of type Workflow
2. Take the workflow template “SharePoint 2007 Sequential Workflow” OR “SharePoint 2007 State Machine Workflow” as per the requirement
3. In this example we will create workflow using State Machine.
4. Click on the Workflow.cs File
5. In the Design Page right click and “Add State”  stateActivity1
6. “Add State Initialization” as first activity. Drop “Create Task with Content Type” state activity.
7. Assign Task Id, Task Property, Correlation Token
Double click on the activity to generate the event handler.

private void createTaskWithContentType1_MethodInvoking(object sender, EventArgs e)
{
try
{
using (SPWeb currentWeb = workflowProperties.Item.Web)
{
this. createTaskWithContentType1_TaskId = Guid.NewGuid();
this. createTaskWithContentType1_ContentTypeId =
"0x010801004D7BB01867D748ba8BE646B432F7ECEF";
SPList currentTaskList =
currentWeb.Lists["TASK LIST NAME"];
VerifyModifyTaskList(currentTaskList, this.
createTaskWithContentType1_ContentTypeId);
createTaskWithContentType1_TaskProperties.Title = "New
Task Created";
createTaskWithContentType1_TaskProperties.AssignedTo =””
}
}
catch (Exception ex)
{

}
}
0x010801004D7BB01867D748ba8BE646B432F7ECEF  This is the Content Type ID that is assigned to the task. This content type id refers to the ASPX page created in the previous step that is deployed in the layouts.


//This fucntion is used for verifying task creation process during approval process
public void VerifyModifyTaskList(SPList taskList, string contentType)
{
try
{
SPContentTypeId contentTypeId = new SPContentTypeId(contentType);
taskList.ContentTypesEnabled = true;
SPContentTypeId matchContentTypeId = taskList.ContentTypes.BestMatch(contentTypeId);
if (matchContentTypeId.Parent.CompareTo(contentTypeId) != 0)
{
SPContentType ct = taskList.ParentWeb.AvailableContentTypes[contentTypeId];
taskList.ContentTypes.Add(ct);
taskList.Update();
}
}
catch (Exception ex)
{
}
}

8. Create New Content Type XML
a. Add new XML File in the workflow project e.g. Test.XML
b. Insert following XML



c. Assign New Content Type ID
0x01080100  Content type Id for Workflow, this value never change
4D7BB01867D748ba8BE646B432F7ECEF  Any Random GUID

d. Replace the newly created content type Id in the workflow “createTaskWithContentType1_ContentTypeId”
e. Rebuild the project and deploy the workflow DLL in the GAC
f. Recycle the Application Pool for web application after DLL GAC deployment
g. Create new Feature and place “feature.xml”, “workflow.xml and Test.xml” file in it.
h. Install and activate the feature.
i. Check the newly created content type. It will come in the site Content Type Section.
j. Attach the workflow to any List\ Library.
k. Once you click on the task created using this workflow it will open OUR custom ASPX page.
l. You can redesign the complete workflow by adding other activities.