Skip to content

Instantly share code, notes, and snippets.

public class SessionWrapper
{
private static HttpSessionState Session
{
get
{
if (HttpContext.Current == null)
{
throw new ApplicationException("No Http Context, No Session to Get!");
}
@RyanABailey
RyanABailey / DataPager
Created March 20, 2014 04:24
ListView Paging
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="10">
<Fields>
<asp:NumericPagerField ButtonType="Link" />
</Fields>
</asp:DataPager>
@RyanABailey
RyanABailey / List of Objects
Created March 21, 2014 02:53
Entity Framework wrapper to return custom objects using LINQ
public static List<Employee> GetEmployessFromDepartment(int departmentID)
{
var searchResults = new List<Employee>();
using (var entities = new EFEntities())
{
try
{
searchResults = (from a in entities.SelectEmployeeByDepartment(departmentID)
select (new Employee()
@RyanABailey
RyanABailey / PageLoad
Created June 30, 2014 03:55
Force Postback
ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(Button1);
@RyanABailey
RyanABailey / TransactionScope
Created July 1, 2014 00:45
Transaction and EF
try
{
using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.RequiresNew, transOptions))
{
// EF calls here
transaction.Complete();
}
}
catch
{
@RyanABailey
RyanABailey / Control
Created July 23, 2014 12:05
C# ReportViewer
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="100%" Height="100%" SizeToReportContent="True" />
@RyanABailey
RyanABailey / count of objects in object array
Created August 6, 2014 00:37
JavaScript and Jquery Snippets
alert(Object.keys(arrayName).length);
@RyanABailey
RyanABailey / Control
Created August 7, 2014 04:56
angularJs hover example
<div id="menu" ng-mouseover="openMenu()" ng-mouseleave="checkCloseMenu()">
</div>
@RyanABailey
RyanABailey / JS
Last active August 29, 2015 14:05
CSOM Access List
var clientContext = new SP.ClientContext("/");
var web = clientContext.get_web();
var list = web.get_lists().getByTitle("List Name");
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'FieldName\'/><Value Type=\'Text\'>X</Value></Eq></Where></Query></View>');
var items = list.getItems(camlQuery);
clientContext.load(items);
clientContext.executeQueryAsync(functionSuccess(), functionFailure);
@RyanABailey
RyanABailey / PowerShell Script
Created August 14, 2014 00:31
Add field to SharePoint ;ist
Add-PSSnapin Microsoft.SharePoint.PowerShell
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges(
{
$site = SPSite("http://siteurl/")
$web = $site.RootWeb
$spList = $web.Lists["List Name"]
$spFieldType = [Microsoft.SharePoint.SPFieldType]::Boolean
$spList.Fields.Add("Field Name",$spFieldType,$false)
$spList.Update()