Customize the SharePoint listform (newform, editform, listform) with custom controls and javascript

This is the Visual studio version for SharePoint 2013 that i created of this initial code plex project

“Out of the box, Microsoft SharePoint has a very rich set of features, but sometimes you need more, or something a little different, to meet the needs of your project. This article will discuss various methods of presenting the UI for SharePoint list forms, such as the New, Edit, and Display forms used when adding an item to a list, or viewing and editing items.”

This include modifications of Create form only.

To activate the feature :

1. Activate site collection feature named “Code Project List Forms Demo”

2. Create a list based on the list definition named : “CP Project Redering Template Def”

3. The create form will contain the text from the user control “UserControl1” that you can customize, and also from : CPRenderingTemplate (which is the template of the form with save button etc)

https://sp2013customformtemplates.codeplex.com/

[SharePoint 2010 – Error fixing] Content By Query WebPart, display items links with wrong URL

image
You are programmatically creating a ContentQueryWebPart and when you test the solution, you try to click on an item link and you get a :
“404 NOT FOUND” page error

The error :

The Content By Query Webpart displays items url as :
http://jeff/sites/test/News/Lists/Posts/1_.000 or
http://jeff/sites/test/News/Lists/Posts/2_.000

 

Solution :

When you programmatically create the CQWP, you need to set the attribute UseCopyUtil to true.
wpCqwp.UseCopyUtil = true;
After, the item url should works and will look like :
http://jeff/sites/dzdza/_layouts/CopyUtil.aspx?Use=id&Action=dispform&ItemId=2&ListId=0b3c3cfc-5724-48e6-85ed-4943eae4f3b9&WebId=954e1a32-c41d-46f1-94b8-615ffd01156d&SiteId=edf289e7-9e97-4429-a9cf-e7d4af9636f2&Source=http%3A%2F%2Fjeff%2Fsites%2Fdzdza%2FSitePages%2FHome%2Easpx

 

Explanation :

By default, when you create a CQWP by the interface, SharePoint set the property UseCopyUtil to true.
Programmatically it’s set to false (i saw it by exporting the webpart, which gave me a .webpart file , and i compared it to a content query webpart created by interface).
Msdn explains, about that property that :
“Objects that are not streamed, such as announcements or calendar events, do not have an associated URL. When you set this property to true, objects that are not streamed have an associated URL that points to the View property of the item. “ Msdn
 
Voila !

[SharePoint 2010 Developpement] Getting started with SharePoint 2010 Developpement, thanks to SharePoint 2010 – 101 Codes Samples (MSDN)

Microsoft has published a SharePoint 2010 Code sample pack. Containing 101 Codes samples !
If I had that when i began to learn SharePoint, it would have saved me a lot of time.
Language are C# and VB, for SharePoint on premise AND Online !!
image
Some of really useful features are, for a sharepoint developper :

  • Programmatically create masterpage for Sharepoint 2010, and apply the masterpage programmatically thanks to a Feature Event Receiver
  • Programmatically create content type for Sharepoint 2010
  • Create List definition for SharePoint 2010

Or some advanced one :

  • Use Azure, WCF, Sharepoint Web service in Webpart, event receiver or Jobtimer

Here the complete list :

  • SharePoint 2010 Leveraging HTML5 Objects in SharePoint
  • SharePoint 2010 Developing JQuery-Enabled Web Parts
  • SharePoint 2010 Creating Document Sets Programmatically
  • SharePoint 2010 Developing List Definitions
  • SharePoint 2010 Hosting Silverlight Applications that Call Azure Services
  • SharePoint 2010 Developing AJAX-Enabled Web Parts
  • SharePoint 2010 Developing Styled Master Pages
  • SharePoint 2010 Programmatically Finding Tagged Items
  • SharePoint 2010 Creating Content Types Programmatically
  • SharePoint 2010 Using JavaScript to Enable Notifications
  • SharePoint 2010 Performing Cross-List Queries
  • SharePoint 2010 Using JavaScript and CAML to Query Lists
  • SharePoint 2010 Developing Delegate Controls
  • SharePoint 2010 Developing Connected Silverlight Web Parts
  • SharePoint 2010 Developing Starter Master Pages
  • SharePoint 2010 Developing Application Pages
  • SharePoint 2010 Developing Custom Navigation Providers
  • SharePoint 2010 Working with Disposable Objects
  • SharePoint 2010 Using JavaScript to Show Dialog Boxes
  • SharePoint 2010 Calling RESTful SharePoint Services From Desktop Applications
  • SharePoint 2010 Using REST to Obtain Excel Charts
  • SharePoint 2010 Developing Connected Web Parts
  • SharePoint 2010 Creating List Items from Silverlight
  • SharePoint 2010 Retrieving Single List Items in REST Requests
  • SharePoint 2010 Using REST to Discover the Contents of Excel Worksheets
  • SharePoint 2010 Logging Site Events Programmatically
  • SharePoint 2010 Programmatically Reading User Profile Properties
  • SharePoint 2010 Displaying User Profile Pictures Programmatically
  • SharePoint 2010 Creating Taxonomies Programmatically
  • SharePoint 2010 Using JavaScript to Edit and Save Values in Items
  • SharePoint 2010 Managing Document Sets Programmatically
  • SharePoint 2010 Developing Web Templates
  • SharePoint Online Authenticating Using the Client-Side Object Model
  • SharePoint 2010 Using JavaScript to Create Lists
  • SharePoint 2010 Developing Workflow Activities
  • SharePoint 2010 Creating Custom Timer Jobs
  • SharePoint Online Accessing Web Services
  • SharePoint 2010 Displaying Video Files Stored in Azure
  • SharePoint 2010 Performing Cached Cross-Site Queries
  • SharePoint 2010 Declaring Records Programmatically
  • SharePoint 2010 Developing Custom Expiration Actions
  • SharePoint 2010 Accessing SharePoint Lists from External WCF Services
  • SharePoint 2010 Developing Custom Expiration Formulae
  • SharePoint 2010 Developing Event Receivers
  • SharePoint 2010 Performing Searches from Silverlight
  • SharePoint 2010 Using JQuery to Retrieve List Contents in JSON
  • SharePoint 2010 Using REST to Query Data Ranges in Excel Worksheets
  • SharePoint 2010 Developing Feature Receivers
  • SharePoint 2010 Canceling Synchronous Events
  • SharePoint 2010 Creating Custom SharePoint Service Applications
  • SharePoint 2010 Developing Custom Field Controls
  • SharePoint 2010 Developing Sequential Workflows
  • SharePoint 2010 Creating Custom Field Types
  • SharePoint 2010 Using JavaScript to Get Details About Sites
  • SharePoint 2010 Calling WCF Services from Timer Jobs
  • SharePoint 2010 Developing State Machine Workflows
  • SharePoint 2010 Logging Data to the Developer Dashboard
  • SharePoint Online Deploying Sandboxed Content Types and List Definitions
  • SharePoint Online Creating and Deploying Sandboxed Web Parts
  • SharePoint 2010 Using JavaScript to Retrieve and Interrogate Items in Lists
  • SharePoint 2010 Using JavaScript to Get Details About Site Collections
  • SharePoint 2010 Developing Page Layouts
  • SharePoint Online Accessing Current User Information in Sandboxed Solutions
  • SharePoint 2010 Calling WCF Services from Web Parts
  • SharePoint 2010 Retrieving List Contents and Parsing Atom Responses
  • SharePoint 2010 Developing Editor Web Parts
  • SharePoint 2010 Developing Branded Media Controls
  • SharePoint 2010 Using JavaScript to Delete Items from Lists
  • SharePoint 2010 Using LINQ in REST Requests
  • SharePoint 2010 Uploading SharePoint Library Content to Azure Storage
  • SharePoint 2010 Using JavaScript to Update Site Properties
  • SharePoint 2010 Calling WCF Services Hosted in SharePoint
  • SharePoint 2010 Creating Items in Lists from External WCF Services
  • SharePoint Online Creating Excel Worksheets by Using Excel Web App
  • SharePoint 2010 Developing Sandboxed Web Parts
  • SharePoint 2010 Creating Content Organizer Rules Programmatically
  • SharePoint 2010 Using REST to Create a SharePoint and Bing Maps Mashup
  • SharePoint 2010 Developing Site Definitions
  • SharePoint 2010 Developing Ribbon Drop Down Controls
  • SharePoint 2010 Calling WCF Services from Event Receivers
  • SharePoint 2010 Creating Custom SharePoint Service Applications
  • SharePoint 2010 Developing Custom Field Controls
  • SharePoint 2010 Developing Sequential Workflows
  • SharePoint 2010 Creating Custom Field Types
  • SharePoint 2010 Using JavaScript to Get Details About Sites
  • SharePoint 2010 Calling WCF Services from Timer Jobs
  • SharePoint 2010 Developing State Machine Workflows
  • SharePoint 2010 Logging Data to the Developer Dashboard
  • SharePoint Online Deploying Sandboxed Content Types and List Definitions
  • SharePoint Online Creating and Deploying Sandboxed Web Parts
  • SharePoint 2010 Using JavaScript to Retrieve and Interrogate Items in Lists
  • SharePoint 2010 Using JavaScript to Get Details About Site Collections
  • SharePoint 2010 Developing Page Layouts
  • SharePoint Online Accessing Current User Information in Sandboxed Solutions
  • SharePoint 2010 Calling WCF Services from Web Parts
  • SharePoint 2010 Retrieving List Contents and Parsing Atom Responses
  • SharePoint 2010 Developing Editor Web Parts
  • SharePoint 2010 Developing Branded Media Controls
  • SharePoint 2010 Using JavaScript to Delete Items from Lists
  • SharePoint 2010 Using LINQ in REST Requests
  • SharePoint 2010 Uploading SharePoint Library Content to Azure Storage
  • SharePoint 2010 Using JavaScript to Update Site Properties
  • SharePoint 2010 Calling WCF Services Hosted in SharePoint
  • SharePoint 2010 Creating Items in Lists from External WCF Services
  • SharePoint Online Creating Excel Worksheets by Using Excel Web App
  • SharePoint 2010 Developing Sandboxed Web Parts
  • SharePoint 2010 Creating Content Organizer Rules Programmatically
  • SharePoint 2010 Using REST to Create a SharePoint and Bing Maps Mashup
  • SharePoint 2010 Developing Site Definitions
  • SharePoint 2010 Developing Ribbon Drop Down Controls
  • SharePoint 2010 Calling WCF Services from Event Receivers
  • SharePoint 2010 Accessing List Items from Silverlight
  • SharePoint Online Creating and Deploying Sandboxed Event Receivers
  • SharePoint 2010 Performing Searches from Web Parts
  • SharePoint 2010 Deleting Items in Lists from External WCF Services
  • SharePoint 2010 Developing Solution Validators
  • SharePoint 2010 Updating SQL Azure Records from Web Parts
  • SharePoint 2010 Calling Azure Services from Timer Jobs
  • SharePoint 2010 Importing Content by Using the Content Deployment API
  • SharePoint 2010 Calling WCF Services from Custom Workflow Activities
  • SharePoint Online Creating and Deploying Sandboxed Workflow Activities
  • SharePoint Online Creating Documents Using Word, PowerPoint, or OneNote Web App
  • SharePoint 2010 Calling Azure Services from Web Parts
  • SharePoint 2010 Creating SQL Azure Records from Web Parts
  • SharePoint Online Creating and Deploying Sandboxed Feature Receivers
  • SharePoint 2010 Developing Ribbon Actions
  • SharePoint 2010 Querying SQL Azure Data from Web Parts
  • SharePoint 2010 Retrieving List Contents in JSON Format and Parsing Responses
  • SharePoint 2010 Exporting Content by Using the Content Deployment API
  • SharePoint 2010 Calling Azure Services from Custom Workflow Activities
  • SharePoint 2010 Deleting SQL Azure Records from Web Parts
  • SharePoint 2010 Calling Azure Services from Event Receivers
  • SharePoint 2010 Retrieving List Contents in JSON Format and Parsing Responses
  • SharePoint 2010 Exporting Content by Using the Content Deployment API
  • SharePoint 2010 Calling Azure Services from Custom Workflow Activities
  • SharePoint 2010 Deleting SQL Azure Records from Web Parts
  • SharePoint 2010 Calling Azure Services from Event Receivers
  • SharePoint 2010 Updating SQL Azure Records from Web Parts
  • SharePoint 2010 Calling Azure Services from Timer Jobs
  • SharePoint 2010 Importing Content by Using the Content Deployment API
  • SharePoint 2010 Calling WCF Services from Custom Workflow Activities
  • SharePoint Online Creating and Deploying Sandboxed Workflow Activities
  • SharePoint Online Creating Documents Using Word, PowerPoint, or OneNote Web App
  • SharePoint 2010 Calling Azure Services from Web Parts
  • SharePoint 2010 Creating SQL Azure Records from Web Parts
  • SharePoint Online Creating and Deploying Sandboxed Feature Receivers
  • SharePoint 2010 Developing Ribbon Actions
  • SharePoint 2010 Querying SQL Azure Data from Web Parts
  • SharePoint 2010 Accessing List Items from Silverlight
  • SharePoint Online Creating and Deploying Sandboxed Event Receivers
  • SharePoint 2010 Performing Searches from Web Parts
  • SharePoint 2010 Deleting Items in Lists from External WCF Services
  • SharePoint 2010 Developing Solution Validators

Thanks microsoft & msdn Clignement d'œil
Download link : http://code.msdn.microsoft.com/SharePoint-2010-101-Code-da251182

[SharePoint 2010 – Error Fixing] SPException invalid date/time (Erreur : Valeur de date/d’heure non valide. Un champ de date/d’heure contient des données non valides. Vérifiez la valeur, puis réessayez)

What did i try to do ?

I’m creating SPListItem Programmatically (create elements in a list) and when the item.update(); is called by the code, the following error is thrown :
“Erreur : Valeur de date/d’heure non valide.Un champ de date/d’heure contient des données non valides. Vérifiez la valeur, puis réessayez”
or in english :
“SPException : invalid date/time…”

What could be the problem ?

  1. The date format is not correct
  2. The date is not correct (minimum date for SharePoint ?)

Solving the problem

I’m giving an example of an incorrect date value “01/01/0001 00:00:00” :

   1: SPList list = web.Lists["myList"];
   2:  
   3: SPListItem item;
   4: string date = "01/01/0001 00:00:00";
   5:  
   6: item = list.Items.Add();
   7:  
   8: item["currentDate"] = date;
   9: if (DateTime.TryParse(row["currentDate"].ToString(), out dateTime) == true)
  10: {
  11:     //si la date est définit
  12:     if (dateTime.ToString() != "01/01/0001 00:00:00")
  13:     {
  14:         item["currentDate"] = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Parse(date));
  15:     }
  16: }
  17:  
  18: item.update();
  19: list.update();

01/01/2001 is an incorrect value for a date in sharepoint.

And we check the date in order to respect sharepoint dates rules, using the method : CreateISO8601DateTimeFromSystemDateTime.

Have you ever had other issue with dates and SPListItem ?

[SharePoint 2010 – Developpement] Allow embedded youtube video in blog post content (as content editor webpart), with new embedded youtube code (iframe) for SharePoint 2010 blog post

What is that ?

Based on this excellent tutorial from kirk Evans : http://blog.evepoints.com/2010/11/add-video-sharepoint-2010-blog.html
This will allow you to add youtube video in a blog content.
Basic sharepoint feature permit you to add the video by modifying the HTML code, from the Insert HTML button of sharepoint, but that is not really user friendly.
Preview, on a blog post :
image

 

New youtube embedded format ?

I modified one of the method of Kirk Evans in order to accept the new youtube embedded video format. The new embedded video format looks like this :

New youtube embedded code for video (<iframe) :

image

Old youtube embedded code for video (object) :

image

So to update Kirk Evans code, replace the last method by :

   1: private string ReplaceEmbedsWithTokens(string body)
   2:         {
   3:             //VARS
   4:                 string returnString = null;
   5:                 //Old version of youtube embedded
   6:                 Regex rx = new Regex("(&lt;object).*?(&lt;embed src=&quot;)(?<src>.*?)(&quot;)(.*?)(&lt;/object&gt;)");
   7:  
   8:             //CLEANING from a text editor
   9:             body = body.Replace("nr", " ");
  10:             body = body.Replace("rn", " ");
  11:  
  12:             if (rx.IsMatch(body) == false)
  13:             {
  14:                 //New version of youtube embedded
  15:                 rx = new Regex("(&lt;iframe).*?(src=&quot;)(?<src>.*?)(&quot;)(.*?)(&lt;/iframe&gt;)");
  16:                 returnString = rx.Replace(body, "[[BLOGVIDEO: ${src}]]");
  17:                 returnString = returnString.Replace("embed", "v");
  18:             }
  19:             else
  20:             {
  21:                 //Old version of youtube embedded
  22:                 returnString = rx.Replace(body, "[[BLOGVIDEO: ${src}]]");
  23:             }
  24:             
  25:             
  26:             return returnString;
  27:         }

It also fix a bug : when you paste the embedded code in a word document in order to save it, and then you paste it in a blog, it won’t work properly.

Enjoy, and thanks again Kirk Evans