Tuesday, 24 June 2014

Using Content Deployment to Copy One Site Collection to Another in SharePoint 2010

Good Article on Content Deployment by KC Young

Using Content Deployment to Copy One Site Collection to Another in SharePoint 2010


In simple terms, Content Deployment in SharePoint 2010 is used to deploy the content from one site to another site. We can set the content deployment jobs (incoming and outgoing) using SharePoint Central Administration 2010.
The two-farm topology is a standard Internet site topology and is typical of topologies that are used to publish an Internet site. It is usually composed of two server farms: one to host the authoring site collection and the other to host the production site collection.
It is important to be aware that content deployment is a one-way process. The content deployment feature does not support round-trip synchronization from source to destination and vice versa. Creating new content or changing existing content on the destination site collection can cause content deployment jobs to fail. Because of this, it is usually recommended to restrict permissions on the destination site collection so that only specific users can make direct changes to content that is stored within that site collection.
We will now go through a typical process that will copy one site collection to another with content deployment.
PROCESS OVERVIEW
Content Deployment in SharePoint 2010 is composed of the following three processes.
  1. Create two Web Applications in separate content databases and create site collections in the web applications.
  2. Configure Content deployment, paths and jobs -> Run jobs.
  3. Check the deployment status and the destination site collection’s content.
I. CREATING THE WEB APPLICATIONS AND SITE COLLECTIONS
1. First, create two web apps and ensure the two are in separate content databases.
  • http://spy2010
  • http://spy2010:1111
2. Second, create site collection http://spy2010/sites/authoring and select the “Team Site” template.

3. The initial content deployment destination must be a blank site collection.
4. Create a site collection and ensure that you select “<Select template later>.”
Note: DO NOT create a site collection using “Blank Site” template, as this does not count as an empty site collection and content deployment will fail.
5. The site collection in port 1111 is just http://spy2010:1111/sites/production.

II. Configure Content deployment, paths and jobs in CA
1. Navigate to Central Administration -> General Application Settings -> Content Deployment -> Configure Content Deployment.

2. Configure new deployment path

Note: A content deployment path is required to define a one-to-one relationship between a source and destination site collection for the purposes of content deployment. Once you have created a path, jobs can be scheduled and run on an ad-hoc basis to deploy additional content as required.
3. Select your “authoring” site collection as the source and “production” site collection as the destination.
4. Enter the current central administration address, including the port number.
Note: We will need to test the connection to make sure the destination site collection list populated correctly.

Create a deployment job and run it
5. We will need to create a deployment job. Jobs and deployment paths have a one-to-one relationship, so we will need to create at least one job for each path that we have specified.
6. Select the “One time only” radio button to kick the job off immediately.

7. Create a schedule or run the job now using the “One time only” option to test your new deployment path.

8. You can view current job status on the “Manage Content Deployment Paths and Jobs” page.


9. Once the job status becomes “Completed,” the “Production” site collection’s content has been copied successfully.

III. Check deployment status and destination site collection’s content
1. Navigate to Central Administration -> General Application Settings -> Content Deployment -> Check deployment of specific content.

2. We can check the “production” status on the following page.

3. When we login to “production,” we can see that the content is now same as the content in “authoring.”


Friday, 13 June 2014

Creating a custom sequential workflow in SharePoint 2010

Nice Article by Kalyan

http://www.techbubbles.com/workflowfoundation/creating-a-custom-sequential-workflow-in-sharepoint-2010/

SharePoint supports state machine and sequential workflows. In Sequential Workflow the activities are placed in logical order with a start and an end. Sequential workflows can be used in automated processes where a manual interaction like moving documents to library. In SharePoint, Workflows can be associated with libraries, lists and sites. Site workflows are introduced in SharePoint 2010 and they exist at the site level and can act on all lists and libraries associated in the site. This post outlines the steps to create a sequential workflow in SharePoint.
Create a list and instantiate the workflow automatically when an item is inserted to a list and flow through the process.
1. Create a list in SharePoint called Credit Approval which contains the below three fields
Field Name Data Type Required
Credit Requested Amount Currency Yes
Employment History Choice (Good, Bad and none exist) Yes
Credit History Choice (Good, Bad and none exist) Yes
2. Launch the Visual Studio  2010 and create a new Sequential Workflow as shown below
image
3. Name the workflow project name and say ok. Visual Studio selects the available SharePoint site on the machine and select deploy as Farm Solution in next step
4. Provide a name to workflow and select List Workflow for the workflow template
image
5. Click next to select the list association and task list and workflow history list
image
6. Check how do you want the workflow to start?
image
7. Click Finish button and Visual Studio generates the necessary files. Add LogToHistoryListActivity activity below onWorkflowActivate activity and set the properties as shown below
image
8. Drag an If-else activity to the designer below the logWorkflowStarted activity. Add other activities as shown below
image
9. Select the code condition in properties window for CheckEmploymentHistoryActivity and add the below code
image
10. Now Deploy the project and browse the list in SharePoint and save an item to the list. As there is no user interaction workflow completes and shows as below
image
11. Click on the Completed status of the workflow to see the workflow history.
image
12. After Deploying the workflow to SharePoint then you can then associate it to list , content or site in two ways
  • Manually by using SharePoint interface
  • During the feature activation via feature receiver
13. Navigate to the list settings –> Workflow settings of the list then you need to associate a workflow as shown below
image
click on the Add a workflow link to add a new workflow as shown below
image

Custom Approval Workflow in SharePoint

Good Article by Muruges

http://intelliview.blogspot.in/2012/08/custom-approval-workflow-in-sharepoint.html

Download code from here
This workflow was created for beginner those wanted to learn the custom workflow in SharePoint from very scratch level.
Even I have created many complex workflows for my work in the past,I feel its time to introspect my knowledge on this simple workflow.
As I follow the many instruction those available in forums and blogs,I end up with confusion and if I wanted to apply my own business requirement out of this instruction,it was very tedious.
So here is the simplified version of my "Custom Approval Workflow in SharePoint using Visual Studio 2010".
Debugging is always enlighten you to apply and learn the secret of the workflow engine. Create a blank SharePoint project and add the new item from project template "Sequential Workflow".
On this design surface add the activities just like you seen here.
The workflow engine manage the following activities such as "Creating task and assigning to someone,after the task has been assigned to someone monitoring the status of Tasks(approved or rejected) and completing the task. Many times I was confused and identified the reason for it,assigning the correlation and Task Properties and Task id via "Property Window". Of course this will be useful for advanced developer[I personally feel those knows all properties of the task and workflow and how to apply these to their business requirement]. For simplicity I am going to create all properties behind the code and assigning to design surface. Required properties here I have created so far globally.
        public Guid TaskID = Guid.NewGuid();
        public SPWorkflowTaskProperties taskProp = new SPWorkflowTaskProperties();
        public SPWorkflowTaskProperties afterProp = new SPWorkflowTaskProperties();
        public SPWorkflowTaskProperties beforeProp = new SPWorkflowTaskProperties();
        public bool isComplete = false;
// This is nothing but "Task ContentType's" field "Status" GUID.
//You can find it by debugging the code line,You can find all field's guid and its value.
//HashTable tbl = afterProp.ExtendedProperites;
        public Guid idStatus = new Guid("c15b34c3-ce7d-490a-b133-3f4de8801b76");

Now we need to assign these properties to design workface.Once you created all these properties on code behind,you can see like this
Important tips to remember: Correlation token for task activities must be same throughout the workflow. So I am renaming the correlation token for my "CreateTask1" as taskToken. Assigning the Owner Activity to "Workflow1" just like below screenshot.
follow the same to all activities "OnTaskChanged1" and "CompleteTask". Secondly,We need to assign the unique GUID for task this one also common for all activities. Right click on CreateTask1 activities -> Properties and choose the "Task Id" click on the button and choose our own created "TaskID" for the task id. like shown here. And do the same for "Task Properties" too.


Here I am creating a method called "createTaskAndAssign".
private void createTaskAndAssign(object sender, EventArgs e)
        {

            taskProp.Title = "Type the title";
//Later you can try the dynamic title text may be workflow item's title using workflowproperties.
            taskProp.AssignedTo = "local\\administrator";
            taskProp.Description = "Please review";
            taskProp.DueDate = DateTime.Now.AddDays(2);

        }
Assign the above method to "MethodInvoking" properties of the "Create Task1" activity. For whileActivity you can manage your condition using "Code Declaration" or "Declarative Rule Condition. I have used "Code condition" you just need to assign the method name[CheckTaskStatus]to "Code Condition properties of "While Activity".
private void CheckTaskStatus(object sender, ConditionalEventArgs e)
        {
            e.Result = !isComplete; //When true - workflow ends up.
        }

Created a method for "OnTaskChange1" activity and assigned the same as did for while activity. This method will check the task content type's task status field value by using the task class's "ExtendedProperties".
 private void onTaskChangedInvoked(object sender, ExternalDataEventArgs e)
        {
            string tbl = afterProp.ExtendedProperties[idStatus].ToString();
            if (tbl.Equals("Completed"))
            {
                isComplete = true;
            }
            else
            {
                isComplete = false;
            }

        }
As soon as the boolean value set to true,the workflow calls the "Complete Task" activity and ends up its cycle. To test this demonstration on your development server,create two user for your sharepoint site and assign the task for them. And log in as different user by using new user check the "Task" list on their log do approve or reject and see the workflow status.

Reference:

http://intelliview.blogspot.in/2012/08/custom-approval-workflow-in-sharepoint.html

SharePoint Foundation 2010 Visual Studio Approval Workflow

Good Article explains step by step by Adil

http://dotnetadil.wordpress.com/2012/05/29/sharepoint-foundation-2010-visual-studio-approval-workflow/

  1. The scenario is that a document library has a column of type option named WorkFlowLevel. Level -0 means that the document is approved automatically by the uploader and Level -1 means the document can only be approved/reject by a person who is in the Approver groups.

    Column

    Approver groups
  2. The final workflow is as below:-
  3. To create such solutions fire up the Visual Studio and select a Sequential Workflow template, and set the solution settings as below




  4. First code is to define the OnWorkflowActivated event .
  5. Then connect this method to the activity on the designer
  6. Next go to the Toolbox, under the Window Workflow v3.0 tab drag and drop the ifElse activity just below the previous activity and then define the code to execute.
  7. Associate the above code to the left if branch (if the condition return true then this side will fire, if it false the right side will automatically fire)
  8. If true, the left side will execute a code (see below) that will email a document approval request to all the member of the Approver groups
  9. Drop the send email activity and associate the above code.
  10. Now we are going to use the while loop that will loop until the Approve Status is equal to Approved or Reject.
  11. Associate the while loop with the code below
  12. Inside the while loop drop the OnWorkflowItemChanged activity and then define the code before associating the two.

  13. When the document have been approved or rejected, the loop will break where based on the status we will send the email to the document creator. Drop the ifElse activity just below the while loop.
  14. Below is the email code for sendApprovedEmail
  15. One last part of the workflow is the right hand side, where the document does not require any approval. The approval status is automatically set to Approved.
  16. For that, just drag and drop the Code activity from the Toolbox inside the else activity and associate the ExecuteCode.

  17. To approve a document, the user needs to have at least Design permission level. Even though the workflow can be triggered by user that has permission other than Design which by right the code should be elevated. Here we are not elevating anything since unlike SharePoint Designer workflow which runs under the user
    who triggers it, a Visual Studio workflow will always run using the System Account (that means Full Control).
  18. Oh, by the way the link in the email will open the below page (Item Display Form).


    Reference

    http://dotnetadil.wordpress.com/2012/05/29/sharepoint-foundation-2010-visual-studio-approval-workflow/

Friday, 6 June 2014

SharePoint 2010 Managed Metadata - Global vs. Local Term Sets

SharePoint 2010 Managed Metadata - Global vs. Local Term Sets

Excellent Article by Andrew Connell

http://www.andrewconnell.com/blog/SP2010-Managed-Metadata-Global-vs-Local-Term-Sets


This post will cover the differences between global & local term sets. The other posts in this series are as follows (I'll update this list as they are published):
As the first part of this post reflects, in previous posts I've talked about what managed metadata is and how you can use it. I touched on something that I wanted to elaborate on a bit more in this post: global vs. local term sets. These are a bit nebulous because no where in the SharePoint UI will you find these terms. Think of this as more logical descriptions... it's unfortunate because they have such a significant impact
First, lets get something out of the way. All term sets are created and stored in a Managed Metadata Service application instance (MMS). When you create a term set from the MMS management interface via Central Administration (CA) it is available to all site collections living in Web applications that are connected via a service application proxy to the MMS instance. We refer to these as global term sets because they are available to all sites & site collections that are connected to the MMS.
If we have global term sets that must mean there's another option: local term sets. These are different in that they are scoped locally to a specific site collection and can only be used by that site collection, not by other site collections. This trips people up at times because you'll see both global & local term sets in the MMS management page when you access it from CA. Local term sets come in handy when site collection owners want to create their own term sets without having to work with librarians. These can be managed from a link in the site collection's Site Settings page or when you modify a column.
There isn't anything wrong with local term sets, it just gives you additional options. You do need to be aware of them though as there are some big differences with these. What's unfortunate with these is that the UI doesn't provide much guidance here. For instance, when you create a new column and select the data type Managed Metadata you'll see the following section the page. If you elect to customize a term set, you will be creating a local term set, not a global one.
One really important thing you need to keep in mind is that local term sets can prove to be very unfriendly when it comes to portability or disaster recovery scenarios (backup/restore). Instead of rehashing this point, I'll simply point you to Sergy Zelenov's post on the SharePoint From the Field blog (a blog where Microsoft employees working directly with customers blog... a fantastic resource!) in his post Beware Local Term Store!.
[Update 6/16/2011 6a] Sergy has since figured out how, using Windows PowerShell, you can recreate this association. Check out his follow up post here: Betware Local Term Store - Continued (with good news, too!)
Here's a little cheat sheet on the differences between global & local. I'm personally not much of a fan of local term sets and try to focus on global ones only, but locals do come in handy at times. Like anything in SharePoint, as long as you're educated on the differences, you can make the decision that works best for you regardless of what some blogger like me is saying!

Global
Local
Created / Managed
MMS instance management page in CA.
From within site collection, either from the column settings page or from link in Site Settings page.
Available
Any site collection in a Web App connected to the MMS instance via a proxy.
To the site collection where they were created.
Who can manage
Those granted explicit permissions via MMS instance management page in CA.
Site collection administrators & owners.







Read more at http://www.andrewconnell.com/blog/SP2010-Managed-Metadata-Global-vs-Local-Term-Sets#v3bA7jpX2R65d0F9.99