0

I'm trying to create a custom view for a list with custom UI. The following is my code:

list.Views.Add("List View", coll, Query, 10, true, false);
list.Update();

SPView view = list.Views["List View"];

string contents = string.Empty;
WebRequest request = WebRequest.Create(SPContext.Current.Web.Url+"/_layouts/CustomViews/CustomBoxed.xml");
request.Credentials = CredentialCache.DefaultCredentials;
WebResponse response = request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
 {
       contents = reader.ReadToEnd();
 }
 response.Close();

 view.SetViewXml(contents);
 view.Title = "My List View";
 view.Update();

The code is basically creating a view in the list, then updating the XML inside the view to display something different. However, on view.Update() I get this error: Cannot complete this action. Please try again

What I'm trying to accomplish: Show an entirely different UI to display the list items. I have gotten copy of the sharepoint VWSTYLES.XML and have used their styles, but that doesn't seem to work.

Thanks! And sorry if this question is a bit confusing.

2
  • Can you verify the contents of the "CustomBoxed.xml" file to which you're making the WebRequest are correctly being assigned to the variable contents? Can you share the contents of that file with us? Commented May 29, 2012 at 22:28
  • SetViewXML isn't suppose to be the XSLT, it contains an XML for the view, defining the fields, etc. There is no way to customize the XSLT of a view. I've done extensive research on that.
    – Umm....
    Commented May 31, 2012 at 20:43

1 Answer 1

0

I found a work around: The List I want my view in, I inject my custom web part on that page. In my custom web part, I hide the fefault listview web part and show my custom UI there. The only issue I have here is that the ribbon loses its tabs. I'll have to fa work around that.

Your Answer

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

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