Question

crosspost: https://orchard.codeplex.com/discussions/456226

In Orchard, each site (whether or not you enable multitenancy) seems to have it's own Folder within Media (main file folder for Orchard). I want to get the entire filesize of a current site (ergo, the folder under Media).

I've digged into the Framework and got into FileSystemStorageProvider which seems to be promising with the FileSystemStorageFolder class and GetSize() method.

However, I was wondering if anyone else checked this out before I go into experimenting with that class.

Any piece of information or advise would be highly apreciated. Thanks!

Was it helpful?

Solution

Didn't really find an easy way to do it but copied mostly from the Orchard framework. You will need the following:

private FileSystemStorageProvider _filesystemProvider;
private ShellSettings _settings;

And then you need to define the Site Storage Path:

var mediaPath = HostingEnvironment.IsHosted
                                ? HostingEnvironment.MapPath("~/Media/") ?? ""
                                : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Media");  
storagePath = Path.Combine(mediaPath, _settings.Name);

Finally, here is my function to compute the storage for a specific folder (in this case, the tenant's/site's root media folder):

public double GetSiteStorage()
        {
            var folders = _filesystemProvider.ListFolders(storagePath);
            long totalSize = 0;

            foreach (var folder in folders)
            {
                totalSize += folder.GetSize();
            }

            return (totalSize / 1024 / 1024);
        }

This returns a double for the MB used. Hope this helps someone :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top