Tuesday 21 February 2012

Select LINQ extension method

collection.Select(item=> new { CityId = item.CityId });

Wednesday 15 February 2012

Powershell in Microsoft SharePoint 2007

Windows Powershell Setup for Windows Server 2003 x64 Edition:

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=16000

Sample Powershell Script:

[System.Reflection.Assembly]::Load('Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c') | Out-Null
$site = new-object Microsoft.SharePoint.SPSite("http://sharepointsite")
$web = $site.OpenWeb()
$web
$web.AnonymousPermMask64 = "ViewListItems, ViewVersions, Open, ViewPages, UseClientIntegration, ViewFormPages"
$web.Dispose()
$site.Dispose()

 

Reference: http://blog.metrostarsystems.com/2011/04/20/leveraging-sharepoint-2007-through-windows-powershell/

Monday 13 February 2012

ASP.NET MVC: Adding active tag for html elements

 public static MvcHtmlString SelectedLink(this HtmlHelper helper, string linkText, string actionName, string controlName, string activeClassName, int id)
{
if (helper.ViewContext.RouteData.Values["action"].ToString() == actionName &&
helper.ViewContext.RouteData.Values["controller"].ToString() == controlName)
return helper.ActionLink(linkText, actionName, controlName, new { Class = activeClassName, Id = id });

return helper.ActionLink(linkText, actionName, controlName);
}
or 
 
        public static MvcHtmlString ActiveMenuItem(this HtmlHelper helper, string linkText, string actionName, string controllerName, int id)
{
TagBuilder li = new TagBuilder("li");

RouteData routedata = helper.ViewContext.RouteData;
string currentAction = routedata.GetRequiredString("action");
string currentController = routedata.GetRequiredString("controller");
int currentId = ConvertionHelper.GetConvertedValue<int>(routedata.GetRequiredString("id"));

if (string.Equals(currentAction, actionName, StringComparison.OrdinalIgnoreCase) &&
string.Equals(currentController, controllerName, StringComparison.OrdinalIgnoreCase) &&
int.Equals(currentId, id))
{
li.AddCssClass("active");
}

li.InnerHtml = helper.ActionLink(linkText, actionName, new { Id = id }).ToHtmlString();

return MvcHtmlString.Create(li.ToString());
}

Thursday 9 February 2012

Areas duplicated: Multiple types were found that match the controller named 'Home'.

Problem:

Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

The request for 'Home' has found the following matching controllers:
Project.Web.Controllers.HomeController
Project.Web.Areas.Dashboard.Controllers.HomeController

Solution:

In Global.asax

    routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "Project.Web.Controllers" }
);