Tuesday, July 28, 2009

Search ASPX pages from sub site in SharePoint (MOSS 2007)

Search ASPX pages from sub site in SharePoint (MOSS 2007)

In my site collection I have one root site and 2 other sub sites. I have configured Search on site collection and crawl works successfully. Now when I try to search contents from search center results from root site return where content from sub sites are not returned in search result. I amazed and do lot of search on net finally I come to know for each sub site we need to turn on index all .ASPX pages to crawl the content of that ASPX.

Follow the steps to enable sub site ASPX pages in crawl.

Go to sub site > click site settings > in site administrator there is one option called search visibility


Now click on this search visibility option and click on radio button allow this web to appear in search result? To yes


And middle radio button of second option that is "Always index all ASPX pages on this site"

Crawl the content again. It will work for you


Thanks. Your comments and suggestion are appreciable


Saturday, July 18, 2009

Understanding and working with the Web Part Verbs

Hi All,

In this post, we are going to discuss about understanding and working with webpart verbs. First question comes to the mind is what this web part verb actually is. Right, so here is the answer to this.

You have already seen Web part verb if you have worked with web parts. They appear when you press the down arrow button key available in every web part at right hand side corner. Each item in that menu is called verb. Look in to below image.



As you can also see in the image that we have created our own custom web part verb as well and added to the web part.

So let us start with explaining the method how we can achieve this functionality. First you need to know that there are two kinds of event you can bind it to a verb. Either it can be client side event or it can be server side event. As you can see in the image, to show you I have created two verbs and bound events respectively. You need to overrides WebPartVerbCollection. First you need to create your web part verb and then finally we will add them to the default web part verb collections for the web part.

Let us see it in action.

First web part verb will be handling the server side event and the other web part verb will be handling the client side event.

public override WebPartVerbCollection Verbs
{

get
{
List <webpartverb> objVerbs = new List <webpartverb>();

WebPartVerb verb = new WebPartVerb(this.ID, new WebPartEventHandler(ServerSideHandler));
verb.Text = "Click to execute server side code";
verb.Visible = true;
verb.Description = "This click will execute server side code";
objVerbs.Add(verb);

WebPartVerb verb1 = new WebPartVerb(this.ID + "newone","alert('hi you clicked me!!!');");
verb1.Text = "Click to execute client side code";
verb1.Visible = true;
verb1.Description = "This click will execute client side code";
objVerbs.Add(verb1);

WebPartVerbCollection allverbs = new WebPartVerbCollection(base.Verbs,objVerbs);

return allverbs;

}
}


As you can see, client side event, we have declared it in the constructor of webpart verb itself. There you can also write something like window.open or any other client side code that you want.

If we talk about the server side code, then it is handling one webpart event ahndler which is ServerSideHandler. To show you how it works, I have created a textbox in that event and added to the controls collection of web part. So by clicking on that verb, a new textbox will generated and added to the webpart.

public void ServerSideHandler(object sender, WebPartEventArgs e)
{
TextBox txtName = new TextBox();
txtName.TextMode = TextBoxMode.MultiLine;
txtName.ID = "txtname";
txtName.Text = "Hey you clicked server side code and see i got generated here";
this.Controls.Add(txtName);

}


Above are the steps that you need to implement. That will complete your functionality of achieving custom web part verb and adding them to your web part.

See the figure below when I click on client side verb, what happens!!





And see when I clicked on server side web part verb, what happenes!!





So I hope that now you have got the idea about web part verb. So now you can create it and use them according to your requirements.

Thank you.

Friday, July 17, 2009

Understanding SPApplicationPool Class

Hi All,

I came across to an interesting thing yesterday when I was exploring the various classes of SharePoint. I found a class named SPApplicationPool and immediately I got an idea that we should be able to get this class object by calling ApplicationPool property of SPWebApplication object and I was right.

So let me explain you one more interesting part of this class. It exposes several properties like Username, Name, DisplayName, Propoerties as hash table and most surprisingly password. Yes Password property was there, I thought it must be only having set attribute. But I was very much surprised to see it was gettable. Well I thought for a moment.

Below is just a test code that I ran from console application.

private void button1_Click(object sender, EventArgs e)
{

SPWebApplicationCollection objAllWebApps =
SPWebService.ContentService.WebApplications;

SPApplicationPool objPool = null;

string strApplicationPoolUserName = string.Empty;
string strApplicationPoolPassword = string.Empty;
string strApplicationPoolName = string.Empty;
string strApplicationPoolDisplayName = string.Empty;
string strPropertyKey = string.Empty;
string strPropoertyValue = string.Empty;

Hashtable objHash = new Hashtable();

foreach (SPWebApplication objwebapp in objAllWebApps)
{
objPool = objwebapp.ApplicationPool;
strApplicationPoolUserName = objPool.Username;
strApplicationPoolPassword = objPool.Password;
strApplicationPoolName =objPool.Name;
strApplicationPoolDisplayName = objPool.DisplayName;
objHash = objPool.Properties;

foreach (DictionaryEntry objEntry in objHash)
{
strPropertyKey = objEntry.Key.ToString();
strPropoertyValue = objEntry.Value.ToString();
}

}
}


But then I got to know that you must be an Administrator user to even run this code because ultimately it is all about Microsoft.SharePoint.Administration class.

Apart from this I came across certain properties that may be useful in some scenario. So let me discuss certain properties of SPWebApplication class.

AlertsEnabled (Bool)- Whether you can set the alerts or not.

AlertsMaximum (int) –Gets or sets maximum number of alerts a user can create on list or list item

CanSelectForBackup(Bool) – Indicating whether web application can be backed up or not.

CanSelectForRestore(Bool) – Indicating whether web application can be restored or not.

EventHandlersEnabled – Event Handles are enabled on this web application or not

JobDefinitions – returns all job definitions for the web application

There are many other properties for this class, just explore and check them.

Wednesday, July 15, 2009

Designing anonymous application page in SharePoint

Hi All,

Today I am going to discuss on how to design anonymous access application page. This is a common problem that many company developer faces. They always ask that designing such a page is always difficult. You will have site running in windows authentication or in forms authentication. If the entire site is anonymous then it is altogether a different story.

So let us discuss how we can design such application page that can be accessed by the anonymous users as well.

Normally we inherit the application page by LayoutPageBase class, right? Yes, so first thing to note is instead of inheriting from this class, we are required to inherit from class named UnsecuredLayoutsPageBase.

In addition to this, you also need to override one more method which is

protected override bool AllowAnonymousAccess
{
get
{
return true;
}
}


Once you are done with these two settings, you are done with this. Try to achieve this and let me know your feedback.

Thank you

Tuesday, July 14, 2009

Understanding SchedulePicker class and using it as control

Hi All,

Today I am going to discuss about SchedulePicker and how to use it as control in webpart. In my earlier post, I mentioned about creating the custom timer job. This is one step which is similar to that post. This class can be used to allow the user to ask to created job schedule by giving timings and schedule duration by them.

For example, you have created one class which inherits from SPJobDefinition and hence actually implements the execute method for scheduling purpose. So here what we can do is we can give an option to use to select the times and all. After use selects the time and schedule we can assign the selected schedule to the custom job definition.

This is in Microsoft.Sharepoint.WebControls namespace. You can find it under 12 hives control templates. Name of the control is SchedulePicker.ascx.

So you need to register the namespace and then you can use this control in your web part or in any other way you want.

<%@ Register TagPrefix="wssuc" TagName="SchedulePicker" src="~/_controltemplates/SchedulePicker.ascx" %>


And then using the control like this:

<wssuc:SchedulePicker id="myScheduler" Weekly="True" Monthly="True" Enabled="True" EnableStateView="True" runat="server"/>


The above setting will allow you to select between the monthly schedule or weekly scheduling. Other options are also available like Daily, Hourly.

Then declare the control like

private Control ctrlUserControl;

Protected SchedulePicker myScheduler;

string strUserControlPath = "/_controltemplates/{your ascx file}";

this.ctrlUserControl = this.Page.LoadControl(strUserControlPath);

myScheduler = this.ctrlUserControl.FindControl(“myScheduler”) as SchedulePicker;


Finally, Initialize the class which is your definition class and then set the Schedule property with the myScheduler.Schedule.

i.e
{Customjobdefinitionclass}.Schedule = myScheduler.Schedule;


In this way, you have actually made the scheduling timing setting dynamic.

That’s it. Your job is done.

Sunday, July 12, 2009

Working with Recycle Bin in SharePoint

Hi All,

Many times we require working with the Recycle bin of the web site in SharePoint. Here in this article I am going to discuss something interesting classes and their methods and properties for achieving this functionality in SharePoint.

First to start with, when we want to gain an access on recycle bin object at site or individual web level, then call RecycleBin property of SPWeb or SPSite object. This will give you SPRecycleBinItemCollection object.

Each item in SPRecycleBinItemCollection is SPRecycleBinItem. Let me explain you certain properties offered by SPRecycleBinItem object.

(1) Author – Gets the User who created the item.
(2) AuthorEmail - Gets the Email of the user who created this item.
(3) AuthorName – Gets the display name of the User who created this item.
(4) DeletedBy – Gets the User who deleted the item.
(5) DeletedByEMail – Gets the Email of user who deleted the item.
(6) DeletedByName – Gets the name of the use who deleted the item.
(7) DirName – Gets the relative URL of the list or folder which originally captained the item.
(8) ItemType – Gets type of an item deleted, what type of an item it was. It returns the SPRecycleBinItemType and it is enumeration which has following values.

Attachment : Specifies an attachment.
File :Specifies a file.
FileVersion: Specifies a file version.
Folder: Specifies a folder.
FolderWithLists: Specifies a folder that contains a list.
List :Specifies a list.
ListItem: Specifies a list item.

Remember one important thing. When you have child sites under your site collection, then when you delete any item it goes in to your web's recycle bin. When you delete an item from that recycle bin, it goes in to the site collection's recycle bin. so you can also get your deleted item from there.

These were certain properties of the class. Now I would like to highlight certain methods of the class.

(1) Delete: the item permanently from the recycle bin.
(2) MoveToSecondStage – this method moves the item from individual web’s recycle bin to the Site Collection recycle bin.
(3) Restore – As a name suggests, it restores the item to the original location.


Let us look into one more aspects of working with Recycle bin. We normally use SPQuery or SPSiteDataQuery to work with the queries from list and document library. But here to work with the Recycle bin, we will use SPRecycleBinQuery class.

SPRecycleBinQuery objQuery = new SPRecycleBinQuery();
objQuery.RowLimit = 100;
objQuery.OrderBy = SPRecycleBinOrderBy.Default;
SPRecycleBinItemCollection recycleitems = objWeb.GetRecycleBinItems(objQuery);


Now we have got the recycleitems, so you can iterate through them and can access properties and also work with methods.

That’s it.

Thursday, July 9, 2009

Accessing Content Type via object model in WSS

Hi All,

Today we are going to talk about the how we can use content type in object model. We will see classes and how to bind any content types with the list or document library.

We all know about the content type is that it can be treated as reusable component that can be used in list and library or any other way. Content type will always inherit from parent content type.

We can have item based content type attached to the list and document based content type attached with the document library. We cannot attach the vice versa.

First to get all the content type in our site level we will call AvailableContentTypes method which will give us SPContentTypeCollection object. Each individual object in SPContentTypeCollection is SPContentType. One more method we will use which takes the content type ID that we know and will directly give us that SPContentType.

Before that please make a note of a difference between the AvailableContentTypes and ContentTypes property of SPWeb class.

ContentTypes will return all content types only with reference to the current web but AvailableContentTypes will return you all content types of current web as well as all parent webs as well.

Ok, coming back to the point, here is a way we can proceed working with content type through the object model.

SPContentType objContentType = objWeb.AvailableContentTypes[“contenetypeID”];
objList.ContentTypes.Add(objContentType);
objList.Update();


Remember if your conenet type is about fields, then when the content type is added to the list, fields gets added to the field collection but won’t show those fields. So you need to take out the SPView class object and add the ViewFields for those new created fields through the ContentType.

Same, if we want to remove any content type, then follow the below approach.

Foreach(SPContentType objContentType in objList.ContentTypes)
{
If(objContentType.Name.toUpper() == “contenetypeID”)
{
objContentType.Delete();
break;
}
}

Monday, July 6, 2009

Retrieving data from BDC Column

Hi All,

Today we are going to discuss how to retrieve data from BDC Column. We all know that we can create BDC column once we have business application definition file installed in central administration.

If you are not clear about the BDC and about the BDC Columns, I would recommend going to this link and reading the whole series of BDC before you start reading this.

When we use this BDC Column then all fields that we have defined in FileDescriptor tag becomes available as a set in one single BDC Column. So sometimes I think, how to retrieve individual item from the single BDC Column. So here is the answer for this.

Assume that we are working with one list which has one BDC column as Order Column and it contains order information. Example ordername, order date, order qty.

Now then when you insert the list item, it will ask you for search the order based on BDC Order column which you do on Order ID. When you search and insert the record, it will fetch all the columns that you have defined in the BDC FileDescriptor tag.

To see all this in action, you create the BDC definition XML file, import and then use Business Data List web part and then play with it sometime to get to know the search field and retrieved columns.

So we have Order Date, Order Name and Order Qty as retrieved columns, then when you query the ListItems with the help of SPQuery. Let us say that we have queried on ItemId 6 by using GetItemByID method. So we will have SPListItem as objItem.

So how can we get the individual items (Order Date, OrderName and Order Qty) from one single BDC Column (i.e Order)? Here is a way to go for it.

objItem[{name of the BDC Column : {name of the propoerty}}

i.e objItem[“Order: OrderName”] //accessing with the friendly name
objItem[“Order _x003a__x0020_OrderName”] //accessing with the internal name


That’s it. Your job is done.

Sunday, July 5, 2009

Features and Solutions with WSS Object model

Hi All,

Today I am going to discuss about the features and solutions. I know you will ask me what is new in this. Well, this time we are going to talk about features and solutions in terms of object model.

We are going to discuss following things.

(1) Feature install and uninstall
(2) Feature activation and deactivation
(3) Solution install and uninstall
(4) Feature properties

We will discuss all in terms of object model. So let us start one by one. First we will take feature install and uninstall.

Now when we create feature and place it in to 12 hive folder and when we run the -o installfeature command, we actually installs the feature at farm level and when we run –o uninstallfeature command, we actually uninstalls the feature at farm level. Now how this can be done programmatically. So here is a way.

But before starting on this, we also need to learn one more object which is SPFarm class. To initiate SPFarm class, we need to know the configuration database connection path, just like ordinary connection path to connect to the database we use in ADO.NET.

For example, this can be a connection string for my configuration database.

string strConnectionString = @”server=localhost\myServer;initial catalog=SharePoint_Config_75980120-a9bf-4p71-3401-qn26385ca059;IntegratedSecurity=SSPI;”;

SPFarm objFarm = SPFarm.Open(strConnectionString);
SPFeatureDefinitionCollection objinstalledFeatures = objFarm.FeatureDefinitions;
objinstalledFeatures.Add(“{new feature}”, new Guid(“guid of feature “));


This will install the new feature at farm level. Now let’s see how to uninstall the feature from farm level.

objinstalledFeatures.Remove(new Guid(“guid of feature “));

Ok, this was about installing the feature at farm level; now let’s talk about activating feature at site level.

Considering objWeb refers to a site, then

objWeb.Features.Add(new Guid({guid of feature}));


And same to deactivate the feature from site level,

objWeb.Features.Remove(new Guid({guid of feature}));


Now let us understand what we mean by feature properties. Each feature has set of properties that you can set along with it and also built in properties that you can enumerate and check. We will insert properties in the feature.

This is how you enumerate to the properties of the feature.

foreach (SPFeatureProperty objProperty in objFeature.Properties)
{
String strPropName = objProperty.Name;
String strPropValue = objProperty.Value;
}


Now let us see how we can add and remove the properties from feature.

SPFeatureProperty objProp = new SPFeatureProperty(“{your prop name}”, “{prop value}”);
objFeature.Properties.Add(objProp);


SPFeatureProperty objProp = objFeature.Properties[0];
objFeature.Properties.Remove(objProp);


Interesting thing to note is that you do not need to call any update method on any of the objects to achieve this behavior.

Now let us take solution in to picture. By solution we mean collectively we can install features at farm level (on every server in the farm) and deploy features to those servers.

We know that every operation that I have mentioned in this article can be achieved through STSADM command, so this operation can also be performed by –o addsolution and –o deletesolution command. But here we are talking about object model, so I will show you the way to do it programmatically.

Consider the objFarm object just like mentioned above and then if you access the Solutions property, it will give you all solutions deployed at farm level.

It can be done simple as add and remove method.

objFarm.Solutions.Add({customapp.cab});
objFarm.Solutions.Remove(new Guid({guid of solution})); // Pass Guid of solution


You can enumerate through all solutions in Farm, like mentioned below.

foreach (SPSolution objSolution in objFarm.Solutions)
{
//your custom code
}


Each objSolution has different properties like Deployed, DeployedServers, Id, Name etc.

Again each DeplyoedServer represents SPServer class and has properties like Name. So in a nutshell, you can make use of these classes and play with it.

At the end I would like to summarize with what we discussed in the article with classes.

SPFeature – Represents individual feature
SPFeatureCollection – Represents collection of features at site level
SPFeatureDefinition – Represents Feature definition.
SPFeatureDefinitionCollection – Represents all feature definitions of farm
SPFeatureProperty – Individual property of feature
SPFeaturePropertyCollection – All properties of single feature
SPFarm – represents Farm
SPSolution – Represents solution file.
SPServer – Represents each server on which solution is deployed in Farm.

Thank you.

Wednesday, July 1, 2009

SharePoint 2010 is coming

Hi All,

Here I am with something very interesting and new things coming up in the market soon. Yes we are going to talk about next version of SharePoint server and also other technologies that will help out new version of SharePoint. New version of SharePoint is called SharePoint server 2010 instead of moss 2010. They have removed the name Office as now they want office to be used for office suit only. So now onwards we will call it as SharePoint Server 2010.

• If you know about Microsoft Groove then this news is for you. Groove will be known as SharePoint Workspace Manager. SharePoint Workspace Manager and OneNote will be a part of the Office 2010 ProPlus SKU.

• SharePoint Server 2010 will support only 64 - bit. It will require 64 bit Windows Server 2008 or 64 bit Windows Server 2008 R2. In addition to this, it will require 64 bit version of SQL Server 2008 or 64-bit version of SQL Server 2005. No more 32 bits.

• Forget IE 6. SharePoint Server will not support any IE browser < 7. It will require browser to be IE 7or higher. Now they are targeting only XHTML 1.0 compliant like IE 7, IE 8, and Firefox 3.x. In addition to this they are also planning to increase the level of compatibility with Firefox 3.x and Safari 3.x on non windows platforms.

• Now turn of Web Enabled Ribbon control. We all know about the ribbon controls in Office 2007. Now they will also be there for web version.

• New concept of Faceted Search is coming. Yet to hear more on this as of now. It might be included as OOTB in SharePoint 2010.

• FAST Search is coming. A new version of FAST Search for SharePoint. They will stop scaling search for documents more than 50 millions. For this purpose they will now use FAST Search.

• Support on mapping list to its own database tables offering better performance and scalability on large SharePoint list.

• Visual Studio 2010 will include support of developing web parts, feature, solutions and content types.

• We will be able to build, deploy and debug the applications right from Visual Studio 2010. Just Hit F5 and deploy and start debugging. Now this is a big relief.

• New Server explorer in Visual Studio that will allow us to navigate to lists, document libraries from site.

So be prepared to learn new version of SharePoint soon but I guess lot to explore more but yes at lot more expense. Tell you what, lot more money requires now to get all this. :) (Obviously Windows Server 2008 64 bit, SQL Server 2008 64 bit and Visual Studio 2010 – along with this, hardware supports. You can count the money now :))

I would like to thank Lar's blog , MSDN SharePoint Team Blog and Mary-Jo Foley for sharing this information.

Till now everybody has idea about the requirements and similar stuff. What actually will be the additions as development and other OOTB features is still a question for us. We all are waiting to get this information. As soon as we will find anything, I will be definitely keen to post it.



Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com