Monday, July 11, 2011

CLAIMS BASED AUTHENTICATION in SharePoint 2010

Authentication??

Authentication, in simple English, we say “The Person is Actually the one what he/she claims to be”.

Like in Famous James Bond Series, if Black Suited, Maybach Driving guy says to you, HI I am Bond , James Bond, will you seriously going to believe him, until or unless you see his ID or “Solid Action” the same thing implies with Technology, and we have to provide a way to our websites, so that  system can authenticate this is the James actually trying to Login the Site.
Microsoft Provides for example Active Directory, in which we can create rules belongs to person and Groups and let the system recognize the access accordingly.

Suppose if James tries to login to our site and he is member of 007 Active Directory and yes it does have access to our site, so James will get access. Till the time our site is running on the basis of Active Directory to which all users of site belong we will have no issue,we don’t need Claims Based Authentication in this .

but this is not the case in General.

So where does requirement comes:


1. Sometimes Rules, Company Laws, etc doesn’t allow to capture everything and publish on the sites, means we cannot ask a user to provide all his personal information and place it on an open internet site.
Example, why a girl who is actually a lady but doesnt look too aged, like to reveal his age to anyone.

2. We work in a Network Environment, where Business Communicates with Other Business and not everyone does have the same Active Directory Authentication and even if they have then it might not be necessary that it will have the same instance of “AD”, Still organization like to provides maximum integration facilities to its users.

So here we go with Claims Based Authentication, it addresses the above challenges.

It addresses privacy and ask very less personal Information from the user and by trusting other parties or systems to do the “proof of identitycheck.

So what does Claims Based Authentication do?

Suppose we have to create a site for a “Pharma Company” which sales its medicines worldwide, called xyzPharma.

But hold on Before implementing authentication, we need to make sure that are we implementing the thing which will pass legal laws of Global Countries, take for example in U.S there are many Supplements/ Shampoos or even drugs which are banned but they are legal in Some other company, so if we have to make this implementation cut to clear then how can we do it, answer is very simple ”Claims Based Authentication”, at the same time we need not to ask who actually the person is,!



It turns out that in the country, the Government has set up a web service that users log on to, which authenticates them based on their citizenId and citizenPassword. It then is able to tell other systems that a user is their country citizen or not, without revealing who that user is.

So we implement our “xyz pharma” website by building a claims-aware system. Instead of building the standard “username and password” login mechanisms, we simply ask the Government’s web service to tell us if the user browsing our site is of which country. The claim that our system uses is a “userCountry” claim, and the claim value is either yes or no. We simply don’t build any authentication system at all beyond a simple “if (userIsofCountry) then..“ statement.


By doing this, we address privacy concerns – we don’t know or keep personally identifiable information – while at the same time ensuring that we don’t sell drugs to someone where it is banned.

Claims Based Authentication:


It actually integrates the different systems by allowing communication via open standards and does provide platform to develop more specialized “identity connectors” between systems.



How is it implemented?

The claims-based authentication implementation has a number of components. In simplified terms here’s how the pieces of technology fit together.

• From a developer’s point of view, the platform that Microsoft is providing is called the Windows Identity Foundation. This used to be called the Geneva framework. It provides a programming library suitable for building claims-aware applications. This library is also used by SharePoint 2010.


• Active Directory Federation Services implements services to create, accept, and transform tokens that contain claims.


• Cardspace provides a user interface for users to select which “identity card” they wish to use for a particular system


For More details read this very good article on Claims Based Authentication:
Claims Based Authentication-Part1

Thursday, May 26, 2011

How To add a pdf icon in Sharepoint sites

So, Why not pdf icons are included in sharepoint?
Let the answer be unspoken.
but how to add that, so when we create a doccument library, icon will appear when we upload a pdf file?

So here we go with steps.

1)Copy pdf_smallicon from adobe site.
2)Open 12\Template\Images folder
3)Paste it in that.
4)open Docicon.xml file which is over here : 12\Template\XML\Docicon.xml
5)Go to tag
6)Add this


7)Thats all, go ahead upload any pdf file now and see the magic...

LINQ to Sharepoint 2010.

LINQ (New Data Access Paradigm), when i hear it for the first time, i was sitting in a seminar and dotnet geeks were giving long lectures on it.It will make developer's life more easy.....

LINQ is a new data access paradigm which allows users to express SQL like syntax against a variety of data sources. LINQ can improve performance by allowing the back end data source to decide the best way to solve the query.
Was Amazed when used it in 2007 days for filtering CAML returned data.

CRUDQ options were allready there for maiking things good for us. but still there was something easy to implement was missing.

And finally with 2010 Microsoft given us LINQ to SharePoint.
Namespace Microsoft.SharePoint.Linq.

For people who are wondering , what is the use of it when we have CAML and more things availlable.

So for those the answer i have is its very fast, Even perform all CRUDQ options, you can bring data from multiple List and as well its very easy to write and intelliscence support we have for gettting the column names and more of the things for which we struggled alot in past looking deeper in internal names of the columns ows_xyz...

SharePoint now fully supports LINQ for querying lists so that you can query information from the platform in a more condensed, easier to understand format.



SPMETAL, the new command line utillity we have for providing the basic structure for LINQ.

In this Post i will be sharing my own experience of working with it and using LINQ to SHAREPOINT.

Writing LINQ queries are very easy but tricky things comes with SPMETAL generated code and how to use SPMETAL utillity and usage of Parameters.xml as parameter file in the command line and as well the way of utillizing the data fetched by LINQ query on EntityList.

First we will take the brief on how LINQ does the Processing(building CAML in the background and then we will come to SPMETAL and way to create the code using Parameter.xml and also i will take the case what if some fields doesnt appear the code file,how to do hard fixing(the term i normally say) )

Next i will explain, how to query with scope recurssive when querying Document Library for Folders.

In the end i will explain how to bind the data to a GridView with Template Columns to the Ienumerable list of data returned by LINQ query.

Monday, February 14, 2011

MOSS to Sharepoint 2010 site Upgrade

Hello Folks Now as we have SharePoint 2010, most of us are looking forward to upgrade their present Moss site to their new SharePoint 2010 farm, this blog of mine will represent that only:

Just follow these steps:

Requirements
Before we Begin to do this amazing task let us discuss our requirements:
1) SharePoint Server 2010.
2) SQL Management Studio 2010.
Also the requirement is that the MOSS or wss site from which we are going to migrate to 2010 should be hosted in a farm with SP2 Upgrades of respective versions.

Initial Preperation
Following are the tasks which we are going to do here:
1) First take the Backup of MOSS/WSS hosted web application using SQL Management Studio 2005.
Remember we have to be very concise about naming of the backups, it should be consistent and same, with what is there right now, that’s why with MOSS SDK , Microsoft suggests:” please do change the name of Content Database while creating a web application”. See Below the best practice for creating a web application:






NOTE: we are migrating whole web application, so whatever sites will be there in web application will get migrated as well.
This is application Based migration.

•Taking Backup(on MOSS/WSS Farm)




For taking back up follow these steps:
1) Go to Microsoft Sql management studio 2005, open the relative Sqlserver instance and then look for the “WSS_Content_31477”, which we created specifically for this application.























After restoring the database, Now provide the Web Application’s application pool Identity user “dbo.owner” rights for this database.

•Creating a Web Application in 2010
Now we will create a web application and on this application we will attach our WSS_Content_31477 database.
Go to central admin, create a new web application, please name the content database keeping in mind that we have to remove this later.
Go to manage applications and create a new web application:



Now we will delete its current database and attach our own database,
For doing that go to manage content database and select the current web application



Click on this particular database, Make the status to OFFLINE:



















And press ok with Remove content database selected.
Now we have done with our detaching of database, now we will add our database to this web application using Powershell.
Open Sharepoint Powershell command prompt.
And write this command:

Mount-SPContentDatabase –Name WSS_Content_31477
–WebApplication “http://nameofwebapplication:port/

A timer will start:













Which will display the current status of attaching wait once it get 100%.

When everythings goes fine then it will show follow screen with 100% status
















Now its time to change the Site Administrators, WHY?Farm is new so could be possible we are at new Active Directory or Administrator could be Domain Specific, if your active directory is same then need not to worry about this section

For changing the Site administrators , In application management go to change site administrator and assign new administrators for this application.



















Now its time for the Main action open your site collection in the web application.












Enter the credentials of the new administrators and here we go…

Now a surprise will comes to you, You will see the same 2007 site in 2010 with exactly same look and feel,














this is not what we require, So what to do next, for this go to next section : Visual Upgrade.

But the good thing was that everthying work exactly the same:

Search Working like it works in moss and everything was fine. Lets see if it remains same in next step:


•Doing Visual Upgrade
Now we will bring 2010 on it.
1)We will bring Ribbon and 2010 feel.
2) If necessary we will change master page config
3)We will cross check the functionality.


Now go to site actions and then site settings













And then press Visual upgrade right below


















And Update all sites, and that was it.

HURRAH…We Done IT..Finally:


Tuesday, August 17, 2010

Command to reset the sharepoint databases, if u r reinstalling Sharepoint

Click Start, click Run, type cmd in the Open box, and then click OK.
At the command line, change to the following directory:
\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
At the command prompt, type the following command to create a new configuration database:
psconfig -cmd configdb -create -server ServerName -database ConfigDBName -user Domain\User -password Password
Rerun the SharePoint Products and Technologies Wizard.


http://support.microsoft.com/kb/927156

Monday, June 28, 2010

Creating Attractive Bar Charts based on data in sharepoint lists and Surveys.

Errr..Reporting of sharepoint sites, data and lists and the backbone for it are sharepoint charts.We have KPI webparts and so many other things in Sharepoint, But today i am discussing how can we generate Charts using data from sharepoint lists..
So lets discuss how we are going to do this ??

I am creating a sharepoint webpart which will bring the data from a survey and represent it in a wonderfull bar chart, not the basic simple one...




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI.DataVisualization.Charting;
using Microsoft.SharePoint;

namespace ChartingMS
{

[ToolboxData("<{0}:Charts runat=server>")]
public class Charts : WebPart
{
System.Web.UI.DataVisualization.Charting.Chart Chart1 = new System.Web.UI.DataVisualization.Charting.Chart();
CheckBox ShowLegend = new CheckBox();
int agree = 0;
int disagree = 0;
protected override void OnLoad(EventArgs e)
{
Chart1.Legends.Add("Legend1");
Chart1.Legends["Legend1"].Enabled = ShowLegend.Checked;



}
protected override void CreateChildControls()
{
remotecount();
ShowLegend.AutoPostBack = true;
ShowLegend.Text = "Show Legend ";
Chart1.Width = 500;
Chart1.Height = 320;
Chart1.RenderType = RenderType.ImageTag;
string imagespath = System.Configuration.ConfigurationSettings.AppSettings["ChartImageHandler"].ToString();
Chart1.ImageLocation = imagespath + "ChartPic_#SEQ(200,30)";
Chart1.Palette = ChartColorPalette.BrightPastel;
Title t = new Title("Each ministry should work independently to automate their own processes using their internal IT manpower. ", Docking.Top, new System.Drawing.Font("Trebuchet MS", 14, System.Drawing.FontStyle.Bold), System.Drawing.Color.FromArgb(26, 59, 105));
Chart1.Titles.Add(t);
Chart1.ChartAreas.Add("Agree");
// create a couple of series
Chart1.Series.Add("Agree");
Chart1.Series.Add("Disagree");
// add points to series 1
Chart1.Series["Agree"].Points.AddY(agree);
//Chart1.Series["Agree"].Points.AddY(8);
// Chart1.Series["Agree"].Points.AddY(12);
// Chart1.Series["Agree"].Points.AddY(6);
// Chart1.Series["Agree"].Points.AddY(9);
// Chart1.Series["Agree"].Points.AddY(4);
// add points to series 2
Chart1.Series["Disagree"].Points.AddY(disagree);
//Chart1.Series["Disagree"].Points.AddY(6);
// Chart1.Series["Disagree"].Points.AddY(18);
// Chart1.Series["Disagree"].Points.AddY(16);
//Chart1.Series["Disagree"].Points.AddY(21);
//Chart1.Series["Disagree"].Points.AddY(14);
Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
Chart1.BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
Chart1.BorderWidth = 2;
this.Controls.Add(Chart1);
this.Controls.Add(ShowLegend);
}


protected override void RenderWebPart(HtmlTextWriter output)
{
RenderChildren(output);

}

public void remotecount()
{
SPSite osite = SPContext.Current.Site;
SPWeb oweb = SPContext.Current.Web;
SPListCollection lists = oweb.Lists;
SPList survey = lists["Ministry Survey"];

SPQuery oquery = new SPQuery();
oquery.Query = "";
SPListItemCollection items = survey.GetItems(oquery);
foreach (SPItem item in items)
{
if (item["ows_Each_x0020_ministry_x0020_should"].ToString() == "Agree")
{

agree = agree + 1;
}

if (item["ows_Each_x0020_ministry_x0020_should"].ToString() == "Disagree")
{

disagree = disagree + 1;
}





}




}


}
}

Wednesday, June 23, 2010

Displaying Image Attachments of a list Item Sharepoint wss3.0


Heya, Again Old Ankur, With a new post.
I am Loving the way Client Object Model with Ecma Script functions in Sharepoint2010.
Well but in this post I am picking up an issue of WSS 3.0 or sharepoint 2007.


Today I was onto a task creating a helpful site on MOSS. In that I was trying to attach a automated generated Image file with the item in a list.

I started with an idea that In the DispForm of the list I will show the attached Image as well.
So when a user go to the list item and view it he can see the image as naturally he is able to see other properties of the item.
I used DataView Web Part SharePoint designer to ease the things but it was not much helping me out as I was able to see that Attachments is 1 or 0 but how to display it I was not getting.
So I followed this

DataviewAttachments

And Modified it in my own ways so that I can associate it with the existing DipForm.aspx page.
So these are the steps which I follow to achieve this:
I use SharePoint Designer 2007, Sharepoint List Web Services Javascript files. You can find the require by going onto Darren’s Blog :
Darren's Blog
So lets go…
1)Open the DispForm.aspx of the List in sharepoint Designer 2007.
It will look like this:


2)Then Select the ListViewwebpart which is already there and click code view.


Now what we will do is in the code view of list view web part we modify the tag’s Value from “true” to “false”.
After that return to Design View.
Note: we have not deleted the webpart there is a reason behind that and it is necessary to make IsIncluded to false.
Than it will look like this

After this go to split view and add another row just below the row where earlier listviewwebpartzone is placed .see this


In that new row’s column put your cursor and after that go to menu bar and click insert >>sharepoint controls>>customlistform like this


Chose your list and select display form. A new form will be get added which will be showing your list data now.
Then just below the last column create another row in the form table and this code….

<div id="att{@ID}" style="padding: 10px;"></div>
<script type="text/javascript">
getAttachments("YourListName",'<xsl:value-of select="@ID"/>'); </script>


And inside the contentplaceholder

<asp:Content ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">


Add this code:

<script src="../../_JS/SPAPI_Core.js"></script>
<script src="../../_JS/SPAPI_Lists.js"></script>
<script src="../../_JS/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
function getAttachments(List,ID){
var lists = new SPAPI_Lists('YourSite');
var items = lists.getAttachmentCollection(List,ID);
if (items.status == 200){
var rows = items.responseXML.getElementsByTagName('Attachment');
var str="";
for (var i=0; i<rows.length; i++){
temp=rows[i].childNodes[0].nodeValue;
ext=temp.substring(temp.lastIndexOf('.')+1);
switch(ext){
case "jpg":
case "png":
case "gif":
bdy='<img src="'+temp+'" alt="'+temp+'" border="0" />';
break;
default:
bdy=temp;
}
str+='<a href="'+temp+'" target="_blank">'+bdy+'</a>'+"<br />";
}
document.getElementById("att"+ID).innerHTML = str;
}else{
alert('There was an error: ' + items.statusText);
}
}
</script>


Don’t forget to change your list name and yoursite name in the above code…
And add the List.asmx files in the _JS like this..



Note : Jquery files are not necessary for this don’t get confuse
After doing this ,save your page….
And when you try to view the item now you will be able to the image like this…



It is the attachment…..You can view 9 attachments with this list with this code…..
Now what is happening behind the scene is we are calling the list data through list web service.

First we are taking all the items having attachments and then passing the ID of the particular item to get the Path of the image and rendering it into innerhtml of the DIV ……
Feel free to ask any queries if have at ankurmadaan2787@live.in