1

I've come across a SharePoint problem that I hope someone can help with. Basically, when I am trying to add a column called "MigratedChemist" to a list called "WorkCards" (pListName in the method parameters). No matter what I try I am getting a FaultException error raised when calling UpdateList. I am connecting using the SharePoint web service. I have confirmed the following:

  1. The column doesn't already exist and I do have permissions to create it in SharePoint
  2. The connection to SharePoint is established corectly to /_vti_bin/lists.asmx
  3. The list name is correct as I have another method which returns items from the list and that works perfectly.
  4. The xVersion and xId values are set correctly when the program runs and passed as parameters - as far as I am concerned I should just be able to pass the list name, as opposed to the GUID, but neither method works.

My code is as follows:

public static bool AddColumnToList(string pUri, string pListName, string pViewName, string pMaxRecords)
    {

        string version = string.Empty;
        XAttribute xId = null;
        XAttribute xVersion = null;

        try
        {
            XElement listDetails = client.GetList(pListName);
            xVersion = listDetails.Attribute("Version");
            xId = listDetails.Attribute("ID");
        }
        catch { throw; }

        XElement ndNewFields = new XElement ("Fields", "");
        string newXml = "<Method ID='1' Cmd='New'><Field Name='MigratedChemist' Type='Text' DisplayName='MigratedChemist' /></Method></Fields>";

        ndNewFields.Add(newXml);

        XElement result;

        try
        {
            result = client.UpdateList(xId.Value, null, ndNewFields, null, null, xVersion.Value);
        }
        catch (FaultException fe)
        {
        }


        return true;
    }

In addition to this does anyone know how to get any decent information from FaultRequest? At the moment I get the following error message, which is of no use and there appears to be no extra detail. I have tried, as some have suggested removing the error handling and letting the program halt, but that doesn't give me any extra information either.

{"Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."}

5
  • The SoapServerException should have an InnerException. Other than that, your new entry should have values in it, no? And is MigratedChemist the only thing that needs to be assigned? Also, why don't you just use client.UpdateListItems(pListName, ndNewFields)? Commented May 23, 2013 at 13:58
  • InnerException is null....I don't want to set a value for it because it is a new column in the list, not a new list item if that makes sense. The new column will be a different value dependng on which list item it refers to. Commented May 23, 2013 at 14:00
  • Could you add the table view with the columns (and their properties) in your question? P.S. I also edited my comment above, please check. Commented May 23, 2013 at 14:01
  • Same result with UpdateListItems. I'm not sure what you mean by table view - the list currently has 30 or so columns in and this is one is an addition to that. Commented May 23, 2013 at 14:04
  • Oh, I thought you were trying to add a row, not a column. I've never actually tried adding a new column, sorry Commented May 23, 2013 at 14:08

1 Answer 1

1

For future reference I have solved both the problem of the SharePoint update failing AND the FaultException problem, so am including it here for posterity:

Problem 1 - Problem with UpdateList

This problem was caused because my XML was malformed. When I called ndNewFields.Add(newXml) then XML that was being returned was replacing < and > than with control characters, as shown below (I have added an extra space because this editor converts them automatically.

<Method ID="1" Cmd="New"&gt ;&lt ;Field Name="MigratedChemist"&gt ;&lt ;/Field&gt ;&lt ;/Method&gt ;

Now, I did notice this pretty early on but wasn't sure whether it would cause a problem or not. However using the XElement.Parse command I was able to remove these characters and this resolved the problem:

ndNewFields.Add(XElement.Parse (newXml));

Problem 2 - Problem with the SharePoint error coming back as FaultException

This has been bugging for me ages so I am glad I have finally solved it. I can't take credit for it, as I took it from another page, but the following code was how I got the details.

catch (FaultException fe)
        {
            MessageFault msgFault = fe.CreateMessageFault();
            XmlElement elm = msgFault.GetDetail<XmlElement>();
}

Hopefully this will save someone some frustration in the future!

Andrew

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.