Wednesday, December 29, 2010

Profile Image of user in Sharepoint

Function to get User profile image in Sharepoint.


public string userInfo(SPUser pUser, SPSite pSite)
{
ServerContext context = ServerContext.GetContext(pSite);
UserProfileManager profileManager = new UserProfileManager(context);

UserProfile profile_User = profileManager.GetUserProfile(pUser.LoginName);
UserProfileValueCollection values = profile_User[PropertyConstants.PictureUrl];
String urlImage = "";
if (values.Count > 0)
{
SPFieldUrlValue urlValue = new SPFieldUrlValue(values.Value.ToString());
urlImage = urlValue.Url;
}
return urlImage;
}

Monday, August 2, 2010

calculated column lookup have Prepend value string#;

Recently I faced problem in pulling the data from the Calculated field as a lookup column in the list, and in the datasheet view the vaues were Prepend by string#;.
Following is the hotfix given by microsoft to resolve the issue.

URL of Hotfix : http://support.microsoft.com/kb/948952

Tuesday, July 6, 2010

Today in calculated column

For getting Today in the sharepoint calculated column we need to fool sharepoint list so that the Today function will be available in the calculated column
Steps to get the Today in calculated Column
1. Create a Column name Today
2. Create the calculated column and write your formulae with respect to Today
3. Delete the Today column.
By doing the above steps you will find the value in the calculated column

Wednesday, May 19, 2010

Left Navigation for Weppart Page

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 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);
}
}

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);