Developer forum

Forum » CMS - Standard features » How to point the Filepublish module to a specific folder programmatically

How to point the Filepublish module to a specific folder programmatically

Henrik Sørensen
Reply

I need to list the content of a dynamically chosen folder. But in the Filepublish module it seems I have to point to a static folder?

To be more precise, all the folders I need to point to are direct subfolders of a given folder.

So it is very easy to generate the path, but how do I override the static folder setting of the module?

When I manually navigate into one of the subfolders I can see (using TemplateTags) that it  has a FilepublishFolderList property = "/foldername". Is it possible to set this value in -- say- a modification of Filepublish/FilepublishList.html?

 


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Henrik

I do not understand what you want to do.

In filepublisher you point to a folder, and Dynamicweb gives you a list of files in that folder and a list of subfolders. Clicking a subfolder gives you files and subfolders in that folder and so forth.

If you want to list the content of the selected folders and all the subfolders at the same time, using a Razor template is an easy way of doing that.

Nicolai

 
Henrik Sørensen
Reply

"In filepublisher you point to a folder, and Dynamicweb gives you a list of files in that folder and a list of subfolders. Clicking a subfolder gives you files and subfolders in that folder and so forth."

That is what I referred to as 'manual navigation'. But I cannot use that. The folders contain confidential files relevant to one customer only. So I have to dive directly into the folder relevant to the customer (folder are named by customer number). The files FilepublishList and FilepublishListPart give me no hint of usable code/tags to set the folder path programmatically.

Should I use another module than Filepublish?

(Note: renamed the subject using 'programmatically' instead of 'dynamically')

 
Nicolai Høeg Pedersen
Reply

OK.

You could use Filepublisher - but you would have to do some things in Razor anyways.

Alternatively use an item with a field of type folder. But your code would be more or less the same.

BR Nicolai

 
Henrik Sørensen
Reply

Thanks, Nicolai

Here is my solution, for the benefit of anybody who stumbles upon this issue:

I gave up on the Filepublish module and just used an ordinary razor-template:

 

@helper GetFiles()
{
    string application = new HostResolver().ApplicationPath;
    string path = application + "Files/MyDocuments/" + Dynamicweb.Frontend.PageView.Current().User.CustomerNumber;

    DirectoryInfo mydocumentsDirectory = new DirectoryInfo(path);
    if (mydocumentsDirectory != null && mydocumentsDirectory.GetFiles().Length > 0)
    {
        foreach (FileInfo file in mydocumentsDirectory.GetFiles())
        {
            if (file.Exists)
            {
                <span>@file.Name</span>
            }

        }
    }
}

And the HostResolver class:

    public class HostResolver
    {

        public string ApplicationPath
        {
            get
            {
                return HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath);
            } 
        }
    }

 

(Of course don't forget to include a using statement in your template, referring to the namespace of your HostResolver class)

 

Solution tested on both localhost and Azure site.

 

 

You must be logged in to post in the forum