Geeks With Blogs
Hammer Blog Sharing lessons learned

Just solved a problem, and wanted to document the solution.

Problem:

SharePoint MOSS 2007 Central Administrations site.  Select Application Management --> InfoPath Forms Services --> Manage form templates.

This runs the page _admin/ManageFormTemplates.aspx

Response is the ever-helpful SharePoint screen:  Error.  Unknown Error.

Thanks, guys.  How do I turn on custom errors in SharePoint?

And how do I get Manage form templates to work?

Disclaimer

`No warrantees, express or implied, are granted with this information.  Please note that this information is FREE and me being nice enough to give it to you does not mean that you should do anything with it, and that it won't do anything horrible to your systems.  Above all, I'm not liable for what you choose to do with it. 

As a matter of fact, THIS INFORMATION HAS THE CAPABILITY OF RUINING YOUR INFRASTRUCTURE AND COSTING YOU UNTOLD MAN-HOURS, MONEY, AND DOWNTIME.  APPROACH WITH CAUTION.

Your continued reading is evidence of your acceptance of this risk, and your agreement that I have nothing to do with whatever problems you might have.

Solution:

To get useful errors in MOSS is not as easily as .NET, but the answer is out there.  Here it is in an easier format.

Find the web.config for the site experiencing the issue (in this, case, the Central Administration site.)

If you're not sure where that is, IIS Manager --> <server> --> Web Sites --> Right-click <Web Site> --> Properties --> Home Directory tab --> Local Path.  Copy and paste that string into the address bar of Windows Explorer.

Edit web.config in a text editor (preferably Notepad).

Set <SafeMode ... CallStack="false" ...> to CallStack="true".

Set <customErrors mode="On" /> to mode="Off".  (This is the .NET way to turn on stack trace information.)  If this is a production system, you should set customErrors mode="RemoteOnly" and troubleshoot from the web server console.

Set <compilation batch="false" debug="false"> to <compilation batch="true" debug="true">

Save your file.  (Make sure the editor didn't add a .txt extension or something stupid.)

Now you'll get an error message that actually means something.

In my case, it returned the following error:

Object reference not set to an instance of an object.   at Microsoft.Office.InfoPath.Server.Administration.FormTemplate.SolutionDeploymentFailed()
   at Microsoft.Office.InfoPath.Server.Administration.FormTemplate.get_FormTemplateStatus()
   at Microsoft.Office.InfoPath.Server.ApplicationPages.FormTemplatePropertiesPage.GetStatusString(FormTemplate template)
   at Microsoft.Office.InfoPath.Server.ApplicationPages.ManageFormTemplatesPage.AddTemplateToTable(FormTemplate template, DataTable table, SPWeb web)
   at Microsoft.Office.InfoPath.Server.ApplicationPages.ManageFormTemplatesPage.FillDataTable(DataTable table)
   at Microsoft.Office.InfoPath.Server.ApplicationPages.GridViewPageBase.GridViewDataSourceView.FillDataTable(DataTable table, DataSourceSelectArguments selectArguments)
   at Microsoft.Office.InfoPath.Server.ApplicationPages.GridViewPageBase.GridViewDataSourceView.Select(DataSourceSelectArguments selectArguments)
   at Microsoft.SharePoint.WebControls.AdministrationDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)
   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
   at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
   at System.Web.UI.WebControls.GridView.DataBind()
   at Microsoft.Office.InfoPath.Server.ApplicationPages.GridViewPageBase.RefreshDataGrid()
   at Microsoft.Office.InfoPath.Server.ApplicationPages.ManageFormTemplatesPage.OnPreRender(EventArgs e)
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Troubleshoot issues with Windows SharePoint Services.

 I tried a bunch of things, but nothing worked.  My partner (development-oriented) and I suspected that a database record in the list of published InfoPath forms had a null where it shouldn't be, but we couldn't figure out how to find the bad record.  (Where does SharePoint store the darn thing?)

Well, he wrote up a script which uses imbedded SharePoint code (installed dll's) to get at the forms record, since we never could find the actual record in the database manually.

WARNING!!!  This script is capable of deleting all of your installed InfoPath forms, as well as all associated workflows!!  Do not run it unless you understand what each line is doing!

Private Function GetFSService() As FormsService
        Dim Farm As SPFarm
        Dim FS As New FormsService
        Farm = SPFarm.Open("Data Source=<DataSource>;Initial Catalog=<SharePoint Config DB>;Integrated Security=True")

        Try
            FS = Farm.Servers.GetValue(Of FormsService)(FormsService.ServiceName)
            For Each frm As FormTemplate In FS.FormTemplates
                frm.FormTemplateStatus.ToString()
                'for each St as Microsoft.SharePoint.SPSite in farm.
                'frm.Delete()
                'Next
            Next
        Catch ex As Exception
            'ERROR
        End Try
    End Function

Ok, have you been warned enough?  See that remarked little frm.delete?  That tells the system to delete all your stuff.  Bad.  What my partner did was to unremark the delete command and run the script within VB Studio in debug mode, so he could step through it one line at a time.  When it found the first record, he told it to delete the record, then checked the site again.  Lucky for us, the record with the null field was the first one in the database.  After that was deleted, everything was sunshine, lollipops, and roses again.

So there you go.  I doubt you'll hit the same problem as I did; I didn't find any fellow victims on Google.  But the methodology for turning off the custom error is darn useful.  Thanks to Andrew Connell and Anders Rask.

-Tom Kretzmer

Posted on Friday, December 7, 2007 10:32 AM | Back to top


Comments on this post: Unable to manage form templates

# re: Unable to manage form templates
Requesting Gravatar...
Thanks Tom for posting this. This is very helpful..
I ran into exact same issue.

But can you please post the entire code instead of just the Function.

This function doesn't compile and run.. what all references do i have to add
Left by Ankur on Dec 12, 2007 4:33 PM

# re: Unable to manage form templates
Requesting Gravatar...
As I mentioned in the article, if you can't use this, you shouldn't run it; it'll delete all your form templates. You have to call the FormTemplate Class within the Microsoft.Office.InfoPath.Server.Administration namespace of microsoft.office.infopath.server.dll. It's not the kind of thing you just compile and run. Personally, I don't know how to actually do this; my partner came up with it. Try this link for additional info: http://msdn2.microsoft.com/en-us/library/microsoft.office.infopath.server.administration.formtemplate.aspx

Glad that you took the time to comment; hope this helps!

-Tom
Left by Tom on Dec 14, 2007 2:36 PM

# re: Unable to manage form templates
Requesting Gravatar...
Further information from my partner:

<quote>
You need to copy the code into a class in visual studio and run it in debug to step through the code to find the form template with the error then reposition the running code pointer to the delete statement to remove the form template causing the error.
</quote>

Hope that helps - all of my coding is done in Notepad.
Left by Tom Kretzmer on Dec 14, 2007 3:59 PM

# re: Unable to manage form templates
Requesting Gravatar...
I encountered the issue when the solution no longer exists in the farm (Operations-> Solution Management). See if you can see a solution matching your form there. If the report is deployed and the solution is removed, the ManageFormTemplates.aspx page blows up. Nice. What to do if you are in this boat?

What I did was:
1) Open the form in InfoPath design mode.
2) From the File menu, choose properties
3) Copy the form id
4) On the SharePoint server execute the following statement in a command window: stsadm -o removeformtemplate -formid <enter copied id here>

The response from the server was:
The form template has been successfully initiated for removal from the farm.

Tried to access the ManageFormTemplates.aspx page and all was right in the world.

This was not a fun error to track down at all...
Left by Phil on Feb 28, 2008 3:37 PM

# re: Unable to manage form templates
Requesting Gravatar...
Tom I really wanna thank you for this great article
I encountered same problem when i deleted the solution before the form template
I write windows application and add two references
1- C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.SharePoint.dll
2- C:\Program Files\Microsoft Office Servers\12.0\Bin\Microsoft.Office.InfoPath.Server.dll
and here is the whole code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.InfoPath.Server.Administration;

namespace ManageFormTemplatesFix
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SPFarm Farm = SPFarm.Local;
FormsService FS = new FormsService();
try
{
FS = Farm.Servers.GetValue<FormsService>(FormsService.ServiceName);
foreach (FormTemplate frm in FS.FormTemplates)
{
// here you get the form template whiich cause the problem by uncomment the line below and put breakpoint
//frm.FormTemplateStatus.ToString();
// then you put its name of your formTemplate instead of TempForm[2]and comment the abbove line
if (frm.DisplayName == "TempForm[2]")
{
frm.Delete();
}
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message);
}

}
}
}
Left by Osama Naeem on Mar 03, 2008 8:32 PM

# re: Unable to manage form templates
Requesting Gravatar...
Following Osama Naeem's C# solution - I am trying to run the program remotely, but am having SQL connection problems.

I am trying

"SPFarm Farm = SPFarm.Open("Data Source=MACHINENAME;Initial Catalog=MOSSSQL;User Id=DOMAIN\\admin;Password=#############");"

instead of the line

"SPFarm Farm = SPFarm.Local;"

What should the initial catalogue be? The Central Admin one or the SharePoint one? Connecting remotely do I need extra parameters in my connection string? I'm familiar with C# and Central Admin but not SQL and the guy I work with who knows is on holiday for a while!

Also, I followed Phil's advice and removed my form template using the command line but it did not fix the issue and my events log is full of errors saying

"Value cannot be null.
Parameter name: userName"

My debug error for ManageFormTemplates is exactly the same as Tom Kretzmer's

Any help I can get would be greately appreciated
Left by John Speak on Apr 04, 2008 5:57 AM

# re: Unable to manage form templates
Requesting Gravatar...
I was checking out the references to this piece, and found a good tidbit at http://www.infopathdev.com/forums/t/7571.aspx. Thank you, zeroecho.

This methodology uses the fact you still have access to the file system of the web server, even if you don't know the record number of the bad record, nor the fileid of the form. You may know the creation date of the bad record, in which case you can take advantage of the following:

stsadm.exe -o RemoveFormTemplate -filename <location>\<filename.xsn>

followed by stsadm.exe -o Execadmsvcjobs

zeroecho also had trouble with content types - not sure about that myself.

If you don't know where the location is, do a search on *.xsn of the SharePoint web server. The default is C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\<ID of feature>. The ID of the feature could look like a GUID, so look around.

Good luck.
Left by Tom Kretzmer on May 28, 2008 1:52 PM

# re: Unable to manage form templates
Requesting Gravatar...
I took the liberty to add a checkedListbox and a delete button to your fine solution.

Here's the Form1.cs:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.InfoPath.Server.Administration;
using System.Linq;

namespace ManageFormInfopathFix
{
public partial class Form1 : Form
{
public int i = 0;
public SPFarm Farm = SPFarm.Local;
public FormsService FS = new FormsService();

public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
i++;
checkedListBox1.Items.Clear();
listBox1.Items.Clear();

try
{
i++;
FS = Farm.Servers.GetValue<FormsService>(FormsService.ServiceName);
i = 100;
foreach (FormTemplate frm in FS.FormTemplates)
{
string myItem = "";
string myStatus = "";
i++;
myItem = frm.DisplayName;
i++;
try
{
myStatus = frm.FormTemplateStatus.ToString();
}
catch
{
myStatus = "FAILED";
}
checkedListBox1.Items.Add(myItem);
listBox1.Items.Add(myStatus);
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message + " i=" + i.ToString());
}

}

private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "Delete started...";
for (int j = 0; j < checkedListBox1.CheckedItems.Count; j++)
{
textBox1.Text = textBox1.Text + "\r\n" + "ItemChecked: " + checkedListBox1.CheckedItems[j].ToString();
try
{
FS = Farm.Servers.GetValue<FormsService>(FormsService.ServiceName);
i = 200;
foreach (FormTemplate frm in FS.FormTemplates)
{
i++;
if (frm.DisplayName == checkedListBox1.CheckedItems[j].ToString())
{
textBox1.Text = textBox1.Text + "\r\n" + "Deleting " + frm.DisplayName;
frm.Delete();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + " i=" + i.ToString());
}
}
textBox1.Text = textBox1.Text + "\r\n" + "Delete ended... ";
}

private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
listBox1.SelectedIndex = checkedListBox1.SelectedIndex;
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
checkedListBox1.SelectedIndex = listBox1.SelectedIndex;
}
}
}

You'll need a checkedListBox1 (Forms), a listBox1 (FormStatus) rigth next to it and a button1 (Start) and button2 (Delete) and a textBox1 (Status) with multiline and scrollbars enabled.

Enjoy, Jesper Simonsen
Left by Jesper Simonsen on Sep 16, 2008 7:23 AM

# re: Unable to manage form templates
Requesting Gravatar...
I've also just extended this further by using PowerShell to make the adjustment which is sometimes a lot easier than deploying an exe to a server if it's installed. Check it out.
http://wss.made4the.net/archive/2008/10/28/infopath-form-services-manage-form-templates-stuck-on-installing.aspx
Left by Jeremy Thake on Oct 28, 2008 9:08 AM

# re: Unable to manage form templates
Requesting Gravatar...
Jesper, thank you so much!

your code works fine!
Left by Miguel Ballesteros on Apr 04, 2009 12:44 AM

# re: Unable to manage form templates
Requesting Gravatar...
Just wanted to say thanks to those who have added additional information and pointers. :)
Left by Tom Kretzmer on Sep 17, 2009 7:17 AM

# Great News
Requesting Gravatar...
You are a very smart person!
Left by Reebradub on Oct 11, 2009 2:55 PM

# re: Unable to manage form templates
Requesting Gravatar...
You are LIFESAVERS!!!!!!!!!
This is a very definitive solution.

Thanks.
Left by Gee & Kay! on Dec 31, 2009 8:12 AM

# re: Unable to manage form templates
Requesting Gravatar...
My good Jesper, this is more than a million rabbits! Mange tak!
Left by 0baz on Jan 18, 2010 7:06 AM

# re: Unable to manage form templates
Requesting Gravatar...
Code in Windows Form was brilliant! Kudos!
Left by Dennis on Feb 09, 2010 11:43 PM

# re: Unable to manage form templates
Requesting Gravatar...
Thank you for the solution to this problem - the program worked great.
Left by Gary Bleads on Mar 12, 2010 7:50 AM

# re: Unable to manage form templates
Requesting Gravatar...
Hi,
You don't need to do it from code.
You can simply run an stsadm command.
You can see my post:
http://ajaxme.blogspot.com/2010/07/you-got-unknown-error-when-accessing.html
Left by Eran Hefer on Jul 22, 2010 12:46 AM

# re: Unable to manage form templates
Requesting Gravatar...
I solved this problem. Here is what I did:

Step 1: Ran stsadm -o enumformtemplates > c:\formlist.txt to output all the InfoPath form templates uploaded in SharePoint Central Administration

Step 2: Due to the fact that I didn’t know which of the form templates is generating the issue I had to delete them all, one by one, by executing the following command:
a. stsadm -o removeformtemplate -formid <enter id here> (eg: urn:schemas-microsoft-com:office:infopath:T02-DM-V4-FINAL:-myXSD-2008-07-11T19-40-02)
b. I got the following error while trying to remove some form templates: "this form template was deployed as part of the FT-01-65a1d9ae-868d-f975-ddce-cacf6e4d703d feature. This form template should be removed only by uninstalling that feature."
c. To solve this error then I removed the solution also. So I had to execute: stsadm -o uninstallfeature -id <idoffeature> -force (e.g.: stsadm -o uninstallfeature -id f97dd99b-7ea7-1c56-25e5-eddf7ff6099 -force)
In order to determine the id, I navigated to the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\FT-01-f97dd99b-7ea7-1c56-25e5-eddf7ff6099b and locate the feature.xml file. The id will be located inside of this file.
Here we should find something like Feature Id="50d541c7-d5f4-fa2c-8449-7f3e4e6eaebe" so this is the id we need to use for the stsadm command

After I removed one InfoPath form I performed an iisreset and try to open the Manage InfoPath forms page. This way I did refresh the page after removing each form and after removing one particular form the Manage Forms page came up without any error. The form I removed last before the page came up without any error was deployed 2 years back. From this I have to conclude that there was some issue with this forms deployment or some timer job that was supposed to activate or deploy this form was stuck.
Left by manoj on Jul 29, 2010 12:12 PM

# re: Unable to manage form templates
Requesting Gravatar...
Kudos Jesper, excellent piece of code!
Left by devshedeu on Mar 29, 2011 9:30 AM

Your comment:
 (will show your gravatar)


Copyright © Tom Kretzmer | Powered by: GeeksWithBlogs.net