Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesDotNetNuke Module File ManagementDotNetNuke Module File Management
Previous
 
Next
New Post
8/5/2011 3:29 PM
 
I am building a custom module and need some help understanding how files should be managed within the context of a module.
I am able to upload files directly but it feels like there should be a more robust, dotnetnuke way to do this. I ask a lot of specific questions below but my basic question is how do I manage files in DNN in the right way? I have yet to find a good tutorial on DNN file management.

How do you allow users to upload a file?
  • Is there a built in way within DNN to do this or do I access the file system directly?
  • How do i separate different instances of the module (and the uploaded files) in the file system? Is there a best practice for this?
  • How do i register that a file was uploaded with the database so I can get info about who uploaded it, when, that sort of thing?
How do I allow users to download a file?
  • Is there a way in DNN to see all the files uploaded within a module?
  • Can I search for files based on date uploaded?
  • Is there any support for zipping multiple files before download?
  • Can I search for files based on whether they have been downloaded before?
 
New Post
8/5/2011 6:20 PM
 
Hello,
you're recommended to use the DotNetNuke API's rather than direct file access code. There are a number of reasons for this
  • the API's will apply various security checks automatically (e.g. safe list of extensions, if the file is within a certain size etc.)
  • the API's will also reflect permissions e.g. if a user "chris" tries to execute code to upload to a folder it will validate that the user has permissions to that folder
  • most importantly - DotNetNuke files are not just physical entries, they have a database component as well which is basically the abstractly file system. This means that files can have different properties and allows for support of standard, secure file system (automatic appending of .resources so files cant be directly accessed) and secure database (store in a database). Using the proper API's this relationship is maintained. If you dont use them you will have to either invoke a SynchronizeFolder method or manually sync in the filemanager.

Unfortunately you never mentioned what version you're targetting. If it's pre DotNetNuke 6.0, then the key class is FileSystemUtils - it'll contain all the various getfolder/getfolders/copyfile/movefile/deletefile etc. However in 6.0 we added support for folder and file providers (see http://www.dotnetnuke.com/Resources/W... ) which makes this class effectively obsolete i.e. you can still code against it (and if you're targetting pre 6.0 installs you have to), but you're recommended to use the new API's so that any alternative folder providers (e.g Azure, dropbox, s3 etc.) will work with your uploaded files/folders.

DotNetNuke does register who created/modified a file/folder and when but it's user based not module based - if your module needs to store this info you'll have to roll that part yourself. Note: when you add files to download somewhere, the control that does that allows you to check a box to track the downloads (this is possible as all access goes through linkclick.aspx - note: you can access the data in the urltracking table to see clicks, lastclick, activity etc.)

You can get lists of files and folders but normally everything is based on your portal and in the case of the files the approriate folder. Of course you can return lists of these fileinfo and folderinfo objects and apply your own filtering e.g. a linq expression

There is a zip component within DotNetNuke and we do support unzipping of packages but AFAIR there is no code for creating zip packages, you can of course write that yourself just reference the icsharpziplib library.

In general I'd recommend you take a look at the file manager code as it uses most functions - you'll find the code in
DesktopModules\Admin\FileManager\ and the relevant file is called FileManager.ascx.cs/filemanager.ascx.vb (depending on version)

Thanks.

Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
 
New Post
8/8/2011 8:24 PM
 
I'm targeting 5.4.2.

I was able to get folders working and files uploaded however any files uploaded do not have a createdByUserID or CreatedOnDate in the database. Any reason why?
private void saveUploadedFile()
{
string path = PortalSettings.HomeDirectoryMapPath;
string testFolder = path + "test\\";

string s = FileSystemUtils.UploadFile(testFolder, fuData.PostedFile);
}
 
New Post
8/8/2011 9:10 PM
 
An additional question.
I have a function that checks if the folder for my module exists, and if not, then it's created. These new folders however are only accessible by admins. Is there a way to grant write access to all registered users to the new folder in code?
 
New Post
8/8/2011 9:12 PM
 
are the columns in the table or are you not seeing values written?

Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesDotNetNuke Module File ManagementDotNetNuke Module File Management


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out