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 ExtensionsModulesModulesFile downloadFile download
Previous
 
Next
New Post
8/19/2010 12:03 PM
 
How do you access your module folder programmatically (in C#) and download a pdf file so it would not open itself in browser? Is there any functions in DNN for it? PortalSettings.HomeDirectoryMapPath gets me to the portal folder, but I need to get to the module folder. Maybe I'm just tired after long night's work, it feels like I got some snow on my head during the hot summer day...
 
New Post
8/24/2010 5:47 AM
 
There is a module.modulepath property in a module, but you shouldn't really store pdf files in a module directory.  They should be stored in the portal directory.

There is no (easy) way to make a pdf download without opening because that's up to the user and their browser/OS settings.  The easiest way is to put the pdf into a zip file.  Or just put the <a> link for the PDF to open in a new window - that won't lose the person from the browser and gives the user the choice on what to do with the pdf file.
 
New Post
8/24/2010 10:52 AM
 
I have a static, informational PDF files that is going to be a part of the module, and the users are clicking the same link, and based on their role the correct PDF file is downloaded.

Here's my solution (might help somebody):

protected void cmdReviewInfo_Click(object sender, EventArgs e)
{
    try
    {
 string strPath = Server.MapPath("~") + @"DesktopModules\ModuleName\FilesFolder\";
 string strContentType = "application/pdf";
 string strFileName = "";

 if (PortalSecurity.IsInRole("CustomRoleOne"))
 {
     //get the required info
     strFileName = "RequiredInformation_One.pdf";
     DownloadFile(strPath, strFileName, strContentType);
 }
 else if (PortalSecurity.IsInRole("CustomRoleTwo"))
 {
     //get the required info
     strFileName = "RequiredInformation_Two.pdf";
     DownloadFile(strPath, strFileName, strContentType);
 }
 else
 {
     Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(), true);
 }
    }
    catch (System.Exception exc) //Module failed to load
    {
 Exceptions.ProcessModuleLoadException(this, exc);
    }
}

///


/// Downloads a file
///
/// Path to the directory
/// File Name of a document/file
/// Content Type of the downloadable file (e.g. application/pdf)
public void DownloadFile(string strPath, string strFileName, string strContentType)
{
    if (File.Exists(strPath + strFileName))
    {
 Response.ContentType = strContentType;
 Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);

 FileStream sourceFile = new FileStream(strPath + strFileName, FileMode.Open);
 long FileSize;
 FileSize = sourceFile.Length;
 byte[] getContent = new byte[(int)FileSize];
 sourceFile.Read(getContent, 0, (int)sourceFile.Length);
 sourceFile.Close();

 Response.BinaryWrite(getContent);
    }
    else
    {
 MsgBox("The file is missing!");
    }
}

These forums are not code friendly at all, which should be opposite...
 
Cheers,

Val
 
New Post
10/25/2010 2:01 PM
 
Hi,

Please help me with this.  I have another page that displays the links to the files for users to download.  When they click on a link, I want them to download the file they clicked on.  The files are dynamically generated for each user so I don't think I can use the document module.  What I did is create a page "DownloadAttachment" and drop a download module with similar code as you described on that page.  The links refer to this "DownloadAttachment" page with query string for which file to download.  However, when the file is downloaded, it contains the content of the file plus the html code for the "DownloadAttachment" page.
 
New Post
10/25/2010 2:05 PM
 
KNGUYEN

You should clear response before sending any data, something like this:

Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "application/json; charset=utf-8";
Response.AppendHeader("Content-Length", lstByte.Length.ToString());
Response.BinaryWrite(lstByte);
Response.Flush();
Response.End();

Sergey
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesFile downloadFile download


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