SPSite site = new SPSite("http://siteURL");
SPWeb web = site.OpenWeb("mk");
SPList list = web.Lists["TestEventListner"];
string assemblyName = "AddEvent,Version=1.0.0.0,culture=neutral,PublicKeyToken=456722d93042a39b";
string className = "AddEvent.AddUser";
list.EventReceivers.Add(SPEventReceiverType.ItemAdded, assemblyName, className);
list.EventReceivers.Add(SPEventReceiverType.ItemAdding, assemblyName, className);
list.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assemblyName, className);
list.EventReceivers.Add(SPEventReceiverType.ItemUpdating, assemblyName, className);
list.EventReceivers.Add(SPEventReceiverType.ItemDeleted, assemblyName, className);
list.EventReceivers.Add(SPEventReceiverType.ItemUpdating, assemblyName, className);
list.Update(true);
Friday, April 30, 2010
Thursday, April 29, 2010
Datagrid to Excel
DataSet ds= new DataSet();
da.Fill(ds);
//Ger response object for Exporting the data
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oSW = new System.IO.StringWriter();
//Bind the data to datagrid
DataGrid dg = new DataGrid();
dg.DataSource = ds.Tables[0];
dg.DataBind();
//Export to excel
System.Web.UI.HtmlTextWriter oHtmlTW = new System.Web.UI.HtmlTextWriter(oSW);
dg.RenderControl(oHtmlTW);
Response.Write(oSW.ToString());
Response.End();
da.Fill(ds);
//Ger response object for Exporting the data
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oSW = new System.IO.StringWriter();
//Bind the data to datagrid
DataGrid dg = new DataGrid();
dg.DataSource = ds.Tables[0];
dg.DataBind();
//Export to excel
System.Web.UI.HtmlTextWriter oHtmlTW = new System.Web.UI.HtmlTextWriter(oSW);
dg.RenderControl(oHtmlTW);
Response.Write(oSW.ToString());
Response.End();
Friday, April 23, 2010
Join with LINQ
AdventureWorksModel.AdventureWorksEntities _db = new AdventureWorksEntities();
List lSales = _db.SalesPerson.ToList();
List lEmp = _db.Employee.ToList();
var EmpDeptJoin =
from sales in lSales
join emp in lEmp on sales.SalesPersonID equals emp.EmployeeID
select new { SalesPerson = sales.SalesPersonID, Employee = emp.EmployeeID };
List
List
var EmpDeptJoin =
from sales in lSales
join emp in lEmp on sales.SalesPersonID equals emp.EmployeeID
select new { SalesPerson = sales.SalesPersonID, Employee = emp.EmployeeID };
Friday, April 16, 2010
Generating Random Password
public string passGenerate(int len)
{
string _passGenerate = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$&*?";
string _myNewPassword = "";
Random rnd = new Random();
for (int i = 0; i < len; i++)
{
_myNewPassword += _passGenerate.ToCharArray()[rnd.Next(0,69)].ToString();
}
return _myNewPassword;
}
{
string _passGenerate = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$&*?";
string _myNewPassword = "";
Random rnd = new Random();
for (int i = 0; i < len; i++)
{
_myNewPassword += _passGenerate.ToCharArray()[rnd.Next(0,69)].ToString();
}
return _myNewPassword;
}
Wednesday, January 6, 2010
Adding the New Form of list on the View
1.Open the view in the designer.
2.Switch to Designer Mode.
3.Click on Insert.
4.On the Ribbon select the New Form dropdown and select the List.
5.All the Mandatory fields will be available
6.To add ther field switch to the Design Mode and add the two tags for the field
7.Copy the tags generated for the Mandatory field and update the field name and the ID
8.Save the form
Just refresh the page after entering the values.
2.Switch to Designer Mode.
3.Click on Insert.
4.On the Ribbon select the New Form dropdown and select the List.
5.All the Mandatory fields will be available
6.To add ther field switch to the Design Mode and add the two tags for the field
7.Copy the tags generated for the Mandatory field and update the field name and the ID
8.Save the form
Just refresh the page after entering the values.
Change the column name for specific View
While creating the new view in the sharepoint list library select "Custom View in SharePoint Designer". The site will open in the designer. Provide the view name and double click on the new view created in the designer, get into the designer view and update the column Name. We can append the static values after the content also like for the currency we can append $ before the field so that in the view when someone opens it will display the values prefixed with $.
Monday, January 4, 2010
Inline add edit in Sharepoint 2010
Subscribe to:
Posts (Atom)