Monday, January 31, 2011

Using People Picker control in SharePoint programmatically

Namespace:

using Microsoft.SharePoint.WebControls;

Creating the control:

PeopleEditor editor = new PeopleEditor();
editor.AllowTypeIn = true;
editor.AutoPostBack = false;
editor.AllowEmpty = true;
editor.MultiSelect = false;
editor.ValidatorEnabled = true;
editor.EnableViewState = true;
PeoplePickerHolder.Controls.Add(editor);

Get the comma separated selected users:

string users = editor.CommaSeparatedAccounts;

Pass input to Dialog window and return back to the Parent window using JavaScript

Scenario - As a developer, we often get requirement to open an Dialog or Add-On on click of a button to search some item and return back to the parent screen.

Ex: Search and assign a doctor to a patient using doctor appointment screen. Search doctor screen should open as a diglog box and return the selected doctor back to the Appointment screen.

Solution:
Appointment Screen


Doctor Search Screen

Sunday, January 30, 2011

JQuery Plug-ins Details


Plug-in NameDocumentationSample
Overlayhttp://flowplayer.org/tools/overlay/index.html
Download –
http://flowplayer.org/tools/download/index.html
 
Tabshttp://flowplayer.org/tools/demos/tabs/index.html 
Scrollablehttp://flowplayer.org/tools/demos/scrollable/index.html 
Tooltiphttp://flowplayer.org/tools/tooltip/index.html 
tablesorterhttp://tablesorter.com/docs/index.html 
Jquery Form Pluginhttp://malsup.com/jquery/form/ 

Finding the Current View in ASP.NET MVC


public static string GetCurrentView(this HtmlHelper helper)
{
string controller = helper.ViewContext.RouteData.GetRequiredString("controller");
string view = helper.ViewContext.RouteData.GetRequiredString("action");

return controller + "_" + view;

}

Ex : string currentView = Html.GetCurrentView();

How to get client's IP Address in Load Balanced Environment


public static string GetIPAddress(NameValueCollection serverVariables)
{
var ip = serverVariables["HTTP_X_FORWARDED_FOR"];

if (!string.IsNullOrEmpty(ip))
{
string[] ipRange = ip.Split(',');

if (null != ipRange && ipRange.Length > 0)
{
int le = ipRange.Length - 1;
string trueIP = ipRange[le];
ip = trueIP;
}
else
{
ip = serverVariables["REMOTE_ADDR"];
}
}
else
{
ip = serverVariables["REMOTE_ADDR"];
}

return ip;

}

Ex: string userIPAddress = GetIPAddress(Request.ServerVariables);

Design an Attribute that forces an unsecured HTTP request to be sent over HTTPS in ASP.NET MVC


[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class SampleRequireSSL : RequireHttpsAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
if (Sample.Web.Areas.Admin.Helpers.ConfigSettings.RequireSSL)
{
base.OnAuthorization(filterContext);
}
}
}

How to get render HTML from a View by passing Model as parameter in ASP.NET MVC



protected string RenderViewToString(string viewPath, T model)
{
using (var writer = new StringWriter())
{
var view = new WebFormView(viewPath);
var vdd = new ViewDataDictionary(model);
var viewCxt = new ViewContext(ControllerContext, view, vdd, new TempDataDictionary(), writer);
viewCxt.View.Render(viewCxt, writer);
return writer.ToString();
}
}

Ex : EmployeeViewModel model = GetEmployeeModel(21);
string htmlString = RenderViewToString("~/Views/EmployeeView.ascx", model);