Open the webpart page in the Sharepoint Designer and remove the following tags
<asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server"></asp:Content>
<&asp:Content ContentPlaceHolderId="PlaceHolderNavSpacer" runat="server"></asp:Content>
And save the file back, on the warning for customization press Yes
Wednesday, May 19, 2010
Wednesday, May 5, 2010
Serialization & De-serialization

Serialization & De-serialization The process of converting a data structure or object into a sequence of bits so that it can be stored in a file, a memory buffer, or transmitted across a network. The Process of serialization is also called Marshalling
To re-construct the object from the previously serialized instance of the same in the persistent or non-persistent storage media.The Process or de-serialization is called UnMarshalling
To make a class Serializable in C# tou need to add the attribute before the class definition
Eg.
[Serializable]
public class Employee
{
public int EmployeeId;
public string FirstName;
public string LastName;
public string Designation;
public int Salary;
}
Types of Serialization
Binary Serialization
Binary serialization is a mechanism which writes the data to the output stream such that it can be used to re-construct the object automatically. Exact binary copy of the object is saved onto the storage media.
fileStreamObject = new FileStream(filename, FileMode.Create();
BinaryFormatter binaryFormatter = new BinaryFormatter();
return (binaryFormatter.Serialize(fileStreamObject));
Advantages of using Binary Serialization in the
The object can be de-serialized from the same data you serialized it to.
Fast
Disadvantage
Portability is not simple
SOAP Serialization
The SOAP protocol is ideal for communicating between applications that use heterogeneous architectures. The SoapFormatter serializes objects into SOAP messages or parses SOAP messages and extracts serialized objects from the message.
FileStream fileStreamObject = new FileStream(filename, FileMode.Create);
SoapFormatter soapFormatter = new SoapFormatter();
soapFormatter.Serialize(fileStreamObject, employeeObject);
fileStreamObject.Close();
The basic advantage of SOAP serialization is portability
XML Serialization
XML serialization converts (serializes) the public fields and properties of an object or the parameters and returns values of methods, into an XML stream that conforms to a specific XML Schema definition language (XSD) document
serializer = new XmlSerializer(typeof(Employee));
stream = new FileStream(filename, FileMode.Create, FileAccess.Write);
serializer.Serialize(stream, emp);
XML stream can be processed by any application, as needed, regardless of platform
slower compared to Binary serialization.
Friday, April 30, 2010
Sharepoint on Item Update add user
public override void ItemUpdated(SPItemEventProperties properties)
{
if (properties.AfterProperties["Status"].ToString().ToUpper() == "Closed".ToUpper())
{
SPSite site = new SPSite(@"http://SiteURL");
SPWeb web = site.AllWebs["mk"];
SPUser user = web.CurrentUser;
SPRoleDefinitionCollection roleDefinitions = web.RoleDefinitions;
SPRoleAssignmentCollection roleAssignments = web.RoleAssignments;
SPRoleAssignment roleAssignment = new SPRoleAssignment(@"mritunjay", "mritunjay@mritunjay.com", "Mritunjay", "myNotes");
SPRoleDefinitionBindingCollection roleDefBindings = roleAssignment.RoleDefinitionBindings;
roleDefBindings.Add(roleDefinitions["Full Control"]);
roleAssignments.Add(roleAssignment);
}
}
{
if (properties.AfterProperties["Status"].ToString().ToUpper() == "Closed".ToUpper())
{
SPSite site = new SPSite(@"http://SiteURL");
SPWeb web = site.AllWebs["mk"];
SPUser user = web.CurrentUser;
SPRoleDefinitionCollection roleDefinitions = web.RoleDefinitions;
SPRoleAssignmentCollection roleAssignments = web.RoleAssignments;
SPRoleAssignment roleAssignment = new SPRoleAssignment(@"mritunjay", "mritunjay@mritunjay.com", "Mritunjay", "myNotes");
SPRoleDefinitionBindingCollection roleDefBindings = roleAssignment.RoleDefinitionBindings;
roleDefBindings.Add(roleDefinitions["Full Control"]);
roleAssignments.Add(roleAssignment);
}
}
Registring Event Listner in Sharepoint
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);
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);
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;
}
Subscribe to:
Posts (Atom)