SharePoint enable List (Form Web Parts)

By default SharePoint’s Form Web Parts are disabled.

List Form web Parts disabled
List Form Web Parts Disabled

 

How to resolve this issue?

Go to your SharePoint admin center

Click settings.

Scroll down to locate the section of Custom Script

Select Allow users to run custom script on self-service created sites

Custom Script
Custom Script

Click OK.
Note: It takes up to 24 hours for the change to take effect.

List Form Web Parts enabled
List Form Web Parts enabled

Turn scripting capabilities on and off
 

.NET HTTPRequest

HTTP Handlers
They are used to process individual endpoints.
Only one handler per request is used
Can be both asynchronous or synchronous
Earliest possible point where you have access to requests

 

HTTPHandlers are extension based. This means that for every extension .aspx .html etc there is a handler (some share handler).

The example used here is very simple and does nothing special except for displaying some static text. The reason is that ideally before attempting to do something elaborate one should check if it works by doing something simple especially while learning.

The examples here were created in ASP.MVC5 applications. The extension that is used is .kk

Synchronous HTTP Handler

The Solution name is HTTP_Handler

Step 1:

Ignore routing for .kk extension in App_Start/RouteConfig.cs (The reason is that we do not want MVC to try to interpret this file)

routes.IgnoreRoute("{file}.kk");

Step 2:

We create the class that will be our handler at the top level  since this is an example and name it CustomHandler.cs

This can be achieved by inheriting IHttpHandler or by using IHttpHandlerFactory (The example uses IHttpHandler)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace HTTP_Handler
{
public class CustomHandler : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
HttpRequest Request = context.Request;
HttpResponse Response = context.Response;
Response.Write("test");
}

public bool IsReusable
{
get { return true; }
}
}
}

Step 3:

We configure the application to use the handler (Integrated mode).

In web.config

<system.webServer>

<handlers>

<add verb="*" path="*.kk" name="CustomHandler" type="HTTP_Handler.CustomHandler"/>

</handlers>

Step 4:

Build and Run

add hello.kk to the link and load it should print test on screen.

 Asynchronous HTTP Handler

 

The Solution name is HTTP_Async_Handler

Step 1:

Ignore routing for .kk extension in App_Start/RouteConfig.cs (The reason is that we do not want MVC to try to interpret this file)

routes.IgnoreRoute("{file}.kk");

Step 2:

We create the class that will be our handler at the top level  since this is an example and name it CustomHandler.cs

This can be achieved by inheriting IHttpAsyncHandler

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace HTTP_Async_Handler
{
public class CustomHandler:IHttpAsyncHandler
{
// Long Process
private static void generateNumbers(HttpContext context)
{
string s = "";
for (int i = 0; i < 1000; i++)
{
s = s + ' ' + i.ToString();
}
context.Response.Write(s);
}

public static Action<HttpContext> _Handle = generateNumbers;

public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
{
context.Response.Write("BeginProcessRequest Executed");
return _Handle.BeginInvoke(context,cb,extraData);
}

public void EndProcessRequest(IAsyncResult result)
{
// Clean up code here
}

public bool IsReusable
{
get { return true; }
}

public void ProcessRequest(HttpContext context)
{
context.Response.Write("ProcessRequest Executed Will not execute");
}
}
}

Step 3:

We configure the application to use the handler (Integrated mode).

In web.config

<system.webServer>

<handlers>

<add verb="*" path="*.kk" name="CustomHandler" type="HTTP_Handler.CustomHandler"/>

</handlers>

</system.webServer>

Step 4:

Build and Run

add hello.kk to the link and load it should print test on screen.

 

Want to know more?

Investigate IHttpHandlerFactory

Classic mode & Integrated mode (IIS)

Sharepoint 2013 List Validation

There are times which one desires to perform validations on entries in a list. For demo pourpose a Leave Request List is created. This list contains a Start Date column and an End Date column. It is sensible to add validations that the Start Date must come before the End Date. Apart from this Start Date must be in the future.

List
Request for Leave List

 

List Menu
List Menu

Click “List”

22

Click “List Settings”

 

List Settings
List Settings

This page shows plenty of options one can modify for the list, but the focus here is mainly validations. Sharepoint offers two validation types out of the box. Column Validation and List Validation.

 

Column Validation (Columns)

Column Validation
Column Validation

These validations let one specify validations with regards to thet column in isolation. for example “=[Count] <= 50”.

This can be done by clicking the column that needs to be validated in the List Settings page

 

List Validation (Validation Settings)

List Validations

There can only be one List Validation this allows specification of cross column validation. e.g. =[Start Date] < [End Date] and a single User Comment: that is displayed to the user if the dates do not pass the validation.

 

Validations in general w.r.t. SharePoint are mostly like Excel mor information on this at the Office Online

Pesrsonally I think this is a huge limitation since it leaves much to be desired to inform the user what is wrong with the entries when the form does not pass the validation. Apart from this one might need different validations depending on levels of access. For example the normal user cannot enter a past date in Start Date however and administrator might be allowed to do so within the company policy.

JavaScript Mine Sweeper

While trying to get a good grasp of JavaScript/CSS, I decided to implement Mine Sweeper.

I tried to use the standard colors for the numbering and standard icons for mines/flag/unknown.

 

I’ve identified the 5 states that any particular cell could be and designed a finite state machine for one cell

  • S is for initial state
  • B is for bomb
  • F is for flag
  • ? is for unknown
  • C is for clear
Finite State Machine for one Mine Sweeper cell
Finite State Machine for one cell

 

This is what the final product looks like

Mine Sweeper Screenshot
Mine Sweeper Screenshot

You may try it out at the link below

http://code.fairmutex.com/projects/web/minesweeper/
What I learned?
Discovered classList
Try to avoid recursion unless the recurring depth is shallow and the worst case scenario is known.

Good explanation about performance (may contain outdated information).
https://www.youtube.com/watch?v=mHtdZgou0qU

A short story of a Developer Challenge

Yesterday I came across https://www.konnekt.com/Challenge/Developer and I decided to give it a go

konnekt

Firebug was used to check for hidden elements and the pesky display:none;  was removed

firebug

… and the following text appeared

Capture

So there must be a GetKey function probably javascript and it was found

getkey

There are 5 rows and 32 columns. Make use of a [5,15][3, 8]S algorithm with mode ECB. Oh, and you will need a key, try GetKey with a certain binary parameter!

What is ECB? Electronic Code book and learned that it has to do with encryption.

Who would name an algorithm [5,15][3, 8]S ? Aha that must be some coordinates

Untitled

So [5,15][3, 8]S stands for DES. Then “There are 5 rows and 32 columns. Make use of a DES algorithm with mode ECB. Oh, and you will need a key, try GetKey with a certain binary parameter!”

Next is the key. It was staring at me in front of the elephant {01000111 01101111}

  1. function bin2txt(bin) {
  2. var res = bin.replace(/ /g,"").replace(/[01]{8}/g, function(v) {
  3. return String.fromCharCode( parseInt(v,2) );
  4. });
  5. return res;
  6. }

funnily enough when you convert this to string it becomes “Go” to complete Ready Set Go.

But when passed as a parameter to Getkey the word “origami” pops out

Other methods of finding the key in GetKey function the list

  1. var asciiToUse = [111, 114, 105, 103, 97, 109, 105]

is the ascii of  “origami” in order

Since my knowledge of DES is next to none, I thought I must convert it to hex and was trying all sorts of website encrypter/decrypters At some point I also thought that “origami elephant” is the key in hex 🙂

Then I found http://des.online-domain-tools.com/tool-form-submit/

I pasted the encrypted text and entered origami as key

result

The result was: https://www.konnekt.com/Challenge/Developer/58fb1b4f9ac643cfa5fbsbb7def6eb29

win

Other curious things

https://www.konnekt.com/Blog/News/52/Developer-Challenge

Give it a try. We’re warning you, it’s {01100100 01100001 01101101 01101110 00100000 01100101 01100001 01110011 01111001}.
bintotext the binary results in “damn easy”

Tools used

JSFIDDLE http://jsfiddle.net/fairmutex/fGHeG/1/

http://des.online-domain-tools.com/tool-form-submit/

 

GetKey description

This function checks if the binary represents the string “Go” in unrelated ways like using  Math.sqrt(5041) which is 71 which is the ascii of “G” and  110.91935  and ceil  to get 111 which is the ascii of “o” and then lists the string “origami” if the string criteria is satisfied.

Thanks for reading

Using VBA Macro to Copy data from one Excel workbook to another using string comparison

  1. Option Explicit

Code that handles the copying
Takes every value in Column A of the Destination and checks if it exists column A of the Source file if a match occurs takes the value of column B of the same row and copies it in the column B of the Destination file in the same row of the original compared value

  1. Sub Button2_Click()
  2. Dim wbSrc As Workbook
  3. Dim wsSrc As Worksheet
  4. Dim wbDest As Workbook
  5. Dim wsDest As Worksheet
  6. Dim cmpstr As String
  7. Dim valuestr As String
  8. Dim rowIndex As Integer
  9. Dim totalRows As Integer
  10. Dim result_Index As Long
  11. Dim file_name As String
  12. Dim LastRow As Long
  13. file_name = get_File_Name("Old")
  14. If file_name <> "" Then
  15. Set wbSrc = Workbooks.Open(Filename:=file_name)
  16. Set wsSrc = wbSrc.Worksheets(1)
  17. file_name = get_File_Name("Dest")
  18. 'MsgBox file_name, vbExclamation, "Debug!!!"
  19. If file_name <> "" Then
  20. Set wbDest = Workbooks.Open(Filename:=file_name)
  21. Set wsDest = wbDest.Worksheets(1)
  22. ' Total rows in Column A in destination workbook
  23. totalRows = wsDest.Range("A1").End(xlDown).Row
  24. ' Total rows in Column A in source workbook
  25. LastRow = wsSrc.Range("A1").End(xlDown).Row
  26. ' Loop in destination rows
  27. For rowIndex = 1 To totalRows
  28. cmpstr = wsDest.Cells(rowIndex, 1).Value
  29. ' loop in source rows
  30. For result_Index = 1 To LastRow
  31. If Not IsError(Application.Match(cmpstr, wsSrc.Cells(result_Index, 1), 0)) Then
  32. wsDest.Cells(rowIndex, 2).Value = wsSrc.Cells(result_Index, 2)
  33. End If
  34. Next result_Index
  35. Next rowIndex
  36. wbDest.Save
  37. MsgBox "Users were Successfully copied."
  38. Else
  39. MsgBox "An error has Occured"
  40. End If
  41. Else
  42. MsgBox "An error has Occured"
  43. End If
  44. End Sub

Open dialog function and returns the path to the file or an empty string

  1. Public Function get_File_Name(str As String)
  2. Dim title As String
  3. title = "Please choose the " & str & " Report Excel file"
  4. FileToOpen = Application.GetOpenFilename _
  5. (title:=title, _
  6. FileFilter:="Excel Files *.xlsx (*.xlsx),")
  7. ''
  8. If FileToOpen = False Then
  9. MsgBox "No file specified.", vbExclamation, "Error!"
  10. get_File_Name = ""
  11. Else
  12. get_File_Name = FileToOpen
  13. End If
  14. End Function

I by no way claim this is the best way to do it. If you have better code for this job please share and post code or link of your work in the comment. In that case I would update the code and give you credit for your work.

Javascript Pre-Init equivalent

var treeData = [
{title: “item1 with key and tooltip”, tooltip: “Look, a tool tip!” },
{title: “item2: selected on init”, select: true },
{title: “Folder”, isFolder: true, key: “id3”,
children: [
{title: “Sub-item 3.1”,
children: [
{title: “Sub-item 3.1.1”, key: “id3.1.1” },
{title: “Sub-item 3.1.2”, key: “id3.1.2” }
]
},
{title: “Sub-item 3.2”,
children: [
{title: “Sub-item 3.2.1”, key: “id3.2.1” },
{title: “Sub-item 3.2.2”, key: “id3.2.2” }
]
}
]
},
{title: “Document with some children (expanded on init)”, key: “id4”, expand: true,
children: [
{title: “Sub-item 4.1 (active on init)”, activate: true,
children: [
{title: “Sub-item 4.1.1”, key: “id4.1.1” },
{title: “Sub-item 4.1.2”, key: “id4.1.2” }
]
},
{title: “Sub-item 4.2 (selected on init)”, select: true,
children: [
{title: “Sub-item 4.2.1”, key: “id4.2.1” },
{title: “Sub-item 4.2.2”, key: “id4.2.2” }
]
},
{title: “Sub-item 4.3 (hideCheckbox)” },
{title: “Sub-item 4.4 (unselectable)” }
]
}
];

 
var tryTree = [{}];
tryTree[0] = {};
tryTree[0].title = “item1 with key and tooltip”;
tryTree[0].tooltip = “Look, a tool tip!”;

tryTree[1] = {};
tryTree[1].title = “item2: selected on init”;
tryTree[1].select = true;

tryTree[2] = {};
tryTree[2].title = “Folder”;
tryTree[2].isFolder = true;
tryTree[2].key = “id3”;
tryTree[2].children = [{}];
tryTree[2].children[0] = {};
tryTree[2].children[0].title = “Sub-item 3.1”;
tryTree[2].children[0].children = [{}];
tryTree[2].children[0].children[0] = {};
tryTree[2].children[0].children[0].title = “Sub-item 3.1.1”;
tryTree[2].children[0].children[0].key = “id3.1.1”;
tryTree[2].children[0].children[1] = {};
tryTree[2].children[0].children[1].title = “Sub-item 3.1.2”;
tryTree[2].children[0].children[1].key = “id3.1.2”;
tryTree[2].children[1] = {};
tryTree[2].children[1].title = “Sub-item 3.2”;
tryTree[2].children[1].children = [{}];
tryTree[2].children[1].children[0] = {};
tryTree[2].children[1].children[0].title = “Sub-item 3.2.1”;
tryTree[2].children[1].children[0].key = “id3.2.1”;
tryTree[2].children[1].children[1] = {};
tryTree[2].children[1].children[1].title = “Sub-item 3.2.2”;
tryTree[2].children[1].children[1].key = “id3.2.2”;

tryTree[3] = {};
tryTree[3].title = “Document with some children (expanded on init)”;
tryTree[3].expand = true;
tryTree[3].key = “id3”;

tryTree[3].children = [{}];
tryTree[3].children[0] = {};
tryTree[3].children[0].title = “Sub-item 4.1 (active on init)”;
tryTree[3].children[0].activate = true;
tryTree[3].children[0].children = [{}];
tryTree[3].children[0].children[0] = {};
tryTree[3].children[0].children[0].title = “Sub-item 4.1.1”;
tryTree[3].children[0].children[0].key = “id4.1.1”;
tryTree[3].children[0].children[1] = {};
tryTree[3].children[0].children[1].title = “Sub-item 4.1.2”;
tryTree[3].children[0].children[1].key = “id4.1.2”;

tryTree[3].children[1] = {};
tryTree[3].children[1].title = “Sub-item 4.2 (selected on init)”;
tryTree[3].children[1].select = true;
tryTree[3].children[1].children = [{}];
tryTree[3].children[1].children[0] = {};
tryTree[3].children[1].children[0].title = “Sub-item 4.2.1”;
tryTree[3].children[1].children[0].key = “id4.2.1”;
tryTree[3].children[1].children[1] = {};
tryTree[3].children[1].children[1].title = “Sub-item 4.2.2”;
tryTree[3].children[1].children[1].key = “id4.2.2”;

tryTree[3].children[2] = {};
tryTree[3].children[2].title = “Sub-item 4.3 (hideCheckbox)”;

tryTree[3].children[3] = {};
tryTree[3].children[3].title = “Sub-item 4.4 (unselectable)”;

 

 

 

Tested with

//called with every property and it’s value
function process(key,value) {
document.write(key + ” : “+value+'<br/>’);
}

function traverse(o,func) {
for (i in o) {
func.apply(this,[i,o[i]]);
if (typeof(o[i])==”object”) {
//going on step down in the object tree!!
traverse(o[i],func);
}
}
}

//that’s all… no magic, no bloated framework
document.write(‘<br/><br/><br/><br/><br/><br/><br/><br/><table><tr><td>’);
traverse(treeData,process);
document.write(‘</td><td>’);
traverse(tryTree,process);
document.write(‘</td></tr></table>’);

 

 

 

CNF – Conjunctive Normal Form (Dimacs format) Explained

This post is just to explain the CNF DIMACS file format to people new to SAT

Boolean Operators
V – OR
^ – AND
¬ – NOT/Negation

Variable – can assume only values either 1 (true/ON)  or 0 (false/OFF)
Clause   – is the disjunction of a number of variables (negations may also be present)
A CNF expression is made up of conjunction of one or more clauses.

Every Satisfiability problem can be expressed in CNF (conjunctive normal form).

File Format

At the begining of the file there can exist one or more comment line.

comment lines start with a ‘c’

Example:

c This is a comment
c This is another comment

The following lines are information about the expression itself so an example expression is used to help understanding.
(A v ¬B v C) ^ (B v D v E) ^ (D V F)

After comments if any comes the  Problem line starts with a ‘p’

p FORMAT VARIABLES CLAUSES

FORMAT is for programs to detect which format is to be expected. Which should always be ‘cnf’

VARIABLES is the count of number of unique variables in the expression

A,B,C,D,E,F

VARIABLES = 6

CLAUSES is the number of clauses in the expression

(A v ¬B v C) ^ (B v D v E) ^ (D V F)
1             1           1        = 3

results to
p cnf 6 3

This line is followed by the information in each clause

unique variables are enumerated from 1 to n

A,B,C,D,E,F
1,2,3,4,5,6

such that
1 represents A
2 represents B
3 represents C
etc…

a negation is represented as ‘-‘

e.g.

-1 represents ¬A

Each variable information is seprated by a blank space

so

(A v ¬B v C)  is represented by 1 -2 3

Add a 0 behind to indicate the end of the clause

so

(A v ¬B v C)  is represented by 1 -2 3 0

(B v D v E)   is represented by 2 4 5 0

(D V F)       is represented by 4 6 0

The final File will be

c This is a comment
c This is another comment
p cnf 6 3
1 -2 3 0
2 4 5 0
4 6 0

Some Considerations
If you are building a parser
-the final 0 is sometimes ommited.

If you are building a SAT solver
-CNF is used just to have a common way of expressing the file format your SAT solver could transform the expression in another format for a different strategy.

Further Readings
http://en.wikipedia.org/wiki/Conjunctive_normal_form
http://www.domagoj-babic.com/uploads/ResearchProjects/Spear/dimacs-cnf.pdf
http://classes.soe.ucsc.edu/cmps132/Winter05/hw/hw8sols.pdf

Get Command prompt to Full Screen in Windows 7

Ever faced the situation where you required to copy text from a Command Prompt and ended up copying the text manually just because you bump at the dialog in Fig:1 when you attempt Alt+enter ?

This System does not support full screen mode
Fig:1

Here is the solution:

Right Click My computer (Either on the Desktop or in the Windows Menu)

Manage My Computer
Fig:2

Click Manage as shown in Fig:2

Click Device Manager (which can be found in the Computer Management on the left of the window)

Disable Display Adapter
Fig:3

Expand Display Adapters and right click and disable your Display Adapter  as shown in Fig:3 and click yes

Open the Command Prompt and press Alt+Enter and it should go full Screen

Known Issues:

  • Do not run anything in Admin mode or you may not proceed. ( If you happen to do it Alt+F4 till u can use the system again)
  • Only CMDs opened after Disabling Display Adapter are allowed to go full screen.