Skip to main content

Posts

Showing posts from July, 2012

How to get SPUser or SPGroup from Person or Group field

You have person or group field in SharePoint list and you want to programmatically get the user or person. The below code to gets SPUser from User or Group field in the list when multiple choice and Groups are not allowed in the field: //get SPUser SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users"); SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["Users"].ToString()); SPUser user = userFieldValue.User; This part of code would help you to get SPUser when multiple choice is allowed and groups are not allowed: //Multiple choices are allowed SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users"); SPFieldUserValueCollection userFieldValueCollection = (SPFieldUserValueCollection)userField.GetFieldValue(item["Users"].ToString()); foreach (SPFieldUserValue userFieldValue in userFieldValueCollection) {     Console.WriteLine("     " + userFieldValue.User.LoginName); } And when group

Adding new font into Rich Text Editor font DropDown box in SP 2010

It’s just as easy as that but the style sheet class must be defined specially and the same reference should called in your master page. The code for that looks like this, where I used a font from googles front directory. FontCSSStyles.css /*************** Changing SP2010 default font **************/ /* Add “Helvetica” font from googles directory http://www.google.com/webfonts/family?family=Helvetica */ @import url("http://fonts.googleapis.com/css?family=Helvetica"); .ms-rteFontFace-12 {      -ms-name: "Helvetica";      font-family: "Helvetica", arial, sans-serif;     -webkit-font-family: "Helvetica", arial, sans-serif; -moz-font-family: "Helvetica", arial, sans-serif; -o-font-family: "Helvetica", arial, sans-serif; } .ms-rteFontSize-14 { font-size:14pt; -webkit-font-size:14pt; -moz-font-size:14pt; -o-font-size:14pt; } .ms-rteFontSize-16 { font-size:16pt; -webkit-font-size:16pt; -moz-f

Access denied within SPSecurity.RunWithElevatedPrivileges

Normally we will use  SPSecurity.RunWithElevatedPrivileges() to execute some code that has to be run under some higher privileges. Whenever we use SPSecurity.RunWithElevatedPrivileges(), it will execute the code under the context of Application Pool identity. Now we can see a scenario where we will get the “Access denied” exception from the code block even if you use SPSecurity.RunWithElevatedPrivileges. This was the code snippet that I have used initially inside a custom webpart to read XML content from of an InfoPath form which was uploaded in a document library. This code will throw an “Access denied” exception while calling the OpenBinaryStream() method whenever I execute it through an Anonymous user account. SPSecurity .RunWithElevatedPrivileges( delegate ()  {        SPWeb  oWeb =  SPContext .Current.Web;        SPList  oList = oWeb.Lists[ "TestList" ];  }); Here the problem was, whenever we take the SPWeb instance using   SPWeb  oWeb