jueves, 14 de febrero de 2013

Extend class String with Trim function in javascript

String.prototype.trim = function () {
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
}

Authentication SharePoint 2010 based in Forms


using Microsoft.SharePoint;
using Microsoft.SharePoint.IdentityModel;

public class AuthenticationSharePoint : Authentication
{
    public bool IsValid( string url, Usuario usuario)
    {
        return SPClaimsUtility.AuthenticateFormsUser(new Uri(url), usuario.Login, usuario.Contrasenia);
    }
}

Clone Generic Object by Reflection in .NET


public static List GetAllProperties(Type type)
{
    BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
    var list = new List();

    if (type != null)
    {
        list.AddRange(type.GetProperties(flags));
        list.AddRange(GetAllProperties(type.BaseType));
    }

    return list;
}

public static T Clonar(T original)
{
    if (original == null) { throw new Exception("cannot be null object"); }

    var tipo = original.GetType();
    var resultado = Activator.CreateInstance(tipo);
    foreach (PropertyInfo propiedad in GetAllProperties(tipo))
    {
        propiedad.SetValue(resultado, propiedad.GetValue(original, null), null);
    }
    return (T)resultado;
}

ProgressBar in javasccript

 

 Progress Bar



    

domingo, 10 de febrero de 2013

Load CSS file Dynamically

function loadCSSFileDymanically(dir){
var link = document.createElement(“link”);
link.rel = "stylesheet";
link.type = "text/css";
link.href = dir;
var head = document.getElementsByTagName(“head”)[0];
head.appendChild(link);
}

Load JavaScript file Dynamically

function loadScriptDinamically(dir){
var script = document.createElement(“script”);
script.type = “text/javascript”;
script.src = dir;
document.body.appendChild(script);
}