Monday, September 24, 2012

Javascript: Freeze/Lock Web Page While Loading

I would like my web page could be freeze/locked when processing, and users are unable to click any button. Here is a excellent JavaScript library - Impromptu .
 
 var v;
 
 function trigger()
 {
  var txt = 'Processing';
  v = $.prompt(txt, {
   opacity: 0.8
  });
  execute();
 }
 
 function execute()
 {
  //execute your code
  $.prompt.close();
 }
It works perfect on Chrome and IE.

Wednesday, September 5, 2012

CRUD in SharePoint Client Object Model

I want to create/read/update/delete list item via SharePoint Client Object Model using Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime.

Create
using (ClientContext context = new ClientContext(url))
{
    //set credentials
    ICredentials cache = new NetworkCredential(userName, password);
    context.Credentials = cache;

    List barcodeReaderList = context.Web.Lists.GetByTitle(listName);
    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                
    ListItem item = barcodeReaderList.AddItem(itemCreateInfo);
    item["Title"] = barcode;
    item.Update();

    context.ExecuteQuery();
}

Update
using (ClientContext context = new ClientContext(url))
{
    //set credentials
    ICredentials cache = new NetworkCredential(userName, password, domain);
    context.Credentials = cache;

    List list = context.web.Lists.GetByTitle(listName);
    ListItem item = list.GetItemById(id);
    item["Title"] = title;

    item.Update();
    context.ExecuteQuery();
}
Delete
using (ClientContext context = new ClientContext(url))
{
    List list = context.Web.Lists.GetByTitle(listName);

    ListItem item = list.GetItemById(id);
    item.DeleteObject();

    context.ExecuteQuery();
}

Read
private IEnumerable newLists;

var dt = new DateTime(2010, 3, 20);
var query = from list
            in clientContext.Web.Lists
            where list.Created > dt && list.Hidden == false
            select list;

newLists = clientContext.LoadQuery(query);
clientContext.ExecuteQueryAsync(onPartQuerySucceeded, onPartQueryFailed);

Verify Local Windows Account Password

I would like to verify local windows account and password through a web part in SharePoint 2010. The code snippet is show below:

protected bool verifyUserAccount(string computerName, string userName, string password)
{
    bool flag = false;
    using (PrincipalContext context = new PrincipalContext(ContextType.Machine, computerName, userName, password))
    {
        flag = context.ValidateCredentials(userName, password);
    }
    return flag;
}

Then the above snippet can really verify local windows account and password!