Tuesday, February 24, 2015

How to update TaxonomyField sharepoint 2013

the most simple solution, and occasionally the only working one, is to find the Term itself and send it and let SP to handle everything else, and the code is much shorter

this is the code for updating the field

Term ItemTypeTerm = GetTermByName();

if (ItemTypeTerm != null)
    TaxonomyField ItemTypeField =       

    ItemTypeField.SetFieldValue(field, ItemTypeTerm);

Sharepoint 2013 SPView does not bring all items and/or fields

i created a handler to bring me a view, so say i had this url for the view

to i sent my view the server relative url

and used it to open a new SPSite and SPWeb and get the items, yet i just couldn't get all my items.
yet when i tried by using the SPContext.Site it worked.

i dont know why, but the context of how the SPSite was opened affects the view.

my final code looks like this
using (SPSite tempSite = new SPSite(serverUrl + serverRelativeViewUrl))
    using (SPWeb getUrlWeb = tempSite.OpenWeb())
        spwebUrl = getUrlWeb.ServerRelativeUrl;

using (SPWeb tempWeb = spContext.Site.OpenWeb(spwebUrl))
    string viewUrl = item.MethodValue;
    if (viewUrl.StartsWith("/") == false)
        viewUrl = "/" + viewUrl;
    SPView oView;
    {        oView = tempWeb.GetViewFromUrl(viewUrl);
    catch (Exception viewEX)
    ...more code...

Search Application Topology errors (sharepoint 2013)

you may have encountered this problem like this
"SharePoint 2013 Search Topology Activation Error: "Unable to retrieve topology component health states. This may be because of the admin component is not up and running".

or like this, having index partition or any other of the 5 components with a warn or error (image is edited to fit).

a more common case we had was having noderunner limited to 300MB.

so the solution was to bring it up to 500.
C:\Program Files\Microsoft Office Servers\15.0\Search\Runtime\1.0\noderunner.exe.config

the conclusion is that noderunner without enough memory eventually throw an error.

Tuesday, February 17, 2015

angular ngrepeat startWith filter

today i had some fun trying to make a "startWith" filter for ng-repeat.

simple start with

the most simple solution is to modify the default angular filter, just this line inside the filter function, deep inside the angular.js file there is our function "function filterFilter()", find this line

return ('' + obj).toLowerCase().indexOf(text) > -1;

and you only need to change it to

return ('' + obj).toLowerCase().indexOf(text) === 0;

example : http://plnkr.co/edit/iRzIj77N9rAoiCSMbRyk?p=preview

any word start with

but then they asked that if we have "In God I Really Do Trust" that 't' will bring it, i.e. make a filter that will find if any word start with, so I made a little nice filter, it even supports object to 1 level depth


maybe there is an OOTB way to do it

while working on all that I noticed that the default filter comes with a comparator, so we can just use that.
the only downside here is that you must provide the scope with the comparator, so its not and individual thing, see example


on the other hand you can always put it in a service and inject it, I still think its the best thing to do.

Wednesday, February 4, 2015

Server Control with Child Control, dynamic created, retain control

public class RelatedPublicationFilesSave : Control
    protected HiddenField _test;

    protected override void OnInit(EventArgs e)
        _test= new HiddenField();
        _test.ID = "_test";
    protected override void OnLoad(EventArgs e)
        _RelatedPublicationFilesSave =
            this.FindControlById("_test") as HiddenField;
        Log.Debug("_test.Value: " + _test.Value);

the point is that OnInit happens before the page parses itself, so creating the control there without passing any value to it with the same ID will eventually render the same "name" property (UniqueID) and thus assigning the right values from the request.

lets do another example, answering this, where we want to add a table with dynamic Checkboxes count.

we start by creating a server control, creating and declaring all controls in the OnInit, rendering the HTML in the RenderControl

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication3
   public class DynamicCbs : Control
      public int CtrlsCount { get; set; }
      public List<CheckBox> lstCheckBoxs;

      /// decleration of controls must be in the OnInit since the next stage of the page life cycle is to connect whatever came back from the client to the server
      protected override void OnInit(EventArgs e)
           lstCheckBoxs = new List<CheckBox>();
           for (int i = 0; i < CtrlsCount; i++)
              string id = "DynamicCbs" + i;
              CheckBox cbx = new CheckBox()
                 ID = id,
                 Text = "i am " + id
              //add controls to control tree

       /// here you must build ur html
       public override void RenderControl(HtmlTextWriter writer)
           foreach (var cbx in lstCheckBoxs)

in the .aspx file

<%@ Register TagPrefix="my" Namespace="WebApplication3" Assembly="WebApplication3" %>
<my:DynamicCbs ID="Dynamicus" runat="server" CtrlsCount="10"></my:DynamicCbs>
<asp:Button runat="server" Text="Button" />
   <h1>true controls:</h1>
   <div runat="server" id="txt"></div>

in our .aspx.cs Page_Load
foreach (var cbx in Dynamicus.lstCheckBoxs)
  if (cbx.Checked) {
     txt.InnerHtml += cbx.ID + "<br/>";


make sharepoint (and asp.net) faster by bypassing internet certificate checks

NOTE that all that means less security.

Part 1: tell you machine that you are MS certificate domain

Run -> drivers -> etc -> edit the "hosts" file.
add " crl.microsoft.com"
sometimes the machine will not let you to edit the file directly so just make a copy, edit it and paste it back.

Part 2: tell .Net to to check certificates

run this powershell script that will put something in the registry that tells .Net to to try and check the certificates, this is the PS:

get-ChildItem REGISTRY::HKEY_USERS | foreach-object {set-ItemProperty -path ("REGISTRY::\" + $_.Name + "\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing") -name State -value 146944}

NOTE that you will get multiple errors running this script, since it does not test which item in the final sub folder is valid. 

in order to test if the script worked you will need to go deep in to that sub folder and look for a value named "State" and see that its value is "146944". sorry but this is not the place to explain it, you're welcome to google it.

to do that do:
Run -> regedit -> HKEY_USERS -> something with a guid but without "Classes" in it -> the path up in the script

Part 3: tell your apps/websites to skip checks

this is a simple one, just add to the web.config under <runtime> these two:
    <bypassTrustedAppStrongNames enabled="true" />
    <generatePublisherEvidence enabled="false" />

Part 4: tell your machine to cut timeouts.

Control Panel > Search for Policy > click Edit Group Policy > Computer Configuration >  Windows Settings > Security Settings > Public Key Policies > double click Certificate Path Validation Settings > click Tab Network Retrieval > click top check box to turn all check boxes on > set the 2 timeout values to 1. see Graphic  below. (i also did it in "Revocation" tab)