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;
}
Wednesday, December 29, 2010
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
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
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
<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);
}
}
{
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;
}
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)