Monday, October 13, 2008

MCTS 70-542

I passed the MCTS exam for SharePoint 2007 - Application Development today :)

Wednesday, July 9, 2008

Using Ajax Technology & RadControls with MOSS 2007 Site

In this post we will take about how to Enable Ajax and Use RadControls in your sharepoint site.

*) Enable Ajax in your Sharepoint Site :

Two ways to do it.

First way:

This way will enable Ajax 3.5 in your sharepoint site using VS 2008.
  • Open Vistual Studio 2008.
  • Go to File --> Open --> Web Site
  • Browes to your MOSS 2007 site location, for example :

C:\inetpub\wwwroot\wss\VirtualDirectories\90
supposing your site's port number is 90.

  • Upgrade message will appear asking you for updating your site from .Net Framework 2.0 to .Net Framework 3.5.

  • Click Yes to Upgrade your site to .Net Framework 3.5
  • Open web.config file and you will see the changes that you need for enableing Ajax into your site automatically there .

Second way :

In this way we will follow the normal way to enabel Ajax in any ASP.NET application.(manually).

Note : if you choose to install AJAX 3.5 , you have to replace the assembly version from Version=1.0.61025.0 to Version=3.5.0.0

*) Using RadControls in MOSS 2007 Site.

To use RadControls in MOSS 2007 site , follow the following steps.

  • Open your MOSS 2007 Site with VS 2005 , 2008.

C:\inetpub\wwwroot\wss\VirtualDirectories\90

supposing your site's port number is 90.

  • Add RadControls to your ToolBox using Telerik.Web.UI.dll file.
  • Create new ASPX page inside a folder for example MyPage folder.
  • Test RadControls by Drag and Drop a Script Manager OR RadScriptManager and RadAjaxManager OR RadUpdatePanel to your page and any other RadControls.

Note : Till this moment, if you test your page from the browser, you will get a security exception becos RadControls should run under a Full Trust.

  • deploy Telerik.Web.UI.dll assembly into the GAC and everything will work fine

enjoy :)

Thanks,

Mohammed Barakat Kharboush

401 unauthorized error when accessing "MySite" in MOSS 2007

Problem :

I installed MOSS 2007 and after creating my first web application and the SSP (Shared Service Provider), When I try to access "MySite" I was receiving a credential prompt, although I entered the correct username & password three times I was getting the a 401 unauthorized error.

Solution :

From the Central Admin, I deleted the site collection that host mysite and then I create it again using My Site Host template which can be found under the Enterprise tab in creating new site collection page and everything works fine.

Thanks,
Mohammed Barakat Kharboush

Monday, June 30, 2008

MOSS 2007 : Access Denied exception even when using SPSecurity.RunWithElevatedPrivileges Method

Problem :

if you implement my previous post which is MOSS 2007 : Implement Task - Task Activities (Parent-Child Relationship) on the same List and after attach the mentioned list event handler on ItemAdded, you will get an "Access Denied Exception" if the current loged in user is not one of the MOSS site's owners (if he is not included in the site's owners group) even if you use SPSecurity.RunWithElevatedPrivileges WSS 3.0 API Method. let me show you the code.

//////////////////////////////////////////////////////////////////////////

public override void ItemAdded(SPItemEventProperties properties)
{
using (SPWeb web = properties.OpenWeb())//Open the web you want to use
{
SPContentType TaskCT = web.ContentTypes["TaskCT"];

if (TaskCT != null)
{
// Check if the Added Item Belongs to Task Content T ype
if (properties.ListItem.ContentType.Name == TaskCT .Name)
{
SPList TaskList = web.Lists[properties.ListId];

// Get folder in the list and a content type.
SPFolder TaskFolder = TaskList .RootFolder.SubFolders[properties.AfterProperties["Title"].ToString()];
SPContentType TaskActivityCT = TaskList .ContentTypes["TaskActivityCT"];
List contentTypes = new List();
contentTypes.Add(TaskActivityCT);

// Set the content type order for the Task Folder and update
TaskFolder.UniqueContentTypeOrder = contentTypes;
TaskFolder.Update(); // The Exception Will Occur Here (Access Denied)
}
}
}
}

//////////////////////////////////////////////////////////////////////////


The above code will generate an exception TaskFolder.Update(); line which marked with red color. why?

Becos as we said, the loged in user is not a member of the site's owner group.

What we can do?? do I have to use SPSecurity.RunWithElevatedPrivileges Method that will Execute my method with Full Control rights even if the user does not have?

Solution:

if you use SPSecurity.RunWithElevatedPrivileges method with the above code, the exception will still raising again and again when your code executed by a normal user (not site owner) ! that will make me lose my mind!!! why ?

lets try it

//////////////////////////////////////////////////////////////////////////

public override void ItemAdded(SPItemEventProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{

using (SPWeb web = properties.OpenWeb())//Open the web you want to use
{
SPContentType TaskCT = web.ContentTypes["TaskCT"];

if (TaskCT != null)
{
// Check if the Added Item Belongs to Task Content T ype
if (properties.ListItem.ContentType.Name == TaskCT .Name)
{
SPList TaskList = web.Lists[properties.ListId];

// Get folder in the list and a content type.
SPFolder TaskFolder = TaskList .RootFolder.SubFolders[properties.AfterProperties["Title"].ToString()];
SPContentType TaskActivityCT = TaskList .ContentTypes["TaskActivityCT"];
List contentTypes = new List();
contentTypes.Add(TaskActivityCT);

// Set the content type order for the Task Folder and update
TaskFolder.UniqueContentTypeOrder = contentTypes;
TaskFolder.Update(); // The Exception Will Occur Here (Access Denied)
}
}
}

});
}

//////////////////////////////////////////////////////////////////////////
we will take now about the reason, why we still get that exception even after using SPSecurity.RunWithElevatedPrivileges method.

from the above code we are using properties.OpenWeb() Method which returns SPWeb object that refer to the current web which our code execute in, but that object was created in a context of a non-administrative user. lets solve it now :


//////////////////////////////////////////////////////////////////////////

public override void ItemAdded(SPItemEventProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{

SPWeb webInContext = properties.OpenWeb();
SPSite siteInContext = webInContext.Site;
Guid _webGuid = webInContext.ID;
Guid _siteGuid = siteInContext.ID;

using (SPSite site = new SPSite(_siteGuid))
{
using (SPWeb web = site.OpenWeb(_webGuid ) )//Open the web you want to use
{
SPContentType TaskCT = web.ContentTypes["TaskCT"];

if (TaskCT != null)
{
// Check if the Added Item Belongs to Task Content T ype
if (properties.ListItem.ContentType.Name == TaskCT .Name)
{
SPList TaskList = web.Lists[properties.ListId];

// Get folder in the list and a content type.
SPFolder TaskFolder = TaskList .RootFolder.SubFolders[properties.AfterProperties["Title"].ToString()];
SPContentType TaskActivityCT = TaskList .ContentTypes["TaskActivityCT"];
List contentTypes = new List();
contentTypes.Add(TaskActivityCT);

// Set the content type order for the Task Folder and update
TaskFolder.UniqueContentTypeOrder = contentTypes;
TaskFolder.Update(); // The Exception was gone :)
}
}
}

}
});
}

//////////////////////////////////////////////////////////////////////////

in this way, the SPWeb is created in a context of an administrative user( site.OpenWeb(_webGuid ) )

enjoy :) and don't forget to include a reference to System.Configuration namspace to have the Guid available.

Thanks,
Mohammed Barakat Kharboush

MOSS 2007 : Connect to Outlook list's option not working

Problem :
The problem is when creating a custom task list with a custom content type you will find the synchronization option between your MOSS list and outlook 2007 not working by using the option "Connect to Outlook".

Solution:
Your list should be created from MOSS Tasks List (Original List thats available under Tracking after hitting the create option from site action), The Type ID for that list is 107 and it should have the content type named as (Task).

Thanks,
Mohammed Barakat Kharboush

Saturday, June 21, 2008

MOSS 2007 VariationsLabelMenu.ascx Invisible!

After Set and configure variations for your site collection , then you need to configure variation labels by adding a label for each language you want your site to have.



After successfully doing that, you may need to make the visitor of your site able to select between those different languages. for example having a list of available languages on your site's master page.

Shareponit 2007 has an out-of-the-box usercontrol that can automatically shows the available languages to your site's visitors, see the below image.



By Defualt your site's master page will have that control , but you have to do additional step to have it visible to your site's visitors by

1) Going to the path where the VariationsLabelMenu.ascx resides.
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES

supposedly you installed MOSS 2007 on your C: drive.

2) Open the VariationsLabelMenu.ascx using VS.

3)You will find that cms:VariationsLabelEcbMenu is outcommented with comments. Remove these comments and the control will works fine :)



Thanks,
Mohammed Barakat Kharboush