views:

2175

answers:

7

I have a SharePoint document library that has a folder structure used for organizing the documents (but also for controlling access, via permissions on the folders).

The documents in the library are updated every month, and we store every month's version of the document in the same folder; there's a "month" column used for filtering that will contain values like Jan 09, Feb 09, etc. It looks like this:

    Title                  Month
    -----                  -----
    SubFolder 1
    SubFolder 2
[]  Interesting Facts      Jan 09
[]  Interesting Facts      Feb 09
[]  Interesting Facts      Mar 09
[]  Fascinating Numbers    Jan 09
[]  Fascinating Numbers    Feb 09
    ...

Now, because users will generally be most interested in the 'current' month, I'd like them to be able to apply a filter, and select (say) Mar 09. However, if they do this using the built-in filtering, it also filters out the folders, and they can no longer navigate the folder hierarchy. This is no good - I want them to be able to move between folders with the filter intact, so that they don't need to keep switching it off and on again.

I figured I might be able to use a custom view (selecting where type=folder or month=[month]), and to an extent that does work. However, I can only get it to work for a fixed month, whereas I need the user to be able to select the month - perhaps via a drop-down control on the page (and I don't want to create 60 views for 5 years' worth of months, nor do I want to have to create a new view every month).

I thought it might be possible to create a view in code (rather than via the UI), but I've not been able to figure out how to get a dynamic value (a user-specific setting) into the CAML query.

Any pointers gratefully appreciated! And by the way, I am aware of the dogma that folders are bad, and that everything should just be a list. However, having considered the alternatives, I still favour using folders - if I can solve this problem.

Thanks in advance.

A: 

You might like to try using a DataViewWebpart filtered by a form webpart to do this. Managing the display of the folders and then the folders items when it is clicked on will be a problem. That is one of the reasons for not using folders I guess.

Nat
A: 
Gary McGill
A: 

I'm currently experiencing the exact same issue, instead of a simple date, I need to filter based on folder names and then then show those folders on the page. Once they click a folder they will then be able to view the content of that folder.

I haven't found a good solution for this just yet, but for yours, you should be able to simply create a custom CAML query using the contentQueryWebpart.

Something like this: Further Customize CQWP

But you would do it on the date/time of the folder and nothing else.

Your query would be something like:

 <![CDATA[
    <Where>
     <Gt>
       <FieldRef Name="Created" Nullable="True" Type="DateTime"/>
       <Value Type="DateTime"><Today /></Value>
     </Gt>
   </Where>
   <OrderBy>
       <FieldRef Name="Created" Nullable="True" Type="DateTime"Ascending="FALSE"/>
   </OrderBy>]]>

I would add also the name of the folder you're looking for to make sure nothing else gets returned.

Hope this helps. And please do postback if you find another solution.

TeckniX
A: 

I think I found your solution - The DataWebPart is actually what helped me....

Using this also was a huge eye opener: ASP.NET Controls Filter Data View

To summarize it, you can simply populate your dropdown with the month year combo, add the shared Doc library on the page via the designer view, use a 'filter' connection to your ASP.NET dropdown and pronto you have a filter on a per month. You can also have it default to a certain date using XSL, it's all in the code-view now :)

TeckniX
A: 

@Gary The Controls filter of the DATA view (my 2nd answer) actually does keep the folder hierarchy.

You can have it go into sub-folders if needed, but in your case you're only interested in showing one specific folder correct?

What you're doing is useing SP-designer to do it, I couldn't find a way to do it via the regular webparts.

  1. drag and drop your shared document library in the 'design' view for the page
  2. Click the common task arrow ( > ) and customize the columns you want to show
  3. Still in the common task, apply a filter of choice. What you want to do here is apply a filter on your Month column, so that the Month column is equal to the current month/year, correct? The filter will only give you a choice to type something in, type the current month, say May 09. then switch to 'code' view
  4. Find the shared document library, and more specifically look for something like: &lt ;Where&gt ;.... That is the CAML query I had mentioned before. You can do an HTML decode on the whole thing, so that it's a bit more readable. But in essence, the filter is a simple CAML query. You want to modify that query, so that your month/year combo is that of the current month/year. CAML has one feature called <MONTH/> which returns the month in the following format: mm/yyyy (you may need to change the format on your column or create a new one to make it easy on yourself) - Your CAML query should be something a bit like this:

<Where>
 <Eq>
   <FieldRef Name='Month'/>
   <Value Type='Number'><Month/></Value>
 </Eq>
</Where>

or html encoded:

&lt ;Where&gt ;&lt ;Eq&gt ;&lt ;FieldRef Name='Month'/&gt ;&lt ;Value Type='Number'&gt ;&lt ;Month/&gt ;&lt ;/Value&gt ;&lt ;/Eq&gt ;&lt ;/Where&gt ;

The key to this, is that you're only creating a filter at the root level, on the data view. Once they click on the folder, they're just thrown into the document library and can view everything within the folder.

Hope this help!

ps: on the html encoded I had to add spaces before the ';' so you could see the code.

TeckniX
A: 

I have worked a great deal with filtering and the SPGridView. Maybe you can get something out of looking into this post on my my blog. As I said, don´t know if it will help you but have a look.

Johan Leino
+1  A: 

Could you create a content type that inherits from Folder that contains a Month column? Then, replace the normal folder content type with your new one on this list. Set the month appropriately, and now your filter would contain the folder as well.