Programmatically create a list and a SPFieldMultiLineText with RichText

dimanche 20 octobre 2013

First, you need to create your List :

Code:
SPWeb web = //[Get your web]
SPList MyList = Utilities.CreateList(web, Title, Key, SPListTemplateType.GenericList);

Then you do the following to create the SPFieldMultiLineText


Code:
// Add RichText column
string htmlFieldName = Utilities.AddField(MyList, SPFieldType.Note, FieldName, false, true);
SPFieldMultiLineText htmlField = MyList.Fields[FieldName] as SPFieldMultiLineText;
htmlField.RichText = true;
htmlField.RichTextMode = SPRichTextMode.FullHtml;
htmlField.Update();

You can even rename the original Title column


Code:
// Rename the original Title column
SPField TitleField = MyList.Fields[SPBuiltInFieldId.Title];
TitleField.Title = anOtherName;

Finally, we run our code snippet into an event receiver


Code:
[Guid("xxx")]
public class MybEventReceiver : SPFeatureReceiver
 {
 public override void FeatureActivated(SPFeatureReceiverProperties properties)
  {
  SPWeb web = //[Get your web]
  SPList MyList = Utilities.CreateList(web, Title, Key, SPListTemplateType.GenericList);
  // Rename the original Title column
  SPField TitleField = MyList.Fields[SPBuiltInFieldId.Title];
  TitleField.Title = anOtherName;
  // Add RichText column
  string htmlFieldName = Utilities.AddField(MyList, SPFieldType.Note, FieldName, false, true);
  SPFieldMultiLineText htmlField = MyList.Fields[FieldName] as SPFieldMultiLineText;
  htmlField.RichText = true;
  htmlField.RichTextMode = SPRichTextMode.FullHtml;
  htmlField.Update();
  }
 }

Actually, this could run for SharePoint 2010 too. 

How to install SharePoint 2013 with controlled names for databases

samedi 19 octobre 2013


Are you having a similar name for your adminCentral database : SharePoint_AdminContent_[GUID] ?
If you are looking for more control, this is how you can create databases with "better" names :


  1. Launch the SharePoint 2013 Management PowerShell as an Administrator.
  2. Type this :
    Code:
    New-SPConfigurationDatabase -DatabaseName CONFIG_DB_NAME_HERE -DatabaseServer SERVER_NAME_HERE -AdministrationContentDatabaseName ADMIN_DB_NAME_HERE -FarmCredentials (Get-Credential) -Passphrase (ConvertTo-SecureString "TYPE_YOUR_PWD_HERE" -AsPlainText -Force)
    

Notice that you can use this command, only before executing the SharePoint 2013 configuration Wizard, so just after binaries been installed.

During the installation, you'll be asked to launch the wizard and continue the process. You'll have to uncheck the checkbox.

How to know whether or not you are liking SocialPost - Sharepoint 2013 Client Object API

vendredi 18 octobre 2013

Today, I'd to speek about giving users the possibility to like SharePoint 2013 posts using the Client Object API.
You'll need to instanciate your SocialFeedManager with your context, and then call the "LikePost" method with the postId you would 'like'.


Code:
public SocialThread LikeThisPost(string SharePointWebUrl, string PostId)
 { 
 SocialFeedManager feedManager = new SocialFeedManager(ctx);
 ClientResult thread = feedManager.LikePost(PostId);
 ctx.ExecuteQuery();
 return thread.Value;
 }

This method returns the whole thread, containing the root post, all the replies and many other attributes.
Maybe you'll need to parse this result into your business post object.

From the SocialPost's LikerInfo collection you could know if the current user likes the post or not.
No need to try to implement some logic for getting this, SharePoint has already done this for you.


Code:
bool CurrentUserLikesThis = socialPost.LikerInfo.IncludesCurrentUser;

My First Post

Hi everybody,

Here are my first words on this blog.
I'm Nizar Joober, I'm 27 and I'm SharePoint developer since 2011.

I'll be sharing some points on these pages, mainly SharePoint subjects, and issues that I encounter while SharePointing.

Welcome to my blog
Copyright @ 2013 Nizar Joober - I'm SharingPoints. Designed by Templateism

Top articles