Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to create a view programatically to be used in an XSLTViewWebPart. When I try to browse to the view I got this exception:

Cannot complete this action. Please try again.

I set the log to verbose in all categories, but there is nothing.

public static void CreateRequestDetailView(SPWeb sourceWeb, string listName, string viewName, string detailNameNorthSouth, string xslLink)
    {
        SPList sourceList = sourceWeb.GetSafeListByName(listName);

        SPView view = sourceList.GetViewByName(viewName);

        if(view != null) {
            sourceList.Views.Delete(view.ID);
        }

        StringCollection viewFields = new System.Collections.Specialized.StringCollection();            
        foreach (SPField field in sourceList.Fields)
        {
            viewFields.Add(field.StaticName);
        }

        string myquery = "<Query><Where><Eq><FieldRef Name=\"ID\"/><Value Type=\"Number\">{SelectedID}</Value></Eq></Where></Query>";

        view = sourceList.Views.Add(viewName, viewFields, myquery, 1, false, false);
        view.ParameterBindings += @"<ParameterBinding Name='SelectedID' Location='None' DefaultValue='' />";
        view.XslLink = xslLink;
        view.Update();
    }
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I have seen the "Cannot complete this action" come up for two reasons.

First make sure that you have permission to view that area. I have two user profiles that I use one with access to all areas and one with limited access. When I test my new webparts in the limited user I sometimes forget that I do not have access to certain areas.

Second would be if for some reason the list page itself would need to be checked in or published. I have a lot of custom code in my masterpage and I get this error every time I make a change to it. I have to remember that I need to publish it so that it can be viewable.

I really can't see anything wrong with your code and from what you stated above it sounds like the issue is occuring before you actually call the function so I would have to say that one of the two above resolutions should work.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.