I have a document library called 'Client Documents' that has a column called 'Client' and 'Document Type', when a user uploads a document to the library they select a client for example 'Microsoft' and then the document type 'Network Diagram'

I then created a view called 'Microsoft Network Diagrams' that filters the company name 'Microsoft' and the document type 'Network Diagrams' to just show me the documents for that client.

I then created a page with a webpart that connects to the document library 'Client Documents' and then I select the view 'Microsoft Network Diagrams' from the webpart options which works as expected.

The problem I have is if I make a change the to view I have to edit the webpart and re-select the view for it to update.

Is there a way for the view to update automatically on the page?


The changes made in the original view will not reflect in the webpart as the copy of the view in webpart is different from original one.


The sample code to update the view of XsltListViewWebPart. Note that I haven't tested the code. You can create a console app, test the code and then use the .exe in task schedueler

// Get refrerence of the page containing the xslt list view webpart
SPFile page = web.GetFile("PageUrl");
SPLimitedWebPartManager wpm = page.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
System.Web.UI.WebControls.WebParts.WebPart webPart = null;
// Check if webpart is on the page or not
SPLimitedWebPartCollection webPartCollection = wpm.WebParts;
foreach (System.Web.UI.WebControls.WebParts.WebPart part in webPartCollection)
    if (part.Title.Equals(webPartTitle, StringComparison.OrdinalIgnoreCase))
        XsltListViewWebPart wp = (XsltListViewWebPart)part;
        // Get the list
        SPList list = web.Lists["ListTitle"];
        // Update the view of list view webpart
        wp.View = list.View["ViewName"];
| improve this answer | |
  • So there is now way around this to allow the view to be updated? – Matt Saunders Nov 30 '14 at 11:30
  • The code can written inside a task scheduler or timer job to update the view as per the timing requirements. – Nadeem Yousuf-AIS Dec 1 '14 at 5:49
  • Hi Nadeem, thanks for the reply, can you explain how to create this with the correct code – Matt Saunders Dec 1 '14 at 5:52
  • @MattSaunders see my updated answer – Nadeem Yousuf-AIS Dec 1 '14 at 6:23

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.