Point Deep

Mundeep's Tech Blog

Archive for August, 2008

How to Html Encode a string in a c# windows application?

Posted by mundeep on August 21, 2008

To HtmlEncode a string from within a Windows application you need to make sure that:

1) You have a reference to System.Web

2) You use the System.Web.HttpUtility.HtmlEncode method.

For example:

using System.Web;

public string MyHtmlEncode(string inputString) {
     return HttpUtility.HtmlEncode(inputString);
}
Advertisements

Posted in .NET | Tagged: , , , | 5 Comments »

What accounts does the people picker show?

Posted by mundeep on August 20, 2008

My colleague Ishai Sagi recently did some research into what accounts the people picker shows and determined the LDAP query that was being used to display accounts if you are using Windows authentication. I did some further research into this and i have noticed that aswell as your authentication provider source (eg. LDAP accounts for sites using Windows Authentication/Active Directory) the picker also shows accounts from the User Information List.

This is important to note as it means that accounts that may have been deleted or disabled in your authentication provider still come up to be selected by users that are entering information into a people field.

For further details on the User Information List see this article on Andrew Connell’s blog which appears to be for Sharepoint 2003 however seems to still mostly apply for MOSS. Also Sahil Malik has done some research into User Profile Information and how it flows.

Posted in Sharepoint | Tagged: , , , , | Leave a Comment »

Value does not fall within the expected range

Posted by mundeep on August 14, 2008

I was debugging a problem today where i would get the following error recently when trying to associate a content type with a document library:

Value does not fall within the expected range. at Microsoft.SharePoint.SPFileCollection.get_Item(String urlOfFile)
at Microsoft.SharePoint.SPContentTypeCollection.Add(SPContentType contentType)
at Microsoft.SharePoint.ApplicationPages.AddContentTypeToListPage.Update(Object o, EventArgs e)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

After examining the elements.xml and confirming that (a) all the bound content types exists and (b) all the site columns used by the content types existed, i noticed that there was a mis-match in the name of the content-type and the url used in the module to deploy the document template. A snippet of the elements.xml specific to one of the content-types is shown below.

  <ContentType Name="Briefing (Event)" Group="Custom Document Content Types" Description="" ID="0x0101002DB264DB4656424CB8247FDE6BA03F7E021C">
    <FieldRefs>
      <FieldRef ID="{52578fc3-1f01-4f4d-b016-94ccbcf428cf}" Name="Comments" />
      <FieldRef ID="{cd94be8c-d754-4a6d-865d-7cb40375b11c}" Name="Document Status" />
	  ...
      <FieldRef ID="{130da223-b498-417c-9bdd-1fc2ac43aa6e}" Name="Country" />
    </FieldRefs>
    <DocumentTemplate TargetName="Briefing_template.doc" />
  </ContentType>
  <Module Name="Briefing" Url="_cts/Briefing" RootWebOnly="true">
    <File Url="Briefing_template.doc" Name="Briefing_template.doc" Type="Ghostable" />
  </Module>

The mistake was that the Url=”_cts/Briefing” property of the module should have been Url=”_cts/Briefing (Event)” to match the Name of the content-type.

Update: I also ran into the same error on another content type where the name of the template file in the tag did not match the actual filename.

Posted in Sharepoint | Tagged: , , | Leave a Comment »

Clearing Active Directory Values in C#

Posted by mundeep on August 5, 2008

To clear values in Active Directory they must be set to NULL and not “” or empty.
This can easily be done by using the Clear() method on the property value collection for the active directory field you wish to update.

using System.DirectoryServices;

public void ClearAdField(string fieldName, DirectoryEntry adEntry) {
  PropertyValueCollection adValue = adEntry.Properties[fieldName];
  adValue.Clear();
  adEntry.CommitChanges();
}

Posted in .NET | Tagged: , | 1 Comment »