Okay, I’ve not blogged for sometime. So here a quick one just as a memory jogger for myself.

I needed to add a SharePoint URL field to a GridView to display data from a SP link list.  Here’s how i did it.

Code Snippet
  1. <asp:TemplateField>
  2.                         <HeaderTemplate>
  3.                           Title
  4.                         </HeaderTemplate>
  5.                         <ItemTemplate>
  6.                             <asp:Hyperlink NavigateUrl='<%#DataBinder.Eval(Container.DataItem, "URL").ToString().Split(new string[] {", "}, StringSplitOptions.RemoveEmptyEntries)[0]%>' Text='<%#DataBinder.Eval(Container.DataItem, "URL").ToString().Split(new string[] {", "}, StringSplitOptions.RemoveEmptyEntries)[1]%>' runat="server"></asp:Hyperlink>
  7.                         </ItemTemplate>
  8.                     </asp:TemplateField>

I know its not rocket science and there’s probably a better way to do it, but a least I won’t have to trawl through Google again to find the answer.

More to come soon. Need to get back into blogging…

Okay, I’ve not done any blogging for a while, been mega busy… But I just came across this problem in a MOSS environment, which after a bit of digging was easily resolved. Just thought I’d share…

While trying to filter a list with a Telerik component. I came across the above error ( also shown in the screen shot below)

image

After looking in the log files I discovered that is was throwing an exception of type ThrowIfMaxHttpCollectionKeysExceeded

Entry in the log file 

Error=Operation is not valid due to the current state of the object.   at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded()     at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding)     at System.Web.HttpRequest.FillInFormCollection()

After a bit of digging it turns out that this is a direct result of an MS update to thwart DOS attacks. As can be seen by the entry on Scott Guthrie’s Blog.  However, in this case, i was trying to fix an internal application so DOS attacks were not an issue.

To fix this issue add the following to the web.config file

<appSettings>
  <add key="aspnet:MaxHttpCollectionKeys" value="Number greater than 1000 until the error goes away" />
</appSettings>

I needed to set this value to 3000 to resolve the issue.   Surprised smile

One of my latest challenges was to display one of the new SharePoint 2010 social fields in a datagrid. At first this was just to display the field, but after the client seen the mouse-over functionality on the list item, they wanted to be able to assign a rating straight from the grid without having to go to the item itself. So, here’s how I went about it.

Firstly I created a custom control call as seen in the code sample below:

Rating Control
  1. [DefaultProperty("Rating")]
  2.     [ToolboxData("<{0}:RatingControl runat=server></{0}:RatingControl>")]
  3.     public class RatingControl : WebControl
  4.     {
  5.         protected override void OnInit(EventArgs e)
  6.         {
  7.             base.OnInit(e);
  8.             Page.RegisterRequiresControlState(this);
  9.         }
  10.  
  11.  
  12.         [Bindable(true)]
  13.         [Category("Binding")]
  14.         [DefaultValue("")]
  15.         [Localizable(true)]
  16.         public SPField RatingField
  17.         {
  18.             get
  19.             {
  20.                 SPField field = (SPField)ViewState["RatingField"];
  21.                 return field;
  22.             }
  23.  
  24.             set
  25.             {
  26.                 ViewState["RatingField"] = value;
  27.             }
  28.         }
  29.  
  30.  
  31.         [Bindable(true)]
  32.         [Category("Binding")]
  33.         [DefaultValue("")]
  34.         [Localizable(true)]
  35.         public int ListItemId
  36.         {
  37.             get
  38.             {
  39.                 return Convert.ToInt32(ViewState["ListItemId"]);
  40.             }
  41.  
  42.             set
  43.             {
  44.                 ViewState["ListItemId"] = value;
  45.             }
  46.         }
  47.  
  48.  
  49.         [Bindable(true)]
  50.         [Category("Binding")]
  51.         [DefaultValue("")]
  52.         [Localizable(true)]
  53.         public Guid ListId
  54.         {
  55.             get
  56.             {
  57.                 Guid id = (Guid)ViewState["ListId"];
  58.                 return id;
  59.             }
  60.  
  61.             set
  62.             {
  63.                 ViewState["ListId"] = value;
  64.             }
  65.         }
  66.  
  67.         protected override void CreateChildControls()
  68.         {
  69.  
  70.             if (this.ChildControlsCreated)
  71.                 return;
  72.  
  73.             
  74.             BaseFieldControl renderingcontrol = this.RatingField.FieldRenderingControl;
  75.             renderingcontrol.ControlMode = SPControlMode.Display;
  76.             renderingcontrol.ListId = this.ListId;
  77.             renderingcontrol.ItemId = this.ListItemId;
  78.             Controls.Add(renderingcontrol);
  79.             this.ChildControlsCreated = true;
  80.            
  81.            
  82.             
  83.        }

Next, after adding a new template column to the datagrid containing a place holder (DataGrid source), then binding the data source to the ListItemCollection returned. 

DataGrid Source
  1. <asp:TemplateColumn>
  2.          <HeaderTemplate>
  3.                 Rating
  4.             </HeaderTemplate>
  5.             <ItemTemplate>
  6.                 <asp:PlaceHolder runat="server" ID="RatingPlaceHolder"></asp:PlaceHolder>
  7.             </ItemTemplate>
  8.         </asp:TemplateColumn>

 

I create a new instance  of the rating control on the girdview OnItemDataBound event receiver and add it to the place holder.

OnItemDataBound
  1. protected void SearchResultsGridView_OnItemDataBound(object sender, DataGridItemEventArgs e)
  2.      {
  3.          if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  4.          {
  5.              Label lastModifiedLabel = (Label)e.Item.FindControl("LastModifiedLabel");
  6.              lastModifiedLabel.Text = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "ModifiedDate")).ToString("dd-MMM-yyyy");
  7.              PlaceHolder placeHolder = (PlaceHolder)e.Item.FindControl("RatingPlaceHolder");
  8.              ratingControl = new RatingControl();
  9.              ratingControl.RatingField = (SPField)DataBinder.Eval(e.Item.DataItem, "RatingField");
  10.              ratingControl.ListId = (Guid)DataBinder.Eval(e.Item.DataItem, "ListId");
  11.              ratingControl.ListItemId = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "Id"));
  12.              placeHolder.Controls.Add(ratingControl);
  13.          }
  14.     }

Job Done!

I just like to start by saying that this post is not ground breaking. However, when I tried to do this it did take me a while to find the answer, so I thought I’d just blog to add it to the grey matter.

As I’m sure you are all aware you can provision multiple files with preconfigured web parts by using a SharePoint module’s element file and a web part page as a template, by targeting the web part zones on the web part page.

However, trying to connect these caused me a bit of problems. In the end though it was quite straight forward. And can be done by specifying the following attributes in the code snippets and the descriptions given in the table below.

WebPartConnection
  1. <WebPartConnection ConsumerConnectionPointID="MediaSearchConsumer" ConsumerID="MediaResultsWebPart"
  2.                          ProviderConnectionPointID="MediaSearchProvider" ProviderID="MediaSearchWebPart" ID="MediaSearchConnector"/>

Web Part Consumer
  1.       <AllUsersWebPart WebPartZoneID="MiddleZone2" WebPartOrder="0" ID="MediaResultsWebPart">
  2.         <![CDATA[<?xml version="1.0" encoding="utf-8"?>
  3. <webParts>
  4.   <webPart xmlns="http://schemas.microsoft.com/WebPart/v3"&gt;
  5.     <metaData>
  6.       <type name="Instalec.SharePoint.WebParts.MediaResultsWebPart.MediaResultsWebPart, Instalec.SharePoint.WebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9e5b38b443f03fff" />
  7.       <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
  8.     </metaData>
  9.     <data>
  10.       <properties>
  11.         <property name="Title" type="string">Media Search Results</property>
  12.         <property name="Description" type="string">Web part to display the results from the media search</property>
  13.          <property name="Hidden" type="bool">True</property>
  14.           <property name="AllowHide" type="bool">True</property>
  15.       </properties>
  16.     </data>
  17.   </webPart>
  18. </webParts>
  19. ]]>
  20.       </AllUsersWebPart>

Web Part Provider
  1.     <AllUsersWebPart WebPartOrder="1" WebPartZoneID="MiddleZone" ID="MediaSearchWebPart">
  2.             <![CDATA[<webParts>
  3.   <webPart xmlns="http://schemas.microsoft.com/WebPart/v3"&gt;
  4.     <metaData>
  5.       <type name="Instalec.SharePoint.WebParts.MediaSearchWebPart.MediaSearchWebPart, Instalec.SharePoint.WebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9e5b38b443f03fff" />
  6.       <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
  7.     </metaData>
  8.     <data>
  9.       <properties>
  10.         <property name="Title" type="string">Media Search</property>
  11.         <property name="Description" type="string">My Visual WebPart</property>
  12.       </properties>
  13.     </data>
  14.   </webPart>
  15. </webParts>
  16. ]]>
  17.         </AllUsersWebPart>

Connection Consumer Attribute
  1. [ConnectionConsumer("The Search Criteria", "MediaSearchConsumer")]
  2.         public void IMediaSearchConsumer(IMediaSearch mediaSearch)

Connection Provider
  1. [ConnectionProvider("The Search Criteria", "MediaSearchProvider")]
  2.      public IMediaSearch IMediaSearchProvider()
  3.      {
  4.          return this;
  5.      }

 

ConsumerID ID specified in the AllUserWebPart element as seen in the Web Part Consumer above
ConsumerConnectionPointID The ID of the ConnectionConsumerAttribute seen above
ProviderID ID specified in the AllUserWebPart element as seen in the Web Part Provider above
ProviderConnectionPointID The ID of the ConnectionProviderAttribute seen
above
ID This can be any value but will not work without it

Job done… Smile

Okay, before anyone comments on the simplicity of this posting. It merely t allow me to get the script easily in the future.  What’s the purpose of it? It basically retracts a solution and waits until its fully retracted, then deletes it, adds it in again and redeploys it. Not rocket science, but handy. 

#Set up Web Application variable
#Only needed if solution contains Web Application scoped resources

$webApp = "
http://sitetodeployto"

#Set up solution name variable
$solutionName =  "solution.wsp"

#Set up solution file path variable
$filePath = "C:\Deploy51011\" + $solutionName

#Uninstall solution
#Add -WebApplication $webApp if solution contains Web Application scoped resources

Uninstall-SPSolution –Identity $solutionName –WebApplication $webApp  -Confirm:$false

#set up a variable for the solution to allow access to properties
$solution = Get-SPSolution $solutionName

#Wait for solution to be uninstalled
do {Start-Sleep -s 1} while ($solution.Deployed -eq $true)

# add another couple of seconds
Start-Sleep -s 2

#Remove solution from the farm without prompting
Remove-SPSolution $solutionName -Confirm:$false

# add it back in and deploy it
Add-SPSolution –LiteralPath $filePath
Install-SPSolution –Identity $solutionName –WebApplication $webApp –GACDeployment

Hope this saves someone some time Winking smile

After receiving several DCOM error in Event Viewer about permission on various object I decided to amend the  Launch and Activation Permissions of the Key in question. I this case it was IIS Admin Service with the Key {A9E69610-B80D-11D0-B9B9-00A0C922E750} and  IIS WAMREG admin Service with the key {61738644-F196-11D0-9953-00C04FD919C1}. However, when I tried to amend I found that all the properties were disabled as seen below

image

After some Google-ing, I found that there were a couple of registry keys forcing this read-only state.

HKEY_CLASSES_ROOT\AppID\{A9E69610-B80D-11D0-B9B9-00A0C922E750}

HKEY_CLASSES_ROOT\AppID\{61738644-F196-11D0-9953-00C04FD919C1}

To change this – right click on the key and choose advanced, and replace the owner as the administrators group

image

The once this has been done change the administrator’s permissions to full control.

image

Now re-launch the component service and you should now be able to edit the values

I received the above error while trying to install Cisco’s VPN x64 client on my laptop.

 

VPNIntall-error.png

 

After some investigation it turns out this error is caused by default value set by Windows 7 in the registry key

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\MaxNumFilters

By default, this value is set to 8 and apparently can be set to a maximum value of 14. As some of the filters were used by Virtual Box, etc. I decided to set this to the maximum, rebooted and, hey presto, it installed!!