Wednesday 11 December 2013

SharePoint: Assign Values to the Taxonomy Field

  TaxonomyFieldValue TenderNO = item["Tender No"] as TaxonomyFieldValue;
   TaxonomyField taxonomyField = newWeb.Lists[i].Fields["Tender No"] as TaxonomyField;
                               

                                    try
                                    {                                      
                                        taxonomyField.DefaultValue = TenderNO.ValidatedString;
                                    }
                                    catch
                                    {
                                     
                                        taxonomyField.DefaultValue = String.Empty;
                                    }
                                    taxonomyField.UserCreated = false;
                                    taxonomyField.Update(true);







Tuesday 10 December 2013

"Unable to load assembly group. The user assembly group provider was unable to provide any user assemblies for the specified assembly group."

Firstly make sure the the sandboxed service run under a managed account that has permissions on the web application.
Secondly, when building the sandboxed solution, make sure you include the assembly in the package.


Monday 9 December 2013

Changing CPUExecutionTime is having no effect

I see someone is having this problem, because they miss this statement

$uc.ResourceMeasures.Update()



==================================================
# Give our sandboxed solution more resources.
# Worker Process Timeout
$wpe = "900"
# CPU Timeout
$cpu = "900"
# Grab the User Code Service
$uc=[Microsoft.SharePoint.Administration.SPUserCodeService]::Local
# Output current values
Write-Host ""
Write-Host "Current worker process execution timeout is:" $uc.WorkerProcessExecutionTimeout "seconds" -foreground cyan
Write-Host "Current CPU execution timeout is:" $uc.ResourceMeasures["CPUExecutionTime"].AbsoluteLimit "seconds" -foreground cyan
Write-Host ""
Write-Host " ***UPDATING***"
Write-Host ""
# Update worker process execution timeout
$uc.WorkerProcessExecutionTimeout = $wpe
# Update CPU execution time
$uc.ResourceMeasures["CPUExecutionTime"].AbsoluteLimit = $cpu
$uc.ResourceMeasures.Update()
# Update User Code Service
$uc.Update()
# Output new values
Write-Host "New worker process execution timeout is:" $uc.WorkerProcessExecutionTimeout "seconds" -foreground green
Write-Host "New CPU execution timeout is:" $uc.ResourceMeasures["CPUExecutionTime"].AbsoluteLimit "seconds" -foreground green
Write-Host ""
Write-Host "Now go and restart the sandboxed code service on all servers!!!"
Stop-Service SPUserCodeV4
Start-Service SPUserCodeV4

Monday 2 December 2013

SharePoint 2013: Error Creating Web Application in SharePoint 2013

I recently ran into an issue when creating a new sharepoint 2013 web application. After couple of minutes the dialog box displayed "Internet Explorer cannot display the webpage".  I waited another couple of minutes and I found that the web app is actually created in Central Administration. However, when I ​looked in the Virtual Directory I noticed there was nothing in the folder for my newly created port. 
I think it might be a timing out issue and took these steps to solve the problem
  1. Open IIS Manager and select Application Pools
  2. On the right hand side of the window click Select Application Pool Defaults...
  3. Change the following 3 Process Model time settings
    1. Ping Maximum Response Time
    2. Shutdown Time Limit
    3. Startup Time Limit
      1. I changed all of these from 90 to 900
  4. Do an iis reset

Wednesday 20 November 2013

SharePoint 2013: addanapp page only shows 3 buttons [addanapp page is broken]

It is a bug in the designer manager, you experience this bug if you use the designer manager to create a master page.
The image below shows the correct addanapp page. If the bug happens, you will not be able to see the buttons in the red circle.





















To fix this, add the following code to your custom.master file.

  <SharePoint:AjaxDelta id="DeltaPlaceHolderPageTitleInTitleArea" runat="server">  
  <asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea" runat="server">  
  <SharePoint:SPTitleBreadcrumb  
    runat="server"  
    RenderCurrentNodeAsLink="true"  
    SiteMapProvider="SPContentMapProvider"  
    CentralAdminSiteMapProvider="SPXmlAdminContentMapProvider">  
  <PATHSEPARATORTEMPLATE>  
   <SharePoint:ClusteredDirectionalSeparatorArrow runat="server" />  
  </PATHSEPARATORTEMPLATE>  
   </SharePoint:SPTitleBreadcrumb>  
  </asp:ContentPlaceHolder>  
  </SharePoint:AjaxDelta>  
  <SharePoint:AjaxDelta BlockElement="true" id="DeltaPlaceHolderPageDescription" CssClass="ms-displayInlineBlock ms-normalWrap" runat="server">  
  <a href="javascript:;" id="ms-pageDescriptionDiv" style="display:none;">  
   <span id="ms-pageDescriptionImage">&#160;</span>  
  </a>  
  <span class="ms-accessible" id="ms-pageDescription">  
   <asp:ContentPlaceHolder id="PlaceHolderPageDescription" runat="server" />  
  </span>  
  <SharePoint:ScriptBlock runat="server">  
   _spBodyOnLoadFunctionNames.push("setupPageDescriptionCallout");  
  </SharePoint:ScriptBlock>  
  </SharePoint:AjaxDelta>  


I added it inside the pageTitle
<h1 id="pageTitle" class="ms-core-pageTitle"> I added it here </h1>

Sunday 17 November 2013

SharePoint 2013: Where is my dll?

Starting from .NET 4.0, there is a new ‘GAC’ folder “c:\windows\microsoft.net\assembly“. 

Monday 21 October 2013

SharePoint 2010 Workflow Exception: "This task is currently locked by a running workflow and cannot be edited"

If you are experiencing this problem, first thing you need to check is this great post.


If your workflow is not in Visual Studio, rather it's a SPD workflow, what you can do is create a Timer Job which runs every couple of minutes and set the workflow version. Here is the Code:

 // Feature receiver  
 using System;  
 using System.Runtime.InteropServices;  
 using System.Security.Permissions;  
 using Microsoft.SharePoint;  
 using Microsoft.SharePoint.Security;  
 using Microsoft.SharePoint.Administration;  
 using **.Code.TimerJobs;  
 namespace **.Features.Unlock_Workflow_Tasks  
 {  
 [Guid("***")]  
 public class Unlock_Workflow_Tasks : SPFeatureReceiver  
 {  
 public override void FeatureActivated(SPFeatureReceiverProperties properties)  
 {  
 SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;  
 if (webApp == null)  
 return;  
 try  
 {  
 // make sure the job isn't already registered  
 foreach (SPJobDefinition job in webApp.JobDefinitions)  
 {  
 if (job.Name == JOB_NAME)  
 job.Delete();  
 }  
 }  
 catch  
 {  
 }  
 // install the job  
 UnlockWorkflowTasks timerJobDefinition = new UnlockWorkflowTasks(JOB_NAME, webApp);  
 SPMinuteSchedule schedule = new SPMinuteSchedule();  
 schedule.Interval = 15;  
 schedule.BeginSecond = 0;  
 schedule.EndSecond = 59;  
 timerJobDefinition .Schedule = schedule;  
 timerJobDefinition .Update();  
 }  
 // Uncomment the method below to handle the event raised before a feature is deactivated.  
 public override void FeatureDeactivating(SPFeatureReceiverProperties properties)  
 {  
 SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;  
 // delete the job  
 try  
 {  
 foreach (SPJobDefinition job in webApp.JobDefinitions)  
 {  
 if (job.Name == JOB_NAME)  
 job.Delete();  
 }  
 }  
 catch  
 {  
 }  
 }  
 }  
 }  
 // The Timer Job  
 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Text;  
 using Microsoft.SharePoint.Administration;  
 using Microsoft.SharePoint;  
 using **.Code.Utilities;  
 using Microsoft.SharePoint.Workflow;  
 namespace **.Code.TimerJobs  
 {  
 class UnlockWorkflowTasks : SPJobDefinition  
 {  
 public UnlockWorkflowTasks(): base() {}  
 public UnlockWorkflowTasks(string jobName, SPWebApplication webApplication)  
 : base(jobName, webApplication, null, SPJobLockType.Job)  
 {  
 this.Title = "**";  
 }  
 public override void Execute(Guid contentDbId)  
 {  
 try  
 {  
 SPSecurity.RunWithElevatedPrivileges(delegate()  
 {  
 using (SPSite site = new SPSite(WebApplication.Sites[0].Url))  
 using (SPWeb web = site.OpenWeb())  
 {  
 UnlockPotentiallyLockedWorkflowTasks(web);  
 }  
 });  
 }  
 catch (Exception ex)  
 {  
 Logger.LogError(ex);  
 }  
 }  
 private void UnlockPotentiallyLockedWorkflowTasks(SPWeb web)  
 {  
 try  
 {  
 web.AllowUnsafeUpdates = true;  
 SPListItemCollection tasks = GetPotentiallyLockedTasks(web);  
 foreach (SPListItem task in tasks)  
 {  
 try  
 {  
 if ((int)task[SPBuiltInFieldId.WorkflowVersion] != 1)  
 {  
 // change it's version to 1.0  
 SPList parentList = task.ParentList.ParentWeb.Lists[new Guid(task[SPBuiltInFieldId.WorkflowListId].ToString())];  
 SPListItem parentItem = parentList.Items.GetItemById((int)task[SPBuiltInFieldId.WorkflowItemId]);  
 SPWorkflow workflow = parentItem.Workflows[new Guid(task[SPBuiltInFieldId.WorkflowInstanceID].ToString())];  
 if (!workflow.IsLocked)  
 {  
 task[SPBuiltInFieldId.WorkflowVersion] = 1;  
 task.SystemUpdate();  
 Logger.LogInfo("Unlock task {0} (ID:{1})", task["Title"].ToString(), task["ID"].ToString());  
 }  
 }  
 }  
 catch (Exception e)  
 {  
 Logger.LogError(e);  
 }  
 }  
 }  
 catch (Exception e)  
 {  
 Logger.LogError(e);  
 }  
 finally  
 {  
 web.AllowUnsafeUpdates = false;  
 }  
 }  
 private SPListItemCollection GetPotentiallyLockedTasks(SPWeb web)  
 {  
 var query = new SPQuery();  
 query.Query = @"  
 <Where>  
 <Neq>  
 <FieldRef Name='Status' />  
 <Value Type='Choice'>Completed</Value>  
 </Neq>  
 </Where>";  
 //query.ViewAttributes = "Scope=\"Recursive\"";  
 return web.Lists[WORKFLOW_TASKS_LIST].GetItems(query);  
 }  
 }  
 }