Friday, February 26, 2016

Timer Job to execute a Workflow Instance

Hello SharePointers,

Here is a little guide to create a timer job and inside its code, you could execute a wf instance.

namespace SP.Sample.OnlineForms{    using System;
    using System.Collections.Generic;
    using System.Web;
    using Microsoft.SharePoint.Administration;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Workflow;
    using Microsoft.SharePoint.WorkflowUtil;
    using Microsoft.SharePoint.Utilities;
    using System.Security.Permissions;
    using System.Text;
    using System.Collections.Specialized;
    public class SampleExpireAlertsTimerJob : SPJobDefinition    {        //SPWeb mySiteWeb;
        public SampleExpireAlertsTimerJob(SPWebApplication webApp)
            : base("Sample Expire Alerts", webApp, null, SPJobLockType.Job)
        {            this.Title = "Sample Expire Alerts";
        }        public SampleExpireAlertsTimerJob()
            : base()
        {        }        public override void Execute(Guid targetInstanceId)
        {            string key = "TeamsRootSiteUrl";
            string TeamsRootSiteUrl = "";
            if (this.Properties.Contains(key))
            {                TeamsRootSiteUrl = this.Properties[key].ToString();
                           }
            if (!string.IsNullOrEmpty(TeamsRootSiteUrl))
            {
               
                using (SPSite site = new SPSite(TeamsRootSiteUrl))
                {                    using (SPWeb web = site.RootWeb)
                    {                        SPList list = web.Lists.TryGetList("SampleExpireAlerts");
                        SPQuery oQuery = new SPQuery();
                        oQuery.Query = string.Format(@"                                                "                                              );                        SPListItemCollection collListItems = list.GetItems(oQuery);
                        foreach (SPListItem item in collListItems)
                        {                            string weburl = item["WebURL"] as string;
                            string listName = item["ListName"] as string;
                            string dateFieldtoFilter = item["DateFieldtoFilter"] asstring;
                            int daysToFilter = int.Parse(item["DaysToFilter"] asstring);
                            string workflowName = item["WorkflowName"] as string;
                            StartAlertWorkFlow(weburl, listName, dateFieldtoFilter, daysToFilter, workflowName);
                        }                    }                }            }        }
        /// 
        /// Send remainder and warning emails to the employees        /// 

        /// Name of the employee ex: Sutha Thavaratnarajah
        /// Name of the module ex: conduct
        ///  Url retrived from the timer job property.
        /// email template ID.
        public void StartAlertWorkFlow(string weburl, string listName, stringdateFieldtoFilter, int daysToFilter, string workflowName)
        {            using (SPSite SampleSite = new SPSite(weburl))
            {                using (SPWeb SampleWeb = SampleSite.OpenWeb())
                {
                    SPList list = SampleWeb.Lists.TryGetList(listName);
                    SPQuery oQuery = new SPQuery();
                    //string userName = "Sutha Thavaratnarajah";                    string datetofilter = System.DateTime.Today.AddDays(daysToFilter).ToString("yyyy-MM-dd");
                    oQuery.Query = string.Format(@"                                                   
                                                     
                                                        
                                                         {1}                                                     
                                                   ", dateFieldtoFilter, datetofilter);
                    SPListItemCollection collListItems = list.GetItems(oQuery);
                    foreach (SPListItem item in collListItems)
                    {
                        item.Web.AllowUnsafeUpdates = true;
                        SPWorkflowManager workflowManager = item.Web.Site.WorkflowManager;
                        SPWorkflowAssociationCollection workflowAssociation = item.ContentType.WorkflowAssociations;
                        foreach (SPWorkflowAssociation Association inworkflowAssociation)
                        {                            if (Association.Name == workflowName)
                            {                                workflowManager.StartWorkflow(item, Association, Association.AssociationData, true);
                                break;
                            }                        }
                   
                    }                                  }            }        }    }}
 Source could be founded here.

Please let me know your experience if you have used this code :)

Until next Post!!!

Wednesday, May 22, 2013

SharePoint 2010 Infopath Print Button


I received a request to put a print button within a List Item display view so that one could easily print the current item they’re viewing.  After searching for a way to put a print button within the Infopath form itself (and coming up empty), I figured out how to simply add it to the page that displays the form.
The end goal
Once you have your Infopath form put together and published to a List, go to the List page.
1. Click on the “List” tab under List Tools
2. Click on the drop down arrow on the “Modify Form Webparts” button (pictured)
3. Select “(Item) Display Form”
4. This will take you to an edit page screen with your Infopath form set as a webpart
5. Add a “Content Editor Webpart” to the page
6. Edit your new webpart’s source and paste in the following:
1
2
"button" value=" Print this page "
onclick="window.print();return false;" />
Note:
tags are not required
This adds a print button to the page that uses the default print call within a browser.  Since we edited the “Display” form, the button will not appear if a user is editing the form or creating a new item.
Of course, the best part of this discovery is the added bonus of being able to add extra code to our Infopath forms, making them a much more versatile tool than they were before.

Wednesday, September 5, 2012

Removing Recently Modified


In SharePoint 2010 we all are familiar with the following annoying quicklaunch menu:
image
In SharePoint 2010, the recently modified items is one of many less-used feature. In software industry we are familiar with 80-20 principal. If 80% custom wants a feature then we should go with it and if you can satisfy 80% users then you have the successful product. I guess the ‘Recently Modified’ quick link doesn’t even needed by 10% people but the link is enable by default. Maybe this is a security feature to let administrator know what files have been modified recently. But there should have an on/off option as this is less wanted feature and most of the administrators want to hide this link. Justin has already found a way to hide the option by modifying template file asdescribed in his blog. However, we can fix the issue without modifying the shared file. Specially in case of shared hosting we don’t want to modify the files from 14 hive. The two approaches described here is implemented by modifying master page. The first approach is acceptable but may have unknown side effects. On the other hand second approach is much better and less chance of side effects.

In order to solve this problem, here is my approach:

As shown in the following screen, the ‘recently modified’ quick launch uses a css class named ‘s4-recentchanges’ (shown with firebug).
image
So we can another property ‘display:none’ to the same css class by adding the following extra attribute to master page’s header section:
<style type="text/css">
    .s4-recentchanges
    {
        display:none;
    }
</style>
You can even put the above section in a css file and refer the file in master page. The following image shows the master page with the css class:
image

If you have any problem, just let me know.

Enjoy!

Monday, September 3, 2012

Sharepoint Main Roles!


Typically in a SharePoint project the the main roles are:
  • SharePoint Administrator
  • SharePoint Developer
  • SharePoint Designer
  • SharePoint Architect
SharePoint Administrator
The role of SharePoint administrator includes setting up the SharePoint infrastructure with servers and services; SharePoint 2007/2010, Exchange Server, Active Directory, Windows 2003 and 2008 Servers, SQL Server 2005/2008, IIS 6.0 and 7.0, network infrastructure, ISA server, etc. He is responsible for maintaining and optimizing the SharePoint farm.
A SharePoint administrator requires knowledge of both SQL Server and Windows Server. Since SharePoint stores all of its data in SQL Server databases, DBA knowledge is critical. However, the Windows Server knowledge required to build and maintain a SharePoint farm is considerable. The administrator role is often split between two people who work closely together: a Windows Server administrator and a SQL Server DBA.The DBA skills required are the standard set required for any SQL Server but the features of Windows Server that a SharePoint Administrator needs to have some knowledge of include:
  • Good knowledge in IIS and the architecture of it
  • Windows Server Manager
  • Active Directory (LDAP,ADLDS,ADAM etc)
  • DNS and SMTP
  • Network Load Balancing (NLB)
  • Firewall (Hardware and software NLB)
  • Event Viewer and Performance Monitor
  • PowerShell scripting will be added advantage if looking in SharePoint 2010
But I suggest some knowledge of SharePoint development experience will add extra benefits to this role.

SharePoint Developer

The main role of a developer is developing custom web parts and component for SharePoint. They should have experience in Asp.net, C#.net, web parts, master pages, Ajax developer, detailed knowledge of the SharePoint 2007 object model / 2010 client object model, JavaScript experience etc. A SharePoint developer should be well versed on .NET frame work and windows workflow foundations (WFF). The Developer should have a solid understanding of C# and or VB.net and a solid understanding of the SharePoint API as a whole. Building workflows from a completely custom Visual studio direction as well as custom coding SQL and SQL server manipulation and maintenance also required so some knowledge in DB side also needed.  XML/XSLT knowledge will also provide some extra value in development. Since most things in SharePoint are xml based or can be converted and fed as xml/xsl, these are just another set of skills are another way that the developer can increase their value. A solid understanding of IIS and editing web config files are needed for a developer.
However, the main thing is to understand the out-of-the-box functionality and SharePoint web services well enough so that you don't program something SharePoint has Out of the box. SharePoint development involves tuning functionality that SharePoint has out of the box. So we should explain how to achieve project requirements with the least amount of programming.

SharePoint Designer

There are some wiles that a SharePoint Designer is really needed for the SharePoint project. But as per my experience it is good to have a Designer in your team so the developers can focus on programming no need to waste their time on customization. Designers are responsible for all the "non-programming" customization of the SharePoint solution. Good understanding of SharePoint and the different out of the box web parts and their functionality are needed for this role. Experience with html, style sheet, caml, xml, xslt, java script, SharePoint Designer 2007/2010 and InfoPath 2007/2010 are the main areas they have to focus.

SharePoint Architect

A SharePoint Architect needs to have a thorough understanding of SharePoint (admin, developing, functions) including when and how new components/web parts should be developed. Also Microsoft Technologies in general, especially .NET 3.5, C#, Exchange, Active Directory, Office 2007/2010, IIS and infrastructure in general. Pivotal specialized role is of SharePoint architect. This is the person who can:
1.       Collect, transform, validate and map functional and non-functional requirements
2.       Plan and architect infrastructure integration
3.       Define solution
4.       Map MOST of solution requirements to existing configurable features of SharePoint
5.       Architect and POC custom code as needed.

The Architect also needs to set up the projects environments. In some cases this can be a full blown Development, Staging and Production environment. If that is the case it's very important to have all the environments match as close as possible if not be exact. The Architect also needs to understand fail over's, clustering and load balancing, for large farms. A SharePoint Architect also needs a solid understanding of alternate access mapping in MOSS, host headers, DNS entries, Kerberos configuration and multiple forms of authentication (forms auth, ntml etc).  
NOTE: Thanks people of C# Corner!

Friday, August 31, 2012

Talking about sharepoint as a project


Hi There!
In this post, I would like to share some of my experience related to MSF.
I expect you enjoy reading this article!
Microsoft Solution Framework: 
Contains the following Phases:
  1. Envision
  2. Planning
  3. Development
  4. Stabilizing
  5. Deploying
 MSF.bmp

 
Envision
In this phase the development team must work with the client on their SharePoint vision by aligning ideas with results. This has to be done in workshops or can be done one-on-one with client and other team members. The primary activities accomplished during envisioning are the formation of the core team and the preparation and delivery of a vision/scope document. The description of the project vision and the identification of the project scope are the main activities; we have to prepare a risk document and present the top risks along with a scope document. In this phase the development team can focus on making prototype development and technology options; feasibility analysis etc. Testing team can focus on testing strategies, testing acceptance criteria, implications etc

Planning
This is one of the important phases, here we have to develop a Statement of Work functional specification, works through the design process, and prepares work plans, cost estimates, and schedules for the various deliverables. There are three levels in the design process: conceptual design, logical design, and physical design. Each level is completed and baselined in this phase. In this phase the development team can focus on technology evaluation, logical and physical design, development plans, development estimates etc. Testing team can focus on design evaluation, testing requirements, test plan/schedule etc. Here we have to develop and finalize the Master Project Plan.

Development
In this phase developers have to focus on the scope complete milestone. Most of the development activities should be accomplished in this phase but some development work may continue into the stabilization phase. Most of this additional work is bug fixing that are raised by the testing team. In this phase we have our critical deliverables source code, executables Installation scripts and configuration settings for deployment will be handled in this. From the testing team we have to deliver test specifications and test cases. Mostly development team must concentrate on code development, infrastructure development, configuration documentation etc. Testing team must focus on functional testing, issues identification, documentation testing, updated test plan etc.
Stabilizing
The Stabilize phase is the critical step in ensuring that our solution meets client's requirements and performance to the desired level of performance.  Quality Assurance, User Acceptance testing and pilot user training all take places during this phase. Once a build has been deemed stable enough to be a release candidate, the solution is deployed to a pilot group. The stabilizing phase culminates in the release readiness milestone. Once reviewed and approved, the solution is ready for full deployment to the live production environment. Some of the important deliverables in this phase is Test results, Release notes etc. In this phase the development team must primarily focus on bug resolution, code optimization etc. Testing team must focus on testing, bug reporting and status and configuration testing.
Deploying
In this Phase our solution is finalized and is ready to bring SharePoint solution live in client environment. But if tweaking is needed then that can also be done.
Next post, I will talk about Sharepoint roles and responsabilities.
Till next post!

Friday, August 24, 2012

Sharepoint Manager 2013 / SPX

Hi There,

Here I found a cool solution when you need to deleted views inherited fromm CTs.

I expect this will help you!

Nice Coding!

Steps:


  • Connect to your site – using the “Connections” menu
image
  • Expand the RootWeb node – and then Webs
  • Find the Web you’re looking for – check within the Webs node (for sub-webs)
  • Expand the Lists node
  • Find the list you’re looking for – for my case it’s “OATR_Test1”
image
  • Expand the Views node – and you’ll see the RELINK and MERGE entries
  • Right-click – and select “DeleteObject” (these are methods via Reflection)
image
  • Repeat for both MERGE and RELINK
  • Can close out of SPx / SharePoint Manager
That’s all you need to do !    If you look at the site/library – you’ll see they’re GONE.
image
Hopefully this helps with your SharePoint environment – viva la SPx !!
Smile