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) {

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

        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;

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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