Tuesday, March 29, 2011

SPWeb Vs SPSite Vs SPWebApplication

If you are a beginner to SharePoint its vital to get an clear knowledge and should have a clear idea to distinguish SPWeb and SPSite and SPWebapplication. If you have a SharePoint environment setup in your machine try writing the following simple console application. This will go beyond the definitions and will be ease to understand and clarify these three buzz words.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;

namespace MyFirstTest
{
class Program
{
static void Main(string[] args)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWebApplicationCollection webappcol = SPWebService.ContentService.WebApplications;
foreach (SPWebApplication webapp in webappcol)
{
Console.WriteLine("Web Application URL :" + webapp.Name);

foreach (SPSite site in webapp.Sites)
{
Console.WriteLine("Site Collection URL :" + site.Url);
Console.ReadKey();

foreach (SPWeb web in site.AllWebs)
{
Console.WriteLine("Site URL :" + web.Url);
Console.ReadKey();
}
}
}

});
}
}
}

OutPut:

Web Application URL : Sharepoint-80

Site Collection URL : http://cd-Home

Site URL : http://cd-Home
http://cd-Home/Test
http://cd-Home/Test/Inside

Note:Since I am getting the "site.AllWebs" property it will iterate through all the webs in the Site Collection

Try in your environment you can understand the difference.....

Monday, March 7, 2011

Error occurred in deployment step 'Activate Features': Invalid field name.

Error occurred in deployment step 'Activate Features': Invalid field name. {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}

The above error may be a common problem on the deployment step, where the project contains site columns and content type/lists. The content type or list will be referencing the site column.

Cause :
There are three reasons for the above behavior.
1. If you have already deployed the solution and you get the error on later attempt, then the declarative mark-up of Field definition/List Schema could be modified from the version you already deployed to the site. Because the content db is queried for a non-existent object, where at that point it throws an error.

2. Referencing site column(field) from content type/lists cannot be resolved by the  deploying thread. Your feature will be structured as below. The referee column located in the “Elements” Module is referred from “Test ContentType” Module. On deployment the feature is activated in the following order.

3. The template/structure of the schema/field file is wrong.

Solution :
1.For the former case, make sure that you retract the package with the same version of above files and then modify the changes in fields/schema to get the newer version effect.

2. For the latter case, the site column(field) should be already deployed in the site before it’s being used by any other module(Test ContentType). In order to do that you don’t need to go for another feature, but simply you can change the order in the feature. In this case, the deployable feature takes the following form.

3. For the third case, rectify the issue in the schema/fields file.

Thursday, February 3, 2011

Coping DLL from the Global Assembly Cache

You Can Easily copy any .dll which is installed in GAC using windows. If you browse to assembly folder placed in c:\windows you will have only the option to uninstall. Rather you browse to GAC_MSIL folder under c:\windows\assembly you can see the installed assembly folders. Each folder has a subfolder under it. In sub folder you can find the DLL what you need. There is no need of using the shfusion.dll to copy the DLL’s.

Steps are as follows:

1.       Browse to c:\windows\assembly\ GAC_MSIL
2.       Each assemblies has a folder, with each version being a subfolder under that.
3.       In the subfolder is the DLL that you can copy to a different folder of you choosing.


Wednesday, February 2, 2011

Control Anonymous User from Accessing Application Pages

I came across a requirement where the SharePoint site should be enabled for the anonymous users in the meantime, they should be restricted to view from the application pages. So first my choice was ViewLockDownFeature, shipped with SharePoint 2007 STSADM. I thought I saved the time by just enabling the feature would solve me the problem. Yes it solved me the problem but it spawned me another problem where the feature blocks the anonymous users navigate to the blog entries, since the blog entries are accessing the Lists directly and get the page contents.

Sample Url of blog

../myblog/Lists/Categories/Category.aspx?CategoryId=2&Name=Category 2

Workaround 1:

Setting the policy at web.config level.

<configuration>

<location path="_layouts/viewlsts.aspx ">

<system.web>

<authorization>

<deny users="*"/>

</authorization>

</system.web>

</location>

</configuration>

For further information follow up here.

The problem in the above method is, if you want to block all the application pages and still wants the blog accessible to anonymous users, then you have to specify all the application page url.

Workaround 2:

Tweaking with Delegate control

SharePoint is a pool to play with delegate controls, where the winner is supposed to get a chunk of development time compared to other optional method.

Normally SharePoint delegate controls resides in Master page and Page layout as well as in Application Pages. First I delve into the delegate controls for the custom navigation control. This is the second time, where I observed that all the application pages are having the delegate control. So overriding the delegate control in the following manner will help you to implement your own policy to ranging from different user groups to different site, page and to url level.

public class AnonyousePolicy:UnsecuredLayoutsPageBase

{

protected override void OnLoad(EventArgs e)

{

if (System.Web.HttpContext.Current.Request.Url.PathAndQuery.IndexOf("_layouts/RedirectionModule/") > 0)

{

//Do Nothing as Anonymous users need to get that redirection available

}

else if (System.Web.HttpContext.Current.Request.Url.PathAndQuery.IndexOf("_layouts/", StringComparison.InvariantCultureIgnoreCase) > 0)

{

if (SPContext.Current.Web.CurrentUser == null)

{

// Anonymous user, prevent access

SPUtility.TransferToErrorPage("Anonymous users have no access to this page");

}

}

}

}

Conclusion : I feel the first method is a simple way to block the anonymous users, provided the accessibility is not restricted upon the user group and less number of application pages.

Second method is handy method is more flexible than the first method I hope !

Expect your feedback.

Sunday, December 12, 2010

WCF/ADO.NET Data Services - Could not load type 'System.Data.Services.Providers.IDataServiceUpdateProvider'

For the SharePoint 2010 users, you might wonder the announcement of Microsoft for the support of RESTFul services is giving error when you try to access the /_vti_bin/listdata.svc.

Error : Could not load type 'System.Data.Services.Providers.IDataServiceUpdateProvider' from assembly 'System.Data.Services, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Work-around :
For Windows Vista and Windows 2008 - http://www.microsoft.com/downloads/details.aspx?familyid=4B710B89-8576-46CF-A4BF-331A9306D555&displaylang=en

For Windows 7 and Windows 2008 R2 - http://www.microsoft.com/downloads/details.aspx?familyid=79d7f6f8-d6e9-4b8c-8640-17f89452148e&displaylang=en

P.S : Don't forget to reset the iis. Otherwise you will get the error recurrently.

Tuesday, November 30, 2010

SP2010 URL Field Type Enhancement

I've observed a nice feature offered by Microsoft SharePoint team when I was trying to migrate the contents from one server to another. In Sharepoint 2007, you will not get an automatic conversion of existing URL when you are migrating list items among the servers (Header of URL). But in SharePoint 2010 it does.

Observation:

Server 1
I've pointed some of the assets by giving the absolute URL path
I want all those list items to be migrated to another server called Server 2

I've used SPContent Deployment Wizard to do the job.
Amazingly all the URL headers of the absolute path is converted in adherence to Server 2

You may ask whether the above tool does the job for you.
The answer is NO. Because I've checked the latest release note of that tool to see whether it supports that kind of fancy conversion.

My next step is to dig on the same stuff to see whether it accepts relevant URL header when I migrate the list items from one server to another server's sub-sitecollection

I'll come up with the latest note on that.

Stay tuned...

Monday, November 22, 2010

MCTS Sharepoint Developer Certification (70-573)


Recently I have sit for the Sharepoint Developer Examination, which is anticipated unlike Administration Examination, a tough exam by my colleagues, though none of them have not tried at least once :) . Everyone pushed me towards the dead-end for the trial, and I also well prepared on the core API of Sharepoint. Since I have been actively working on Sharepoint for last one year, most of the API is covered through out my tasks, which enabled me to go for a dry run on the new features introduced in Sharepoint 2010 API such as SPListCollection.TryGetList etc.

These are the steps I've focused once I've decided to embark on the Sharepoint bed.
First, I've done some POCs based on the weight of skills to be tested.
Microsoft Preparation Guide

Lets say, TimerJob implementation is included in the preparation list, I've written a simple TimerJob and deployed as Farm Administrator and note down if any issues encountered.
But at the exam, required us to be familiar with the sandboxed solution deployment as well, where as we deploy everything as Farm Administrator. So for the audience, I'm encouraging all you to go through the dual deployment steps and get hold of the stuffs as its a new feature introduced in SharePoint 2010; I meant the SandBoxed solution.

Atlast, outline given by Microsoft is analysed detailed and provided reference on the following blog, which was a worth guide for me.
Guide with References

If any specific clarification neede on the exams, just post me your questions.