Archive

Archive for August, 2011

Copy value from column to another using JQuery

August 19, 2011 1 comment

Copy the value from one column to another column on a New List Item Form.

In this example, I am populating the End Date Field with the Start Date Field value when user is filling out a meeting request form in SharePoint.

Add the following code on the page under “PlaceHolderMain” tag.

<script type="text/javascript" src="../../Shared Documents/Javascript/jquery/jquery.js">

$(document).ready(function(){
var strStartDate = $("input[title='Start Date']");
strStartDate.focusout(function()
 {
$("input[title='End Date']").val(strStartDate.val());
});
});
</script>

How to create Views Programmatically in SharePoint 2010

August 17, 2011 2 comments

Below is the code snippet to create views programmatically

Create a View

      private void CreateView(string strViewName)
{
try
{
string fieldName = //Get Field Internal Name
var docquery = "<Where><Eq><FieldRef Name='" + fieldName.ToString() + "' /><Value Type='Choice'>" + strViewName.ToString() + "</Value></Eq></Where>";
System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
viewFields.Add("Type");
viewFields.Add("Name");
viewFields.Add("Modified");
viewFields.Add("Modified By");
viewFields.Add(fieldName.ToString());
oViewCollection.Add(strViewName, viewFields, docquery, 100, true, false);
web.Update();
}
catch (Exception e)
{
throw new SPException(e.Message.ToString());
}
}

You can use U2U Query Builder tool to build CAML query (http://www.u2u.net/res/Tools/CamlQueryBuilder.aspx)