How To Change SharePoint Document Library View On The Fly Using Code
For example, I have a document library that hold contracts for multiple projects.
So:
DocLib Contract_For_Project_A.pdf (metada: code: PRJA) Contract_For_Project_B.pdf (metada: code: PRJB) etc.
In requirement term, maybe something like "I want to store project specific document like contracts in any document library belonging to a division or department, etc. I should not be restricted to store project specific document in only the project site since it might make more sense to associate them to its related department / division, etc."
And there is a user requirement that "as a user开发者_如何学编程, I want to be able to only view project specific document based on the project code metadata that I will choose when I arrive in the portal and all documents that are shown to me should be filtered by the chosen project code metadata (in any document library that contain project specific documents)
The question is how can we do this in SharePoint?
I'm thinking of storing the chosen project metadata in a Session variable from a webpart and then pick this up once I get to the document library, perhaps add another web part in there that will pick up the project metadata from session and redirect the page to the right view that is already setup to filter documents based on the project metadata...
DocLib Views ViewForProjectA ViewForProjectB etc.
Is this a good approach or is there a better approach?
In this scenario it will basically load the default view w/ the redirector webpart first, so there will be a redirect which might not be desirable. Is there a way to do this in a straightforward way without having to do client redirect?
I would recommend following approach which I feel is simple and wont require coding.
- Create a Custom Content Type Project inherited from Document, you can add a column for Project Code.
- Add this content type to all the doc Lib of any site you wanted.
- Create a Content Query Webpart & Hook up this Content Type and add a Filter to Filter the records based on the Project Code.
- If you wanted to display the details based on the Logged In user Information, then you can always use Audience Targeting or Extend the Content Query WebPart to get the customized based on the login in user.
Refer This for more information on Content Query WebPart.
精彩评论