Category Archives: SharePoint Development

One Reason for “One or more field types are not installed properly”

I was making a small tweak yesterday to a web part that does a CAML query against a list.  I made the change, deployed it and got hit with an error:

An unexpected error has occurred in the Three Day Outlook Weather Forecast WebPart. Please contact the system administrator. One or more field types are not installed properly. Go to the list settings page to delete these fields.

I was facing another oddball issue earlier so I didn’t immediately connect my CAML query with the error that SharePoint was reporting to me.  I did a quick bing search and and found this helpful blog post by Sandeep Nahta  (http://snahta.blogspot.com/2009/01/one-or-more-field-types-are-not.html).

Here is the bad query:

query.Query += "<Where><And><Neq><FieldRef Name=’Abbr’/><Value Type=’Text’>SFNY</Value><FieldRef Name=’Abbr’/><Value Type=’Text’>SFIS</Value></Neq></And></Where>";

Here it is fixed:

query.Query += "<Where><And><Neq><FieldRef Name=’Abbr’/><Value Type=’Text’>SFNY</Value></Neq><Neq><FieldRef Name=’Abbr’/><Value Type=’Text’>SFIS</Value></Neq></And></Where>";

So, the moral of the story is: make sure your CAML is correct or you may get an oddball error.

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

</end>

SharePoint 2010 Solution Stuck in “Deploying” Status

I used PowerShell to deploy a solution to a SharePoint farm (h/t:  Corey Roth and his blog post). 

I then went to the central admin, accessed System Settings and then “Manage farm solutions” to deploy it to the farm and to my (slight) dismay, it got stuck in “deploying”.

I’ve seen this issue come up many times on the MSDN forums, so I was pretty nervous about it.  I searched around a bit and found this helpful article (by a seemingly unattributed person from http://www.resolutionsnet.co.uk/).  I cancelled the deployment job and when I clicked into the solution, it told me that it had successfully deployed the solution to three of the four servers in the farm.

I went to the errant server, stopped the timer service and restarted it.  Windows server actually told me that the service failed to respond to the command, so that tells me that it was sick.

This time, when I went back to central admin, I was able to deploy it with no problem.

Hopefully this bit of info will help some in a bind one of the days.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Error of the Day: “Cannot Add the Specified Assembly to the GAC”

I’ve been fighting a bit with visual studio 2010 on a an sp2010 solution and was getting this error:

Error occurred in deployment step ‘Add Solution’: Error: Cannot add the specified assembly to the global assembly cache: YourAwesomeDLLThat IAmJustNotGoingToInstallRightNow.dll

I went to the GAC itself (c:\windows\assembly) to try and remove and got a “file in use” error.

I did an iisreset, I almost downloaded sysinternals, I stopped the timer service in services… finally, I just closed and reopened visual studio itself and I was finally able to close it out.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Quick and Easy: Debugging VS 2010 Solution Deployment

Visual Studio 2010 reports hard-to-debug errors during deployment some times.  A quick and easy way to do some very rough debugging is to throw your own named exceptions.  Visual Studio will show them in the output console.

Consider this bit of code:

image

If this feature is scoped to a web application, site will be null.  If you try and reference a property of site, you’ll get the ambiguous error:

Error occurred in deployment step ‘Add Solution’: Object reference not set to an instance of an object.

However, if throw a new Exception and pass a string to the constructor, you get a slightly more useful message:

image

It’s a crude technique, but pretty fast and easy.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Timer Job FeatureActivated And Feature Scope

I’ve been working with some code that someone handed to me for a timer job.  He hadn’t provided the actual feature activation code so I had to write it, of course.  I took advantage of Andrew Connell’s famous blog post on the subject.

I’m using Visual Studio 2010 and deployment kept failing with an error “Error occurred in deployment step ‘Add Solution’: Object reference not set to an instance of an object.”

I was taking his code too literally.  I was scoping the feature to the web application level, as shown:

image

As a result, the properties that are sent to the receiver are from the web application, not a site collection.  In the end, the code looks like this:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{

    // Don’t do the following with web app scoped features, it leads to despair Smile
    // SPSite site = properties.Feature.Parent as SPSite;

    SPWebApplication wa = properties.Feature.Parent as SPWebApplication;

    if (wa == null) throw new Exception("webapp2 is null.");

    foreach (SPJobDefinition job in wa.JobDefinitions)
    {

        try
        {
            if (job.Name == List_JOB_NAME)

                job.Delete();
        }
        catch (Exception e)
        {
            throw new Exception("marker 2");
        } // catch exception e
    }

    // install the job

    WeatherForecastTimerJob weatherForecastTimerJob =
        new WeatherForecastTimerJob(List_JOB_NAME, wa);

    SPMinuteSchedule schedule = new SPMinuteSchedule();
    schedule.BeginSecond = 0;
    schedule.EndSecond = 59;
    schedule.Interval = 5;
    weatherForecastTimerJob.Schedule = schedule;
    weatherForecastTimerJob.Update();

}

The key take-away is that when the feature is scoped to a web app, the SPFeatureReceiverProperties that SharePoint passes to your feature receiver has web app level parameters.  Andrew’s old blog entry assumes it’s scoped to the site collection.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Where is Microsoft.SharePoint.ApplicationPages.Administration.dll?

I was handed a visual studio project that references Microsoft.SharePoint.ApplicationPages.Administration.dll.  It took me a little while to find it and I thought I’d share.  In my environment, it’s located at:

c:\program files\common files\microsoft shared\web server extensions\14\config\adminbin

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

CodePlex Project – SP2010 Explorer

As part of an on-going effort to learn the technical low level details of SharePoint 2010, I’ve created a “SharePoint Explorer” kind of tool.  The idea isn’t new.  I used this project more than once: http://sharepointexplorer.codeplex.com/.  My idea is to create a SharePoint version that uses connected web parts to show all the low-level detail that the object model can provide. 

This blog post serves as both an announcement of the project as well as a call for volunteers.  If you’re interested in working on this project, let me know via email (galvin.paul@gmail.com) and we’ll work it out.

Here is the project: http://sp2010explorer.codeplex.com/

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Working With TreeNodeBinding in the ASP.NET Treeview Control

I’ve been working on what I hope will be a soon-released CodePlex project that provides a nice integrated bit of web parts talking to each other via provider/consumer connections for the purpose of exploring a SharePoint site under the covers.  (This has certainly been done before, but this is a learning project as much as anything else).  This is meant to be a replacement for the windows explorer view of SharePoint 2010 document libraries.

The code has the usual recursive call down the SPWeb’s and SPLists from a given starting point.  The object that does all that traversing builds up an XML string that looks something like this:

<sitecollection url=’http://demo2010a:9090′>
 
<web
     title=’Hello World Sandbox’ 
     Template=’A site for teams to quickly organize, author, and share information, BLAH BLAH BLAH’>

     <list
        title=’BCC_Health_Services_FAQs’
        Template=’CustomList’
       
listid=’http://demo2010a:9090/helloworldsandbox[delim]1e02b001-3cb2-4f17-b63d-7809e86b4174′>
    
</list>

     <list
        title=’BCC_Notifications’ 
        Template=’CustomList’ 
        listid=’
http://demo2010a:9090/helloworldsandbox[delim]5a5a13d1-877c-41c0-9063-b9612be80d5e’>
     </list>

  </web>

</sitecollection>

I expect to clean up that XML before all is said and done.

I want to ultimately get that information up and into a Treeview control.  Not exactly earth shattering stuff.

The challenge I took on here was to connect the tree view to an XML Data Source control instead of manually building up my treenodes as I traverse the tree.  I did this partly because I’m deliberately making things harder on myself (this is a learning project after all) and partly because I have this vague notion that building up tree nodes as I traverse the tree isn’t a good idea for the long term.

The problem with this approach is that the Treeview control doesn’t know about the good attributes on the interesting nodes like “list” or “web” so it shows this output by default:

 

image

That’s not useful.  This is where the TreeNodeBinding class helps.  I can use this to tell the Treeview control how it should interpret the XML.  Here’s an example:

tnb = new TreeNodeBinding();
tnb.DataMember = "list"; // This is the label in the xml for a site.
tnb.TargetField = "listid";
tnb.ValueField = "title";
tnb.ToolTipField = "Template";

This binding tells the treeview that when it finds a <list> node in the XML, apply the bindings for TargetField, ValueField and ToolTipField.  In may app, these map as follows:

  • TargetField: When someone clicks on a node value, this is what you’ll get for SelectedNode.Value.  This is not to be confused with…
  • ValueField: This is what you want the Treeview to display to the user.
  • ToolTipField: The value from the XML that you want as a Tooltip.

Add that TreeNodebinding to the tree view’s DataBindings and you get output like this:

 

image

I’ll have more on all this as I continue on the project and eventually put this up on Codeplex.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Connecting Text Field Filters to Your Custom Web Part

I wanted to receive information from a Text Field filter in SharePoint 2010 into my custom web part.  I tried using this MSDN article as a basis but the article is either broken or I’m just not following it correctly.

A little more searching turned up Mike Smith’s MSDN contribution here (http://social.msdn.microsoft.com/forums/en-us/sharepointdevelopment/thread/72F1732A-7F93-441E-8644-2E82BBB153D9).

There’s a lot of stuff out there on connectable web parts but Mike’s article is as simple as it gets.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Quick and Easy: Send Email Using Gmail SMTP Server in .NET C#

This isn’t exactly a new topic, but when I needed to do it, I found a lot of “why won’t this work for me” and not too many direct answers.  I hope someone finds this useful.

The following bit of code will send an email using my own gmail account to do it, including attachments:

using System.Net.Mail;
using System.Net;

NetworkCredential loginInfo = new NetworkCredential("[My Gmail ID]", "[My Gmail Password]");
MailMessage msg = new MailMessage();
msg.From = new MailAddress("[M Gmail Id]@gmail.com");
msg.To.Add(new MailAddress("paul.galvin@arcovis.com"));
msg.Subject = "Test infopath dev subject";
msg.Body = "<html><body><strong>A strong message.</strong></body></html>";
msg.IsBodyHtml = true;

foreach (string aFile in NIPFD.GetAttachmentNamesAndLocations())
{
    msg.Attachments.Add(new Attachment(aFile));
} // Adding attachments.

SmtpClient client = new SmtpClient("smtp.gmail.com");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Port = 587;
client.EnableSsl = true;
client.Send(msg);

 

A few key bits that slowed me down and other observations / notes:

  • The first line that creates the loginInfo object needs to use the gmail ID stripped of “@gmail.com”.  So, if my gmail email address is “sharepoint@gmail.com” and my password is “xyzzy” then the line would look like:

NetworkCredential loginInfo = new NetworkCredential("sharepoint", "xyzzy");

  • My gmail account is set up to use SSL and that wasn’t a problem.
  • There is some conflicting information out there on what port to use.  I used port 587 and it worked fine for me.
  • In my case, I also needed to send attachments.  That NIPFD object has a method that knows where my attachments are.  It’s returning a fully path (e.g. “c:\temp\attachment1.jpg”.  In my test, I had two attachments and they both worked fine.

I used visual studio 2008 to write this code.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Technorati Tags: ,,,