Tuesday, October 21, 2014

Check Workflow association of list items

Hi,

I was researching on this matter and found a way implement. I got event handler for my submit button and I have added my code inside it.

In my test, I'll be getting site collection url from a textbox and evaluate all the webs inside that site collection. We will go inside web object and get all the lists and evaluate whether any item associated with a workflow that running status as 2, which is "In progress". Code is below

            string SiteUrl = string.Empty;
            ArrayList inflightWorkflowDocuments = new ArrayList();
 
            if (string.IsNullOrEmpty(txtSiteUrl.Text.ToString()))
            {
                throw new Exception("Site URL is empty!");
            }
            else
            {
                SiteUrl = txtSiteUrl.Text.ToString();
            }
 
            //Check site collection exist or not
 
            bool isSteExist = SPSite.Exists(new Uri(SiteUrl));
 
            if (isSteExist && !string.IsNullOrEmpty(SiteUrl))
            {
                using (SPSite site = new SPSite(SiteUrl))
                {
                    //Loop through all webs
                    SPWebCollection allWebs = site.AllWebs;
                    Dictionary<stringstring> liUrls = new Dictionary<stringstring>();
 
                    foreach (SPWeb theWeb in allWebs)
                    {
                        Guid webGuid = theWeb.ID;
                        using (SPWeb web = allWebs[webGuid])
                        {
                            SPListCollection cusLists = null;
                            if (null != web.Lists)
                            {
                                //Get list of lists (custom/OOB lists)
                                cusLists = web.Lists;
                            }
 
                            if (null != cusLists)
                            {
                                foreach (SPList sltList in cusLists)
                                {
                                    if (sltList.Title == "TestList")
                                    {
                                        //Get each list and iterate through all items on that list
                                        foreach (SPListItem litem in sltList.Items)
                                        {
 
                                            //Check all workflows and their associations
                                            int wkflStatus = GetWorkflowStatus(litem);
 
                                            /*   Workflow statuses
                                     
                                                    Not Started                     0
                                                    Failed on Start                 1
                                                    In Progress                     2
                                                    Error Occurred                  3
                                                    Canceled                        4
                                                    Completed                     5
                                                    Failed on Start (retrying)     6
                                                    Error Occurred (retrying)     7
                                                    Canceled                     15
                                                    Approved                     16
                                                    Rejected                     17
                                                */
 
                                            //Check that list item having Workflow 'In Progress'
                                            if (wkflStatus == 2)
                                            {
                                                //Rest of your work                                               
                                            }
                                        }
 
                                    }
                                    
                                }
                            }
                        }
                    }
                }
            }
 
            
            //Creating a grid view with items having workflow associated.
 
            if (null != inflightWorkflowDocuments)
            {
                grdWorkflowItems.DataSource = (string[])inflightWorkflowDocuments.ToArray(typeof(string));
                grdWorkflowItems.DataBind();            
            }
}


public int GetWorkflowStatus(SPListItem item)
        {
            if (item == null)
                return -1;
 
            SPWorkflowManager manager = item.Web.Site.WorkflowManager;
            foreach (SPWorkflow instance in manager.GetItemWorkflows(item))
            {
                if ((instance != null) && (instance.ParentList != null) && (instance.ParentList.Fields != null))
                {
                    foreach (SPField field in instance.ParentList.Fields)
                    {
                        if ((field != null) && (field is SPFieldWorkflowStatus))
                        {
                            SPFieldWorkflowStatus statusField = (SPFieldWorkflowStatus)field;
                            if (item[statusField.StaticName] != null)
                            {
                                int statusValue = -1;
                                try
                                {
                                    statusValue = int.Parse(item[statusField.StaticName].ToString());
                                }
                                catch { }
                                return statusValue;
                            }
                        }
                    }
                }
            }
            return -1;
        }

Wednesday, September 24, 2014

Memory gates checking failed because the free memory is less than 5% of total memory. As a result, the service will not be available for incoming requests. To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.

Hi Friends,

Did you ever experienced below error while loading newly created Team Site on SharePoint 2013? 




Root cause: This is happening because of excess memory using by the SharePoint 2013.

I think there are 2 solutions. Just find below service and restart it. 

Solution 1



It will release some memory leaks on host controller. then refresh the browser to load the page.

Solution 2

1.Open IIS by running CTRL+R -> inetmgr
2.Identify the WebService that calling by the web page



3.Right Click -> Explore
4.Edit Web.config file
5.Modify node serviceHostingEnvironment

<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="1" />


6.Just save web.config and do a IISRESET

double check your environment.

References:

http://stevemannspath.blogspot.com/2012/07/sharepoint-2013-opening-memory-gates.html
http://kancharla-sharepoint.blogspot.com/2013/04/sharepoint-memory-gates-checking-failed.html

That's it. Good Luck!

Tuesday, September 23, 2014

Error occured in deployment step 'Activate Features': Unable to locate the workflow's association data. To restore the association data..

Hey Friends,

Have you ever faced an issue like below, while developing Sequential workflow for SharePoint 2013, using VS 2012. 



Be cool, solution is there

Reason for the issue:

I'll give some context on Workflows. Workflows were having several number of Tasks and actions to perform, upon ItemAdding and ItemUpdating. Workflow will update entries in Task List (created for each workflow by default) and History list will record the steps executed (History list also get created). So while creating the workflow through VS 2012, Association between Task List, History List and Workflow will be created automatically by VS 2012. This error will appear after you have tried to redeploy same workflow code to different site collection and if your workflow already undergone some processing tasks.

Fix for the issue:

Just select the Workflow node from the project and check the properties window. notice the parameter "Auto Associate" and make it "False"



That's it, Rebuild the project and try to deploy to the site collection. Error will vanish.

Good Luck!

References:

http://blogs.msdn.com/b/exploring_technology_/archive/2011/10/19/error-occurred-in-deployment-step-activate-features-unable-to-locate-the-workflow-s-association-data.aspx


Wednesday, September 17, 2014

Provisioning a publishing web page with a simple webpart (SP2010 + VS 2010) - simplified steps

Hey Folks,

While I'm checking for the easiest way to publish a page with a webpart, I think I have found set of steps and thought to share for any users (Advance/Beginner). So let's jump in.

1.Open your VS 2010 environment with Administrator privileges.
2.Open new SP 2010 project (I have created project called "TestProvision")



Select correct site collection to be use with farm level deployment (make sure you have activated publishing features in your site collection)




3.Add Feature to host webpart deployment (this feature scoped as Site)





4.Create a folder as "CustomWebParts"

5.Add new item (Visual WebPart would be prefered)



6.Create another feature to host provisioning webpart page (scoped web)



7.Add Folder called "CustomPages"

8.Add new Module



9.Delete default "Sample.txt"

10.Add new .aspx page



11.Modify Element.xml file in Module and add below code

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="CustomPages" Url="Pages" Path="" RootWebOnly="FALSE">
    <File Name="SuperTest.aspx" Url="SuperTest.aspx" Type="GhostableInLibrary" Path="CustomPages\SuperTest.aspx" IgnoreIfAlreadyExists="TRUE">
      <Property Name="Title" Value="Super Test" />
      <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/BlankWebPartPage.aspx, Blank Web Part page" />
      <Property Name="ContentType" Value="MyPageLayoutContentType" />      
    </File>
  </Module>
</Elements>

Special Note: Module-> Url parameter is the document library that "SuperTest.aspx" page will deploy. In File->Path, you should add the absolute path to the page. I'm using Blank Web Part page layout. "ContentType" would be any contenttype as you wish.

Then add the webpart markup. Go to below file 



Add that code to Element file like below

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="CustomPages" Url="Pages" Path="" RootWebOnly="FALSE">
    <File Name="SuperTest.aspx" Url="SuperTest.aspx" Type="GhostableInLibrary" Path="CustomPages\SuperTest.aspx" IgnoreIfAlreadyExists="TRUE">
      <Property Name="Title" Value="Super Test" />
      <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/BlankWebPartPage.aspx, Blank Web Part page" />
      <Property Name="ContentType" Value="MyPageLayoutContentType" />
      <AllUsersWebPart WebPartZoneID="Head" WebPartOrder="1">
        <![CDATA[<?xml version="1.0" encoding="utf-8"?>
<webParts>
  <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
    <metaData>
      <type name="TestProvision.CustomWebParts.TestCustomVisualWebPart.TestCustomVisualWebPart, $SharePoint.Project.AssemblyFullName$" />
      <importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
    </metaData>
    <data>
      <properties>
        <property name="Title" type="string">TestCustomVisualWebPart</property>
        <property name="Description" type="string">My Visual WebPart</property>
      </properties>
    </data>
  </webPart>
</webParts>]]>
      </AllUsersWebPart>
    </File>
  </Module>
</Elements>

Special Note: Use any WebPartZone as you wish. I used "Head" zone just to demonstrate possibilities.

Your control can have simple thing like below



12.Open newly created .aspx file and copy below code

<%@ Page Inherits="Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Reference VirtualPath="~TemplatePageUrl" %>
<%@ Reference VirtualPath="~masterurl/custom.master" %>

13.Open Manifest.xml file of the feature and double check below entries were automatically added. (If not modify the Manifest.xml file and add those entries)



14.Build the project

15.Package wsp

16.Deploy the .wsp to Site collection


that's it, go to Site Actions -> View All site contents -> Go to Pages Library (or just go to http://<YourSiteCollection/Pages/Forms/AllItems.aspx>)...You will notice the page will appear with your webpart.




Good luck!

Tuesday, September 16, 2014

configure SharePoint:DateTimecontrol to run server side for dynamically generated controls

I'm sure you may wonder, why do we care about Server side firing of default validation comes with SharePoint:DateTime Control. We just can enable IsRequired = "True" and configure <control>.ErrorMessage with appropriate styles.

Yes you are correct. However think about a scenario that client want to have server side validators plus client side validators like SharePoint:Datetime control. If this is the case, can you imagine the main issue. When end user clicks on "Submit" button first application fires client side validation. Then after fires the server side validators within separate post back. This issue would be a great headache for sure.

So let's dig into the issue using my scenario. All fields were generating dynamically using the SharePoint list fields and controls were in <tr><td></td></tr> sets. Ultimately no server control markup to configure attributes. then I have created the DateTime control object from the BaseFieldControl(Microsoft.SharePoint.WebControls) object get passed.

DateTimeField dateTimeField = (DateTimeField)control;

Then I have disabled IsRequired from there.

dateTimeControl.IsRequiredField = false;


After that I have added a label control dynamically (initially setting styles to hide on load), while adding the control id to the Session. So ultimately I can access the control through button code behind.

Finally, get the control id from session variables and check whether datetimecontrol is empty or not. If empty we will reset styles to show the error message label and hide if not. This was my simple solution within my context. Hope will help someone and thought to share.

Thursday, July 3, 2014

SharePoint 2013 Search Magics -> Continuous Crawling

What is Crawling?

There are 3 methods can be used within SharePoint 2013. They are Incremental crawl (default schedule is 4 hours), Full crawl (default schedule is 4 hours) and most importantly Continuous Crawl. Crawling is the process of analysing content from "content source/s" and make available for Search results.

What is Continuous Crawling?

Continuous crawls crawl SharePoint site frequently to keep search results fresh. Continuous crawl will happen in 15 minutes interval. Ultimately users can configure this time interval from 1 minute to 15 minutes

Continuous crawling interval re-configure (put any minutes from 1 - 15 in parameter "n")

$ssa = Get-SPEnterpriseSearchServiceApplication
$ssa.SetProperty("ContinuousCrawlInterval",n)


Disable continuous crawl

$SSA =  Get-SPEnterpriseSearchServiceApplication
$SPContentSources = $SSA | Get-SPEnterpriseSearchCrawlContentSource | WHERE {$_.Type -eq "SharePoint"}
foreach ($cs in $SPContentSources)
{
  $cs.EnableContinuousCrawls = $false
  $cs.Update()
}