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...DNN Platform (o...DNN Platform (o...Creating file download linkCreating file download link
Previous
 
Next
New Post
4/15/2009 10:38 PM
 

Folks,

My application has streaming media with a download option.  The download button on the page is meant to open the file download dialog on the browser so you can save the media file locally.  I've wired my download link to the following code in the event:

            System.IO.FileInfo file = new System.IO.FileInfo("C:\\pathtomyfiles\\myfile.mp3");

            Response.Clear(); // clear the current output content from the buffer
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + file.Name);
            Response.AppendHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(file.FullName);
            Response.End();

Adding the "Content-Disposition" header should make the file dialog pop up, but nothing happens.  Does DNN mess with the response headers?  Is there a more DNN-friendly way of making a file download link on a page?

Thanks for your help.

AldenG

 
New Post
4/15/2009 11:53 PM
 

That code is similar to what I've used before with the following differences, however:

1. In place of Response.Clear(), I use the following (but seem to recall that Clear() clears both Content and Headers anyway):

Response.ClearContent();
Response.ClearHeaders();

2. I thought that when specifying the filename for the Content-Disposition header, the filename needed to be enclosed in single quotes:

Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + file.Name + "\"");

3. Before calling Response.End, I explicitly flush the content to the stream:

Response.Flush();
Response.End();

I would also recommend that for security reasons alone you should instead use the DNN core LinkClick.aspx handler for file download. You should call the following method (or one of it's overloads) to construct the download link:

Public Function LinkClick(ByVal Link As String, ByVal TabID As Integer, ByVal ModuleID As Integer, ByVal TrackClicks As Boolean, ByVal ForceDownload As Boolean) As String

Link may be either a reference to a DNN FileId in the form of "fileid=####" or a filepath. The ForceDownload parameter should be true to force the file open/save dialog box to appear.


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
4/16/2009 11:37 AM
 

This is great, thanks.  I'd like to use LinkClick, but I've run into a little problem.

Early on, I found the standard file upload in DNN didn't provide a decent user experience for large file uploads.  I implemented Brettle NeatUpload, which gives me a progress bar, a cancel button and a more AJAXy feel.

But now I have a file full of media on the server that is not hooked in with the standard DNN file manager.  Are there APIs I can call on upload that can install my directory and files into the file manager and give me a FileID for the uploaded file?  Then I'll just store the FileID in my table, and I can use it in LinkClick.

Thanks!

AldenG

PS: I will likely turn to Amazon S3 to store these files, eventually.  They're big.  Does the DNN file manager integrate easily with S3?

 
New Post
4/16/2009 12:46 PM
 

Assuming that you are storing uploaded files in either the portal root folder, i.e. "/Portals/nn/" where nn is the PortalId or in a sub-folder of the Portal root, you should (as a temporary fix for existing uploads) be able to open the DNN file manager and perform a manual resync which will assign FileId to each file. Alternatively, and a far better long term approach, will be to modify your module's code which uses the Brettle NeatUpload control to both store the uploaded file bits to physical storage AND add the file to the DNN Files table. A FileId would be returned from the core method which you could then store in your custom table.

There are several methods available in the FileSystemUtils class to do that. Other, lower level methods also exist in the DNN FolderController and FileController classes but should only be used if a higher-level method does not fit your needs. I would suggest taking a look at the DNN framework source code including that of the File Manager control for inspiration.

I also recall that the DotNetNuke.Common.Globals.LinkClick url building method will take a file path as the link parameter but don't recommend (because of security concerns) that approach if you can store and use a FileId.


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
4/16/2009 6:27 PM
 

Thanks so much for your help.

I'm trying to figure out the right methods to call in FileSystemUtils and how to do it.  I'm guessing its something like the following, but this isn't working:

                FolderInfo fo = FileSystemUtils.GetFolder(PortalSettings.PortalId, "AudioFiles/");
                string result = FileSystemUtils.AddFile(Server.MapPath("~") + "\\Portals\\0\\AudioFiles\\" + file.FileName, PortalSettings.PortalId, true, fo);
 

At this point in the code, the audio file is already in the correct directory.  I'm just trying to get the DNN tables set up correctly.  The FolderInfo comes back correctly, but I've tried several ways of calling AddFile, and none of them are working.  Because it doesn't return a FileID, I'm not even sure this is the right method, but I can't find any that do.  What's the right method to call?

AldenG

 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Creating file download linkCreating file download link


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