Saturday, March 16, 2013

Deploying Master Pages & Themes via a Feature using Visual Studio 2010

Following this guide you’ll see the process that goes behind creating the feature which commonly be used to deploy branding items such as Master Pages, CSS, JavaScript, & Themes. If you plan to follow along just replace the steps with my name with whatever you wish.

Configure the Project

  1. Open Visual Studio 2010
  2. File -> New -> Project

  1. Select SharePoint -> Empty SharePoint Project
  2. Add Name: TomDaly.SharePoint.Branding (this is my standard structure)
  3. Add Location: C:\Projects\TomDaly

  1. Click OK
  2. Enter your test site for debugging purposes.
  3. Select ‘Deploy as farm solution’

  1. Click Finish

Adding the CSS / Image / JavaScript Files

Add CSS file

  1. Right Click on the Project -> Add -> SharePoint ‘Layouts’ Mapped Folder

  1. This created a folder which is mapped to the layouts

** These files in here are accessible through the web via http://YOURSITE/_layouts/TomDaly.SharePoint.Branding/
  1. Right click on Layouts\TomDaly.SharePoint.Branding folder -> Add -> New Item

  1. Select Web on the left, and Style Sheet on the right, and Name the file at the bottom.
(I typically use base.css or style.css for the foundation of my styles, but this is all up to you)
  1. Click Add

Add Images & JavaScript Folder

This would be the location for any images associated with the site css.
  1. Right Click on the Layouts\TomDaly.SharePoint.Branding folder -> Add -> New Folder

  1. Name the folder ‘images’

OPTIONAL STEP
  1. Repeat Step 1 & 2 for the JavaScript folder. (I typically call this folder ‘js’)

I usually include a JavaScript folder because most of the time I end up using jQuery somewhere on the site, this is where I store those files which I would reference on page or in the Master Page. Depending on how it’s needed.
These files would be accessible: http://YOURSITE /_layouts/TomDaly.SharePoint.Branding/js/JSFILESHERE

Setting up the Feature

  1. In your project Right click on Features -> Add Feature

This will create a feature with some default name of ‘Feature 1′, which we don’t want
  1. Select Feature1, Right Click -> Rename

  1. Rename the Feature to TomDaly.SharePoint.Branding (I typically name it to the same as the project name)

  1. Double Click on your Primary feature, in the main left hand window the properties should appear

  1. Give your feature a normal title name Title and Description, and scope it accordingly. (I usually scope my master pages to (Site) as they are normally used through the site collection

  1. Click Save

Renaming the WSP

This is really annoying to me so I always change it. When a .WSP is generated it will usually come out as Feature_Feature.wsp. I prefer just Feature.wsp.
1. Double Click on the primary Feature, the Properties should appear right below it.
2. Change ‘Deployment Path’
From: $SharePoint.Project.FileNameWithoutExtension$_$SharePoint.Feature.FileNameWithoutExtension$
To: $SharePoint.Project.FileNameWithoutExtension$

Adding the Master Page

1. Right Click on the Project -> Add -> New Item

2. In the left Installed Template column, Select SharePoint 2010
3. On the right select Module
4. At the bottom name the Module, Master Pages

5. Click Add
** You module will be added to your project **
6. Under the Master Pages Module, right click on Sample.txt and Delete It

7. Now Drag & Drag and Drop your Custom Master Page from another folder into the project, In the Master Pages Module

8. Double Click on the Elements.xml in the Master Pages Module

9. In the Elements.xml file, make the following changes to the <Module> line
Change
<Module
Name=MasterPages>


To
<Module
Name=MasterPages
Url=_catalogs/masterpage>


10. In the Elements.xml file, make the following changes to the <File> line
    a. add IgnoreIfAlreadyExists=True

    b. add Type=GhostableInLibrary

    c. remove MasterPages/ from the
Url=MasterPages/TOMDALY.master


So essentially this line
<File
Path=MasterPages\TOMDALY.master
Url=MasterPages/TOMDALY.master />


Changes to

<File
Path=MasterPages\TOMDALY.master
Url=TOMDALY.master
IgnoreIfAlreadyExists=True
Type=GhostableInLibrary />


11. Click Save

Adding Theme

This step will incorporate a theme into your project. How to generate the .thmx is not covered here but a simple way would be to export from PowerPoint or use ThemeBuilder to generate this file.
1. Right Click on the Project -> Add -> New Item

2. On the left Click SharePoint -> 2010
3. On the Right Select “Module”
4. Add Name: Theme

5. Click Add
6. In the Theme node, Delete Sample.Txt

7. Copy in you custom .thmx file
8. Double Click on the Elements.xml in the Theme Module

9. In the Elements.xml file, make the following changes to the <Module> line
Change
<Module
Name=Theme>


To
<Module
Name=Theme
Url=_catalogs/theme>


10. In the Elements.xml file, make the following changes to the <File> line
    a. add IgnoreIfAlreadyExists=True

    b. add Type=GhostableInLibrary

    c. remove Theme/ from the
Url=Theme/TomDaly.thmx


So essentially this line
<File
Path=Theme\TomDaly.thmx
Url=Theme/TomDaly.thmx
/>


Changes to

<File
Path=Theme\TomDaly.thmx
Url=TomDaly.thmx
IgnoreIfAlreadyExists=True
Type=GhostableInLibrary />


11. Click Save

Adding the Feature Receiver

This whole step is optional. Its sole purpose is to automatically turn on the branding on the sites and subsites, apply a theme, or apply search master pages to your site collection. NOTE: If you changed the scope then there is no guarantee that this code will work.
Please take some time to look through the code as there are different sections you might want to comment out or fill in. Say if you want to configure the Site Logo or an Alternative CSS file. If you not interested and just want a working project jump down to the END and in the summary there is a link to download the project.
1. Right Click your primary Feature, Select Add Event Receiver

** This will get added Right under your feature**
2. Double Click on the new file TomDaly.SharePoint.EventReciever.cs

5. At the very top Add the following using statements
using Microsoft.SharePoint.Utilities;

using System.Collections.ObjectModel;


7. Under the class declaration add these three string constants which contain the names of the masterpages and the theme.

So my master page name is TomDaly.master, my search master page which I don’t have a custom one for yet is minimal.master, and my Custom Theme is called TomDaly
8. Replace the public override void FeatureActivated, with

public override void FeatureActivated(SPFeatureReceiverProperties properties)

{

SPSite site = properties.Feature.Parent as SPSite;


if (site != null)

{

using (SPWeb topLevelSite = site.RootWeb)

{

//Get the relative path

string relativePath = topLevelSite.ServerRelativeUrl;

if (!relativePath.EndsWith(“/”))

{

relativePath += “/”;

}


//Get Theme collection from site and the them we want

ReadOnlyCollection<ThmxTheme> themes = ThmxTheme.GetManagedThemes(site);

ThmxTheme customTheme = null;

foreach (ThmxTheme theme in themes)

{

if (theme.Name == themeName)

{

customTheme = theme;

break;

}

}


//Apply branding to each web in the site collection

foreach (SPWeb web in site.AllWebs)

{

//Apply masterpage and logo

if (web.WebTemplate == “SRCHCENTERLITE” || web.WebTemplate == “SRCHCEN” || web.WebTemplate == “SRCHCENTERFAST”)

{

web.CustomMasterUrl = relativePath + “_catalogs/masterpage/” + searchMasterPage;

}

else

{

web.MasterUrl = relativePath + “_catalogs/masterpage/” + masterPage;

web.CustomMasterUrl = relativePath + “_catalogs/masterpage/” + masterPage;

}


web.AlternateCssUrl = “”;

web.SiteLogoUrl = “”;

web.UIVersion = 4;

web.Update();


//Also apply the theme

if (customTheme != null)

{

customTheme.ApplyTo(web, true);

web.Update();

}

}

}

}

}

9. Replace the public override void FeatureDeactivated, with
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)

{

SPSite site = properties.Feature.Parent as SPSite;


if (site != null)

{

using (SPWeb topLevelSite = site.RootWeb)

{

//Get the relative path

string relativePath = topLevelSite.ServerRelativeUrl;

if (!relativePath.EndsWith(“/”))

{

relativePath += “/”;

}


//Apply branding to each web the wen the site collection

foreach (SPWeb web in site.AllWebs)

{

//Apply default masterpage and logo

if (web.WebTemplate == “SRCHCENTERLITE” || web.WebTemplate == “SRCHCEN” || web.WebTemplate == “SRCHCENTERFAST”)

{

web.CustomMasterUrl = relativePath + “_catalogs/masterpage/minimal.master”;

}

else

{

web.MasterUrl = relativePath + “_catalogs/masterpage/v4.master”;

web.CustomMasterUrl = relativePath + “_catalogs/masterpage/v4.master”;

}


web.AlternateCssUrl = “”;

web.SiteLogoUrl = “”;

web.Update();


//reset the theme back to default

ThmxTheme.SetThemeUrlForWeb(web, null, true);

web.Update();

}

}

}

}

10. Click Save
11. Hit F6, or Build -> Build Solution … to ensure that everything is correct and ok. You should receive the “Build Succeed” in the bottom left corner



Changing the Site Url for Testing

Sometimes you want to create or re-use this package and you need to change the url of the site to deploy to.
1. Click on the project and in the Properties window you’ll notice the Site URL

2. Change that to your new site destination
3. Click Save

Deployment

If you’re testing on a development box, that visual studio is on then you can simply deploy through visual studio. Otherwise you’ll have to push out your solution with the .wsp file.

Deploy from Visual Studio

1. In the Build Menu, Select Deploy

OR

Getting the .WSP for manual deployment

1. In the Build menu, Select Build to ensure no errors
2. In the Build menu, Select Package to generate the .WSP file

3. The files will be in the project folder, and by default in the BIN\DEBUG
Either way once you deploy your solution should be available in the Site Collection Features Gallery as shown here

Summary

So that’s how you setup a project for deploying branding assets. This is the typical setup I use but can change from client to client depending on their needs.

When to use Allow Unsafe Updates

AllowUnsafeUpdates is set to true when you are trying to update the database as a result of the GET request.
Say you have a list and you want to update something, then you need to set AllowUnsafeUpdates = true for the web and after you have done you need to set it back to false.
AllowUnsafeUpdates = false protects from cross site scripting.
So if you need to allow your code to make some updates, you need to set allow unsafe updates to true and then back to false as soon you update.
SPList list= web.Lists["list name"];

SPListItemCollection items= list.GetItems();

web.AllowUnsafeUpdates = true;
foreach (SPListItem item in items)
{
     item["Field"] = "new val";
     item.Update();
}
web.AllowUnsafeUpdates = false;

Also refer following links for more idea.
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.allowunsafeupdates.aspx
http://blog.animesh.co.in/2010/03/sharepoint-spsiteallowunsafeupdates.html

Difference between SharePoint 2010 and 2013


Very briefly i will tell what are the major changes in SharePoint 2013 on above of 2010

First thing is it 14 hive folder has been moved to 15 hive folder and it is also called as SP15

Shredded storage this is used for storing the version updates in documents and stores locally
Workflow manager for 2013 which is also called as windows azure workflow which can be only used for SharePoint 2013
workflow service manager - this is an integration layer between SharePoint and workflow manager
workflow manager should be installed in separate farm server where SharePoint is not installed

SharePoint is now with HTML 5

content search web part(CSWP) new in SharePoint 2013

Distributed cache service which is a new service located in services on server this is used for cache in SharePoint and also used for rendering of docs more faster than previous versions

Minimal downloaded Strategy(MDS) : when a document is downloaded to SharePoint server it will create a copy locally and keep it in cache when ever changes happens it will only download the changes that are made not the whole document
MDS will not be enabled for publishing site
Enable minimal download= True is the property for enabling MDS and it is a feature in SharePoint 2013

Now using Open XML/Power point/word 2010 we can create themes in SP15 and the extension for this is .thmx

Three new services had been included in SharePoint service application:

  • Machine Translation( only this can be used across farm servers)
  • Work Management
  • App Management


Usage.xslx is an excel file in webanalytics used to see the usage of user and you can see this option in site settings--> site administration--> property trends

In SP15 webapplications are by default claims based authentication
and this calims based authentication supports

  • windows claims
  • SAML- based claims
  • Forms based authentication claims

Hosted name site collection: these site collections should have public IP and DNS examples for these site collections are
http://hr.adventure-works.com
http://it.adventure-works.com
(SP15) this is a new change in SP15

http://intranet.adventure-works.com/sites/hr
http://intranet.adventure-works.com/sites/it
(sharepont 2010) this is a old version


Saturday, January 19, 2013

How to get data from multiple lists in SharePoint

In this article I am showing you how to display data from two lists in one data view using share point designer 2007

Here I am taking the example of two list say Task and Contact list

Image1.gif



1. First of all you have to open the share point site in share point designer And then open the page where you want to insert data view.

2. Click on Insert -> Share point Controls-> Data view by selecting a web part region in your page.

Image2.gif

3. From the Right top region from the data Source Library go to Linked Source.

4. Click on Create linked source as shown below.

Image3.gif

5. Following pop up will come .From there select Configure Linked Source.

Image4.gif

6. Select the contact and Task list as shown below.

Image5.gif

7.
 Click Next. From the next screen choose Join the contents of the data sources and click Finish.

Image6.gif

8. Now you get popup as shown below Go to General Tab ad Give a proper name for our Linked source. Click OK.

Image7.gif

9. Now our linked Source will be added to Data Source list as shown below. Select Show Data.

Image8.gif

10. Now you can see the data from Two list (Contact and Task are displayed in the Linked source).

11. I have selected Phone number from Contact, Title and priority from task List.

Image9.gif

12. Now please drag the items you selected to the region where you want to display the dataview joined with two lists.

Image10.gif

13. Click save and check in your changes.

Saturday, December 15, 2012

Types of Content Management in SharePoint

  • Document Management
  • Metadata Management
  • Records Management
  • Web Content Management
  • Digital Asset Management

Types of workflows in SharePoint Designer 


This article is the third in the series trying to demystify all that SharePoint Designer 2010 has to offer. Check out the other two articles here:
User Interfaces of SharePoint Designer 2010
Site Level Customizations and Settings using SharePoint Designer 2010
Also, related to this article, you can obtain the SharePoint Designer 2010 Workflow videos we have available here:
SharePoint Designer 2010 Workflow Videos

Types of Workflows

The Workflow Designer in SharePoint Designer 2010 is used to create workflows on the currently opened SharePoint site. There are 3 types of workflows that can be created using SharePoint Designer: List, Reusable, Site.

Each type of workflow has its reason for existence and will be (should be) used by used by Site Admins, Power Users and Designers of the site. Workflows in SharePoint sites are used to create robust processes using components of the site. They can interact with users, lists and libraries. The other ways to create workflows on top of SharePoint are Browser based and using Visual Studio. Out-of-box browser based workflows are good for many scenarios, but they are simpler in nature and cannot be modified further using the browser. While Visual Studio workflows are extremely powerful and scalable, but require coding skills to implement.
Following is a quick breakdown of how the 3 SharePoint Designer workflows are used and why you would use them:
List Workflow – Using this mechanism, you attach the workflow directly to a list or library on the site. Use this workflow when you are making a workflow that’s very specific to a list or library and does not need to be later used on a different list or library.
Reusable Workflow – This type of workflow is created with reusability in mind. Create a reusable workflow when you intend to attach it to a content type and use that content type in a list or library.
Site Workflow – Site based workflow does not require to be attached to a list or library. It works on the site itself. Use this workflow if you do not want to restrict the automated process to a list or library on the site. For example, you can use the site workflow to take a survey of the site members or to execute a process on a Document Set (new functionality in SharePoint 2010).
You don’t necessarily have to start creating a workflow from scratch. The out-of-box workflow templates (Approval, Collect Feedback and Collect Signatures) that can be used in the browser can also be extended using the workflow designer. Meaning, if you like the way these workflows work, but just want to tweak it to your liking, you can do that! These workflows are categorized as Globally Reusable Workflows and are visible and available at every site in the site collection.

A word of caution: Be careful while working with these! If you modify any of these from directly the root site of your site collection, then you are modifying the actual workflow template that’s in use at your site collection. Whatever changes you make will take effect everywhere in your site collection where this workflow is being used. If you click on any of these workflows from a subsite, it will instead inform you that a copy of the workflow will be made that you can further modify (I would recommend doing this and Not changing the out-of-box workflow template).

Workflow Designer Interface

Let’s look at the workflow designer interface that’s used to configure the workflows. You get to the design interface by either creating a new workflow or by clicking on an existing workflow and then clicking on the Edit Workflow link on the summary page of the workflow.

The workflow designer interface is where you define the complete logic of the workflow. To put it simply, SharePoint Designer workflows consist of steps which are executed sequentially in the order they are placed in the workflow designer. Clicking on the Step button in the ribbon inserts a new step in the workflow designer interface. Within the step, you can place Conditions and Actions. Clicking on the Condition button will show you all of the conditions that are available.

A conditional logic statement is used to look out for a specific possibility. If the condition is true, then whatever is encapsulated within the conditional block will be executed. Otherwise, the workflow process will move on to the next conditional logic statement (if one exists). Programmers have been using the conditional logic construct (If… Else If… Else) for decades now. Now information workers also have the power to write their own business logic without coding!
Actions are the actual statements which execute a certain activity (ex: Creating a List Item, Checking in an Item, Sending Email etc). The image below shows a snapshot of a partial list of the actions available in the designer environment.

Parallel Block

Each of the actions and conditions can be moved around rather easily within the step or even from one step to another. Just click on the action/condition you would like to move and click the Move Up or Move Down button in the ribbon. The default nature of the actions you place in the workflow steps is sequential. The first action takes place then the next and so on. This is made evident by the word then that appears preceding every action within the step after the first action. There will be many instances where you need the actions to take place in parallel. For example, if an action calls for collecting data from a user, the process will not move on to the next action until that action is accomplished and the user who the data is being fetched from provides the data. If you want actions to fire in parallel, you can use the Parallel Block functionality. You first start by placing the parallel block within the step right up close to the actions you want to run in parallel and then by clicking on the Parallel Block button in the ribbon.
The below animation highlights the following:
  • Moving actions up and down
  • Parallel block
SharePoint Designer 2010 Workflow Designer-1
Remember that there is no Undo button in the workflow designer so that if you make a mistake, you just need to undo it manually the old fashioned way :-) .
That’s it for now. I’ll be back with more information on workflows in my next article. There are still many things to be discussed such as workflow settings, impersonation steps, parallel blocks, association columns, nested steps and a whole lot more. Stay tuned…

Setting Time stamp for a workflow in SharePoint Designer workflow


" Set Time Portion of Date/Time Field" workflow action - description, tips, limitations etc.workflow actions - Set Workflow Variable




Use this action to create a timestamp, and stores the output value in a variable. You can set the time in hours and minutes and add a current date, specific date or a lookup.

Allows you to set a date value with a specific value for hours and minutes

The date can field can be either today, a specific date or a lookup

Example scenarios:

1) Suppose you want to add a timestamp to any new customer orders that is added to an orders list. Instead of using the current time of the order received in the timestamp, you want to add a specific time so that you can have your workflow perform any action to all the new items with the same timestamp, such as routing orders to the warehouse.

2) You have a presentation at 9 a.m. on a particular day, and would like an email reminder. You can use this action to add the time to the date, pause the workflow till the day before the presentation and then have the workflow send you a reminder.

SharePoint - Cannot convert a primitive value to the expected type 'Edm.Double'. See the inner exception for more details If y...

Ad