Technical Questions Technical questions on Kentico CMS Connector for Microsoft SharePoint.
Kentico CMS Connector for Microsoft SharePoint > Technical Questions > Handling Folders in Document Lists View modes: 
User avatar
Member
Member
mosgath - 2/15/2013 8:53:02 AM
   
Handling Folders in Document Lists
We have a SharePoint Document List that contains folders and sub-folders n-levels deep as well as documents from each level such as:

-Root Level
--Folder 1
----Folder 3
------Document 5
----Folder 4
------Document 4
--Folder 2
----Document 3
--Document 1
--Document 2

We need to display on one page all documents and folders under Folder 1 and allow the user to click on a link for Folder 4 to get the list of documents under it. The CMS Connector for SharePoint does not allow me to pass in the folder I want to display the contents of.

I contacted support and they have added this as a feature request as it is not support out of the box. However, I wanted to see how others may have handled this scenario? Did you write a completely custom web part or use a web service web part or did you extend the CMS Connector for SharePoint web part? Or am I missing something more obvious?

Thanks.



User avatar
Member
Member
mosgath - 2/19/2013 8:03:59 AM
   
RE:Handling Folders in Document Lists
I have decided to go with customizing the Sharepoint web parts. I am using CMS 7.0, so I copied the contents of the CMSWebParts\Sharepoint directory to a company specific folder under CMSWebParts and renamed all the class in the copied files to include a company identifier to prevent conflicts. Then in the CMSWebParts\{company}\Sharepoint\SharePointDataSource_Files, I updated the logic in the SharePointDataSource.ascx.cs. I added a new public property to hold QueryOptions

private string mQueryOptions;

/// <summary>
/// Gets or sets query options which should be used. XML Formatted.
/// </summary>
public string QueryOptions
{
get
{
return mQueryOptions;
}
set
{
mQueryOptions = value;
}
}

and updated the LoadListItems function to populate Query Options.


if (!String.IsNullOrEmpty(QueryOptions))
{
queryOptions = new XmlDocument();

string xml = "<QueryOptions>";

xml += QueryOptions;

xml += "</QueryOptions>";
queryOptions.LoadXml(xml);
}


The queryOptions parameter was already being passed to the GetListItems method of the SharePoint web service.

Then I registered my WebParts through CMSSiteManager by cloning the existing Sharepoint controls into a Company specific category and updating the control paths. Then added the new field to each of them for Query Options under the advance category. I opted for the same configuration as what was used for the Query field.


After that, it was a matter of adding the web part to the page and configuring it. If I wanted to pull contents from a specific folder, I added the folder path into the QueryOptions property. This includes the necessary sub sites and list code name:

<Folder>{SubSite}/{ListName}/{Folder}/{SubFolder}</Folder>


I did have a few issues when I tried to configure the webpart on my page to allow drill down capability. Instead of hardcoding a path in the Query Options property on my page, I used macros to generate it based on a query string.


{%if (QueryString.GetValue("folder")!="") {"<Folder>"}%}


I used both the urlencode and replace macro options because the urlencode translated a space into plus ("+"). SharePoint expects them to be a "%20" instead. Also, if I tried to build this all inside of a single "if" statement, the replace macro options replaced the plus "+" with more than just a "%20". It actually included the closing brackets from my macro's if statement. My solution was to split it up into 3 if statements, one for the opening Folder tag, one for the path, and one for the closing Folder tag.

One other issue I ran into with the drill down was caching. I had left the caching properties set to the default. When I tested the drill down of my page through preview, it worked fine. But when I did it though the live site, it wouldn't drill down even through the query string was different. I discovered that I had to set the cache minutes to 0 in order to force it to retrieve the sub folder information from SharePoint.


User avatar
Member
Member
kentico_davidb2 - 2/20/2013 3:44:02 AM
   
RE:Handling Folders in Document Lists
Hello,

thank you very much for your contribution to our forums. Posts like this one are really appreciated.

Regards

David

User avatar
Member
Member
travis.bean-ranzcp - 5/10/2013 1:38:20 AM
   
RE:Handling Folders in Document Lists
Hi, this describes exactly what I would like to do on our website, but we are on Kentico v6. Do you think these mods would work in v6?

If so, I have a further question - you say in your post "I registered my WebParts through CMSSiteManager by cloning the existing Sharepoint controls into a Company specific category and updating the control paths. Then added the new field to each of them for Query Options under the advance category. I opted for the same configuration as what was used for the Query field."

Might you be able to explain this a little more step by step as this is one part of the process I'm not understanding how to do

thanks in advance!


User avatar
Member
Member
mosgath - 5/23/2013 3:20:02 PM
   
RE:Handling Folders in Document Lists
I would assume that this would work within Kentico v6, but I haven't worked directly with it to be certain. I am using v7.

In Site Manager under the Development Tab, select web parts. Open the folder with the SharePoint controls in it. For me it is under All Web Parts>Microsoft SharePoint.

I click the down arrow that is next to the delete icon in the list of controls in the Actions column for the SharePoint Data Source. This gives me a Clone option. I select that. A dialog will appear.

Enter the new object's Display Name as "{Company Name} SharePoint data source". I then select the Company Category I already had created for company web parts. I uncheck Clone Web Part Files because I had already created them. I enter the path and name of the Custom Data Source control that I had created in the Cloned web part file name. Then, I click clone.

I open the Company Category folder where I had these cloned to in the dialog. I click the edit icon that is next to the "{Company Name} SharePoint Data Source". I click the Properties tab.
I highlight the "View Fields" property and click the "+" icon.

In the new property, I give it the Column name "QueryOptions" which should match the field that I added to the ascx class file. I set the Attribute Type to "Long Text", the Field caption to "QueryOptions", the Form Control to "Text Area", columns to 80, rows to 4, and check the Wrap Text checkbox. Then click save.

I repeat those steps for each of the controls I created.

You could doe this manually by adding a new web part, but the cloning brings over all the other fields that already existed for the control. It is a lot less work. The key is to make sure that the property you add is the same name as the property that was added to the control and that the file name is the file name of your custom control.

Hope this helps.