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

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Code for downloading filesCode for downloading files
Previous
 
Next
New Post
9/4/2009 10:26 AM
 

Hi,

I need to impliment functionality to download files with server side code.

My module already has functionality for users to upload files.  When the file is uploaded, it is physically renamed to a GUID plus the file extension (for example, a MSWord file named "report.doc" may be renamed to "5fb72ccd-6a0f-4931-b26e-3be906f8a29b.doc").   The original filename, GUID file name, and UserID are stored in a table. 

Now, I want to have server side code to download individual files.  The Save As dialog should contain the original file name - in this example - report.doc

I have found ser ver side code to perform a basic download - but no code that has the extra step of showing the original file name - and not the physical file name on the server.  It is probably just one extra step that I am unaware of...

Any assistance and/or code samples would be appreciated.

Thanks in advance, Al

 
New Post
9/4/2009 11:47 AM
 

Take a look at the Repository module source code, it does exactly that .... including the GUID :) and renaming the file on download.

NOTE: The source is still .net 1.1, so download and take a look using notepad if you're using VS2005,2008 or 2010. Do NOT install the source code verison of the module in your DNN 4.X or 5.X web site.

 
New Post
9/4/2009 11:50 AM
 

oh what the heck .. I'll save you the time :)

use the .AppendHeader method.  In the example below, "DownloadAs" is a string variable that contains the original filename

            Dim objResponse As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
            objResponse.ClearContent()
 
            objResponse.ClearHeaders()
            objResponse.AppendHeader("Content-Disposition", "attachment; filename=" & DownloadAs)

 

 
New Post
9/4/2009 2:17 PM
 

Thanks Steve - I will download the module and have a look at the source code.

 

 
New Post
9/7/2009 8:15 AM
 

Well I almost have this working - thanks for pointing me in the right direction.

I get the file save as dialog box - but when I go to save the file, it times out and I get an error "filename could not be saved, because the source file could not be read".  This occurs in FireFox and IE8.

I stepped through the source code, and it is attempting to download a physical file on the file system that does exist...  Any ideas what may be causing this problem?

Note:  I am running the site from localhost - the files are saved (and subsequently downloaded) to/from a folder named  DesktopModulkes/MyModule/FileUploads.  It shouldn't be a permissions issue since Network Service has full rights to all folders/files.

Any ideas on what may be causing this issue?

Thanks, Al

 

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Code for downloading filesCode for downloading files


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