Pages

Search This Blog

Tuesday, October 23, 2012

Attach Disposition Workflow on a content type using Powershell

Hi Friends,

Many times we are needed to attach a "Disposition Workflow" with a Content Type in SharePoint 2010. This is pretty easy to accoplish. Please find the PowerShell to do this.

# Method Calling
AddWorkflowToContentType $site $ContentTypeName "Disposition Approval" "WFA" $TaskListName

#Method Definition
function AddWorkflowToContentType($site, $ctName, $WfName, $WfAssociationName, $TaxTaskList)
   {
    [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SharePoint')
    [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.Office.Policy')

    [Guid]$wfTemplateId = New-Object Guid
    $web = $site.RootWeb
       $ct = $web.ContentTypes[$ctName]
       $culture = New-Object System.Globalization.CultureInfo("en-US")
       $template = $site.RootWeb.WorkflowTemplates.GetTemplateByName($WfName, $culture)
   
       if($template -ne $null)
       {                       
      $tasklist = $TaxTaskList
                     $historylist = "Workflow History"
                    
                        # Checking For WorkFlow History List; If not exists then create it
                        if(!$web.Lists[$historylist])
                        {
                            $web.Lists.Add($historylist, "A system library used to store workflow history information that is created in this site.  It is created by the Publishing feature.",
                            "WorkflowHistory", "00BFEA71-4EA5-48D4-A4AD-305CF7030140", 140, "100")
                           
       if (!$web.Features["00BFEA71-4EA5-48D4-A4AD-305CF7030140"]) {
                                Enable-SPFeature -Identity WorkflowHistoryList -Url $web.Url
                            }
    
                            $wfHistory = $web.Lists[$historylist]
                            $wfHistory.Hidden = $true
                            $wfHistory.Update()
                        }

                        # Checking For WorkFlow Task List; If not exists then create it
                        if(!$web.Lists[$tasklist])
                        {
                            $web.Lists.Add($tasklist, "This system library was created by the Publishing feature to store workflow tasks that are created in this site.", "WorkflowTasks", "00BFEA71-A83E-497E-9BA0-7A5C597D0107", 107, "100")
                        }
   
                        # Creating Workflow Association with Content Type
                        $association = [Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateSiteContentTypeAssociation($template, $WfAssociationName, $web.Lists[$tasklist], $web.Lists[$historylist])
                       
      $association.AllowManual = $false
                        #$association.AutoStartCreate = $true
                        $ct.AddWorkflowAssociation($association)
                        $ct.UpdateWorkflowAssociationsOnChildren($true, $true, $true, $false)
                        $association.Enabled=$true
                        $ct.Update()
                        $web.Update()
                        #$ct.WorkflowAssociations[0]           
       }
       else
       {
        Write-Error "Workflow Template not found"
                    Add-Content $logFileName "Workflow Template not found."
       }
   }

Happy Coding!!!

Prabhat

Friday, July 20, 2012

Requested registry access is not allowed


If you are trying to register a new manage account in SharePoint 2013 and getting error
Application error when access /_admin/registeraccount.aspx, Error=Requested registry access is not allowed.  
 at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)    
 at Microsoft.SharePoint.Administration.SPCredentialManager.GetMasterKey(SPFarm farm)    
 at Microsoft.SharePoint.Administration.SPCredentialManager.GetFarmEncryptionKey(SPFarm farm)    
 at Microsoft.SharePoint.Administration.SPCredentialManager.EncryptWithMasterKey(SecureString sstrPassphrase)    
 at Microsoft.SharePoint.Administration.SPEncryptedString.SetSecureStringValue(SecureString sstrValue)    
 at Microsoft.SharePoint.Administration.SPManagedAccount.Update()    
 at Microsoft.SharePoint.WebControls.RegisterAccountControl.BtnSubmit_Click(Object sender, EventArgs args)    
 at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)    
 at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)    
 at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)    
 at System.Web.UI.Page.ProcessRequest()    
 at System.Web.UI.Page.ProcessRequest(HttpContext context)    
 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()    
 at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Please make sure that apppool user of the central administrator have full access on the following location in registry.
HKLM\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\15.0\Secure\FarmAdmin

Thursday, July 19, 2012

Configure SharePoint 2013 Project Template in Visual Studio 2012 RC

If you have installed SharePoint 2013 and Visual Studio 2012 RC, but can not see the SharePoint 2013 project template in visual studio, please refer the below steps to setup it.


  •  Select the "Microsoft Office Developer Tools for Visual Studio 2012 RC" from the search result.
  • Add and install the selected component. During installation, it will install other supporting components also.

  • After installation, Install SharePoint Server 2013 Client Components SDK from the following location.

  • You are done now and SharePoint 2013 project template should be available in the visual studio 2012. 




Wednesday, July 18, 2012

Sharepoint 2013 Beta released

Microsoft has officially released the beta version of its Sharepoint Foundation 2013 Preview and Sharepoint Designer 2013. You can follow below links to download the beta versions:

You can also navigate to the below link for details on SharePoint 2013

http://msdn.microsoft.com/en-us/library/sharepoint/jj162979(v=office.15)

Monday, June 11, 2012

SharePoint 15


Microsoft is planning to release the beta version of its new SharePoint avtaar aka SharePoint 15 by this summer, however the actual product may be launched later this year or starting 2013. I have been searching for the new enhancements and new features that Microsoft is planning for SharePoint 15. Below are some key points that I gathered while searching for new features of SharePoint 15.

  • Include an overhauled Client Object Model (COM), "making it easier for UI designers and front-end developers to build compelling visual interfaces."
  • Support a new app marketplace that will create an ecosystem for multitenant apps.
  • Feature a version for education and training called SharePoint Education.
  • Enable workflow looping in SharePoint Designer, eliminating the need for the Visual Studio development environment for that function.
  • Provide authentication via OAuth 2.0, an open standard that provides cross-platform authentication.
  • SharePoint 15 and Exchange Server 15 are both getting additional built-in information-rights-management (IRM) document-protection functionality as part of the base products.
  • Project Online: New Project site to manage lightweight projects.
  • Visio cloud service component.
  • Offer added information rights management in SharePoint Foundation.
  • Support for viewing business intelligence content on Apple iPad devices.
  • SharePoint 2013 Technical Preview Software Development Kit (SDK) is launched and can be downloaded at: http://social.technet.microsoft.com/wiki/contents/articles/8564.sharepoint-2013-technical-preview-interoperability-api-documentation.aspx
  • New SharePoint Apps Marketplace.
    Namespace:
    using  Microsoft.SharePoint.AppManagement
     
  • Support new Database provider. You can attach Database like MSSQL and any other using namespace:
Microsoft.SharePoint.Administration.DatabaseProvider
 
  • Authentication with a service that supports OAuth 2.0 bearer token authentication using namespace:
Microsoft.SharePoint.IdentityModel.OAuth2
 

Sunday, April 22, 2012

SharePoint List Bulk Delete

Hi Friends,

I came through some requirement where I need to delete number of rows on the basis of some condition. Here we have choice of iterating all the list items and match the required condition if matched delete that list record. This is fine when we say its meeting the requirement. But when we look into its performance its not really a good solution. So here we have another very efficient solution of using ProcessBatchData of SPWeb. This batch technique is 10 times faster than list.Delete(i) technique and it minimizes the round trips to DB. Please find a very simple implementation of this you can alter this as per your requirement.


private void button1_Click(object sender, EventArgs e)
        {
            String strSourceList = "Bulk Delete List";//textBox2.Text.Trim();
            String strSite = "http://abcSite:9000/sites/uk/";//textBox1.Text.Trim();
            String strIds = String.Empty;
            try
            {
                if (!String.IsNullOrEmpty(strSite))
                {
                    if (!String.IsNullOrEmpty(strSourceList))
                    {
                        try
                        {
                            SPSite sourceSite = null;
                            try
                            {
                                sourceSite = new SPSite(strSite);
                            }
                            catch { }

                            if (sourceSite != null)
                            {
                                SPWeb sourceWeb = sourceSite.RootWeb;
                                if (sourceWeb != null)
                                {
                                    sourceWeb.AllowUnsafeUpdates = true;

                                    SPList sourceList = sourceWeb.Lists[strSourceList];
                                    StringBuilder sbDelete = new StringBuilder();
                                    sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");

                                    if (sourceList != null)
                                    {
                                        string command = "<Method>" +
                                                         "<SetList Scope=\"Request\">" + sourceList.ID + "</SetList>" +
                                                         "<SetVar Name=\"ID\">{0}</SetVar>" +
                                                         "<SetVar Name=\"Cmd\">Delete</SetVar>" +
                                                         "</Method>";

                                        foreach (SPListItem objListItem in sourceList.Items)
                                        {
                                            sbDelete.Append(string.Format(command, objListItem.ID.ToString()));
                                        }
                                        sbDelete.Append("</Batch>");

                                        string retVal = sourceWeb.ProcessBatchData(sbDelete.ToString());

                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }

Thanks
Prabhat

Publish Content Type in Content Type hub SharePoint 2010

Sometimes we have a requirement where we need to create the content type in hub and publish the same via code. Following are the methods to Publish or Un-Publish the Content Type in Content Type HUB


 public static String PublishorUnPublishedContentType(SPSite hubSiteCollection, SPContentType cType, bool doPublish)
        {
            String sMessage = String.Empty;
            if (ContentTypePublisher.IsContentTypeSharingEnabled(hubSiteCollection))
            {
                ContentTypePublisher publisher = new ContentTypePublisher(hubSiteCollection);
                try
                {
                    if (doPublish)
                    {
                        publisher.Publish(cType);
                        sMessage = "Content Type Published Successfully.";
                    }
                    else
                    {
                        if (publisher.IsPublished(cType))
                        {
                            publisher.Unpublish(cType);
                            sMessage = "Content Type UnPublished Successfully.";
                        }
                        else
                        {
                            sMessage = "Content Type is not published. You need to Publish the Content Type before UnPublished.";
                        }
                    }
                }
                catch (Exception ex)
                {
                    sMessage = ex.Message;
                }
            }
            else
            {
                // The provided site is not a valid hub site.
                sMessage = hubSiteCollection.Url + ": is not a valid Content Hub Site.";
            }
            return sMessage;
        }

Hope this will help you out !!!!!