Tuesday, October 30, 2012

Blank option in ASP.NET DropDownList

I would like to create an blank option in DropDownList by default and don't use append to add options into the list. So, I bind the datasource first and then insert the blank option afterwards.

.aspx.cs
DropDownTenderNumber.DataSource = list;
DropDownTenderNumber.DataBind();
DropDownTenderNumber.Items.Insert(0, new ListItem("----PLEASE SELECT----", "0"));

Further, I use 'InitialValue' in RequiredFieldValidator to exclude the blank option.

.aspx

Freeze/Lock Web Page While Processing in ASP.Net

I would like to create a layer to cover a page while it is processing. First, downloading a loading icon from ajaxload. Then, you just need to paste following code in .aspx file.

UpdateProgress

    
        
Loading
UpdatePanel

    
        
    
    
        
    

Script Manager


CSS
.overlay  
{
    position: fixed;
    z-index: 98;
    top: 0px;
    left: 0px;
    right: 0px;
    bottom: 0px;
    background-color: #aaa; 
    filter: alpha(opacity=80); 
    opacity: 0.8; 
}
.overlayContent
{
    z-index: 99;
    margin: 250px auto;
    width: 80px;
    height: 80px;
}
.overlayContent h2
{
    font-size: 18px;
    font-weight: bold;
    color: #000;
}
.overlayContent img
{
    width: 60px;
    height: 60px;
}
Use UpdateProgress To Cover Screen

I have tried to browse it use chrome, firefox and ie and it works fine.

globalization Element in web.config

I would like to provide a textbox to user and let them filter data by a given date in (dd/MM/yyyy) format.



query = query.Where(i => i.OperationDate <= end);

Unfortunately, query results seems not working properly. It seems that SQL Server uses date format (MM/dd/yyyy) to do the searching. Then, the question is how to specify the date format in my web application. By adding following line in web.config, the issue is solved.


CultureInfo Class:
Represents information about a specific culture including the names of the culture,the writing system, and the calendar used, as well as access to culture-specific objects that provide information for common operations, such as formatting dates and sorting strings.

Thursday, October 4, 2012

SSIS: DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER

I create an SSIS project using SQL Server Business Intelligence Development Studio under Windows Server 2008 R2. When I run the project, something is wrong and an error message is shown below:

"[OLE DB Source [1]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER."

I don't get any idea from above message. After I disable the Run64BitRunTime option, everything work fine.


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!