Friday, November 25, 2016

Sharepoint 2013 Change Sharepoint Branding text in Top Left

In Sharepoint instance, we see a branding text 'SharePoint' on top left corner of the page.

There are multiple ways to change this text to our organization branding. Few of the easy approaches are as below.

Approach 1: Using Powershell.
In Powershell, we have a property SuiteBarBrandingElementHtml for webapplication using which we can read and set the Branding Element HTML. Use below code to read and set the text.
 #Add powershell snapin  
 Add-PSSnapin microsoft.sharepoint.powershell  
 #Get web application  
 $webApp = Get-SPWebApplication http://metisqa.broadridge.net/  
 write-host "Original Branding Text"  
 #read brand elemnt html  
 write-host $webApp.SuiteBarBrandingElementHtml  
 #Set Branding Element HTML. can include styles / class file as below   
 $webApp.SuiteBarBrandingElementHtml = "<div class='ms-core-brandingText'>Your Company Name</div>"  
 #Update the webapplication to reflect above changes  
 $webApp.Update()  
 write-host "Updated Branding Text"  
 #read existing brand elemnt html  
 write-host $webApp.SuiteBarBrandingElementHtml  

We can also set Images / hyper links in the branding text by simply setting the required HTML tagged text.

Approach 2: Using CSS
As the Branding text tag holds as CSS Class 'ms-core-brandingText', we can update styles around this class and change display  using 'Content' style attribute.
 .ms-core-brandingText:after  
 {   
      content:"Your company Name";  
      padding-left:10px;  
 }  
 .ms-core-brandingText{  
      margin-left: -95px;  
 }  

In this approach we can set images using css property background-image, but can't set any links to the branding element.

Approach 3: JavaScript / JQuery
Update html text in the html branding text tag. this can be achieved easily using the CSS class 'ms-core-brandingText'
 //Jquery code to set branding text  
 $('.ms-core-brandingText').html('Company Name');  
Here, we can also set image / hyper links by setting required html content in above code.

By using any of the above approached, it appears as below.


Wednesday, November 23, 2016

Project Professional 2013 Add-in using Visual Studio

In this article, I will walk through creation of a simple Add-in for Project Pro 2013 using Visual Studio 2013 and C# to add a new task when project load and also on a custom button click in Ribbon.

Step 1: Open Visual Studio 2013 and Create New Project, Select ‘Project 2013 Add-in’ from Installed -> Templates -> Visual C# -> Office/Sharepoint ->Office Add-ins

Step 2: Provide a Name for the project and click on Ok.

Project 2013 Add-in solution is created and it comes up with ‘ThisAddIn.cs’ class file and also the class has 2 default event handlers one is to trigger on Add-in Startup and other is on shut down.
 
Step 3: As one of our requirement here is to create a new task when Project loaded, let us create a method to add new task with defaults and attach this method to Project Load event handler in Startup method.
 

And the code is as below.
 //Method  
 void AddTask(MSProject.Project pj)  
 {  
    MSProject.Task newTask = pj.Tasks.Add  
       ("This text was added by using code on addin startup", missing);  
    newTask.Start = DateTime.Now;  
    newTask.Duration = "3";  
 }  
   
 //To add the above method to event handler  
 this.Application.NewProject += new   Microsoft.Office.Interop.MSProject._EProjectApp2_NewProjectEventHandler(AddTask);  

Step 4: As the other requirement is to create a task on button click in ribbon, let us add ribbon tab to this project. To do this, click on add new Item to the solution in Solution Explorer and under Installed -> Visual C# Items -> office/Sharepoint Select ‘Ribbon (Visual Designer)’. With Visual designer option, we will be able to drag controls from toolbox.

Step 5: with this, CustomRibbon class file and corresponding designer file are added to solution and it appears as below
 
Here we can rename label of ribbon and also the group name using properties window of corresponding control.

Step 6: Using toolbox, from Office ribbon controls section select button. There are lots of other controls and also we can add more tabs by right clicking on design screen in tab area.

Step 7: Add Image to button and also label the button from property screen and finally it appears as below 

Step 8: By double clicking on the button, it redirects to class file with button click event handler created and attached to the corresponding button. This can also be done through properties window.
In the event handler method, let us write the required code to add a new task to the current plan loaded 

And the code is as below,
 MSProject.Project currProject = Globals.ThisAddIn.Application.ActiveProject;   
 MSProject.Task newTask = currProject.Tasks.Add  
    ("This text was added by using code on button click",Type.Missing);  
 newTask.Start = DateTime.Now;  
 newTask.Duration = "3";  
With these steps, we completed the implementation and to test it, click on ‘Start Debugging’ and it opens up the Project Pro. Select the environment and click on a “New project” or select an existing project.


Note: Once we run the solution, it creates a set of registry entries and also some security settings are configured to enable this add in.
So, once tested, remove the above created entries and changes by cleaning the solution.