Get absolute URL to listitem’s default display form – Sharepoint2013


Problem : 

I need to have an absolute URL of a listitem’s display form – currently I do it the following way:


item.ParentList.ParentWeb.Url.TrimEnd('/') //""
+ "/" 
+ item.ParentList.DefaultDisplayFormUrl.Trim('/')//"Lists/WorkflowTasks/DispForm.aspx"
+ "?ID=" + item.ID //"?ID=1"

This gets me the correct URL, meaning

However this fails when my site collection is on a slightly more sophisticated host url, for example – both methods from my code return the url containing the “/sites/secondsite/ part so I end up with

How do I code it in a more reliable way?

Solution :

There are a couple of methods for this available in the object model without the need to handle the slashes etc yourself, one method using MakeFullUrl:

var fullUrl = item.ParentList.ParentWeb.Site.MakeFullUrl(item.ParentList.DefaultDisplayFormUrl);


+ "?ID=" + item.ID //"?ID=1"



Using C# to read data from a SharePoint list using the SharePoint REST API

If you’re working with a C# application that is required to read information contained in a SharePoint list located on an external SharePoint farm, the SharePoint REST API can provide just the solution that you’re looking for.  Here is some sample code that you can use for accessing the information contained in that SharePoint list:

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Web.Script.Serialization;

namespace Sample
    public class SharePointListReader

        public List<SharePointListItem> GetAllSPListItems()
            List<SharePointListItem> posts = new List<SharePointListItem>();
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://webapp/site/_api/web/lists/getbytitle('listName')/items?$select=id,Title");
            request.Method = "GET";
            request.Accept = "application/json;odata=verbose";
            request.ContentType = "application/json;odata=verbose";
            request.Credentials = System.Net.CredentialCache.DefaultCredentials;
            WebResponse response = request.GetResponse();
            Data data = null;

            // Read the returned posts into an object that can be consumed by the calling application
            using (response)
                using (var reader = new StreamReader(response.GetResponseStream()))
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                        string jSON = reader.ReadToEnd();
                        data = serializer.Deserialize(jSON);
                    catch (Exception ex)
                        throw new Exception(string.Format("An error occurred when reading the list items from SharePoint: {0}; {1}", ex.Message, ex.StackTrace));
            foreach (SharePointListItem post in data.d.results)
            return posts;

    public class Data
        public Results d { get; set; }

    public class Results
        public SharePointListItem[] results { get; set; }

    public class SharePointListItem
        public string id { get; set; }
        public string Title { get; set; }

SharePoint : can’t see app templates for Announcement & survey


Just check if Team Collaboration Lists feature activated? you can find this under Site Settings > Site features.

This feature enables Wiki Page Library, Links, Announcements, Calendar, Discussion Board, Tasks and few other templates.

If you still have the issue then the easiest way is by directly accessing create.aspx page which you can find user _layouts/15/create.aspx.

For SharePoint 2013: http://<site URL>/_layouts/15/create.aspx

For SharePoint 2010: http://<site URL>/_layouts/create.aspx

Error occurred in deployment step ‘Install app for SharePoint’: The provided App differs from another App with the same version and product ID


Cannot deploy a solution and getting the error: Error occurred in deployment step ‘Install app for SharePoint’: The provided App differs from another App with the same version and product ID.

Open the AppManifest.xml in code view and generate a new guid for the app -> Change value of ProductID.

This task requires the application to have elevated permissions.

I start my Visual Studio 2010, create new SharePoint project and after giving project name and clicking OK I get this error:


This task requires the application to have elevated permissions.

I already started VS2010 as administrator, but that’s not the solution yet.

I log to the server via Remote Desktop with my domain account. To be able to connect VS to SharePoint, my account needs to be added to local administrators group (get your admin/domain admin to do that).
Afterwards, I need to log out from Windows (thus ending my session) and log in again. Now, when I run Visual Studio as administrator, I can create new SharePoint project.

Regular Expressions Example (c#) – CSharp


The following example shows the use of Regular Expresssions in C#.This program has basic validation scripts for validation easily useable in all programs.

csc /r:System.Text.RegularExpressions.dll,System.dll Validation.cs
using System.Text.RegularExpressions;
using System;
class Validation
public static void Main()
String strToTest;
Validation objValidate=
new Validation();
Console.Write(“Enter a String to Test for Alphabets:”);
Console.WriteLine(“{0} is Valid Alpha String”,strToTest);
Console.WriteLine(“{0} is not a Valid Alpha String”,strToTest);
// Function to test for Positive Integers.
public bool IsNaturalNumber(String strNumber)
Regex objNotNaturalPattern=
new Regex(“[^0-9]”);
Regex objNaturalPattern=
new Regex(“0*[1-9][0-9]*”);
return !objNotNaturalPattern.IsMatch(strNumber) &&objNaturalPattern.IsMatch strNumber);
// Function to test for Positive Integers with zero inclusive
public bool IsWholeNumber(String strNumber)
Regex objNotWholePattern=
new Regex(“[^0-9]”);
return !objNotWholePattern.IsMatch(strNumber);
// Function to Test for Integers both Positive & Negative
public bool IsInteger(String strNumber)
Regex objNotIntPattern=
new Regex(“[^0-9-]”);
Regex objIntPattern=
new Regex(“^-[0-9]+$|^[0-9]+$”);
return !objNotIntPattern.IsMatch(strNumber) &&
// Function to Test for Positive Number both Integer & Real
public bool IsPositiveNumber(String strNumber)
Regex objNotPositivePattern=
new Regex(“[^0-9.]”);
Regex objPositivePattern=
new Regex(“^[.][0-9]+$|[0-9]*[.]*[0-9]+$”);
Regex objTwoDotPattern=
new Regex(“[0-9]*[.][0-9]*[.][0-9]*”);
return !objNotPositivePattern.IsMatch(strNumber) &&
objPositivePattern.IsMatch(strNumber) &&!objTwoDotPattern.IsMatch(strNumber);
// Function to test whether the string is valid number or not
public bool IsNumber(String strNumber)
Regex objNotNumberPattern=
new Regex(“[^0-9.-]”);
Regex objTwoDotPattern=
new Regex(“[0-9]*[.][0-9]*[.][0-9]*”);
Regex objTwoMinusPattern=
new Regex(“[0-9]*[-][0-9]*[-][0-9]*”);
String strValidRealPattern=”^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$”;
String strValidIntegerPattern=”^([-]|[0-9])[0-9]*$”;
Regex objNumberPattern =
new Regex(“(” + strValidRealPattern +”)|(” +
trValidIntegerPattern + “)”);
return !objNotNumberPattern.IsMatch(strNumber) &&!objTwoDotPattern.IsMatch
strNumber) && !objTwoMinusPattern.IsMatch(strNumber) && objNumberPattern.IsMatch(strNumber);
// Function To test for Alphabets.
public bool IsAlpha(String strToCheck)
Regex objAlphaPattern=
new Regex(“[^a-zA-Z]”);
return !objAlphaPattern.IsMatch(strToCheck);
// Function to Check for AlphaNumeric.
public bool IsAlphaNumeric(String strToCheck)
Regex objAlphaNumericPattern=
new Regex(“[^a-zA-Z0-9]”);
return !objAlphaNumericPattern.IsMatch(strToCheck);

There is another simple way to perform these validation think of it while the next article comes.

SharePoint 2013 Prerequisites Install Error


While installing SharePoint 2013 prerequisites on Windows Server 2012 and SQL Server 2012, I have received the error “There was an error installing the prerequisites…” After checking out the logs (under %TEMP%\prerequisiteinstaller.<date>.<time>.log), you quickly learn that prerequisite install failed because of Microsoft SQL Server 2008 R2 SP1 Native Client.

To bypass this problem, you can manually download Microsoft SQL Server 2008 R2 SP1 Native Client from and install it. After you manually download Microsoft SQL Server 2008 R2 SP1 Native Client, go ahead and restart SharePoint 2013 prerequisite installer. Now SharePoint 2013 prerequisites should install successfully.

My Weblog registry is a directory which stores settings and options for my Professional Life (mostly SharePoint)

%d bloggers like this: