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 ExtensionsModulesModulesLinkClick Function does not workLinkClick Function does not work
Previous
 
Next
New Post
3/24/2011 6:02 PM
 
Hi,
I want to download a file by selecting a line in a GridView. File is located on specific server directory (site in not in production yet, I'm running in on IIS).

I use the following code:

Protected Sub GridViewFichiersRéponseUploadés_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridViewFichiersRéponseUploadés.SelectedIndexChanged

DotNetnuke.Common.Globals.LinkClick("http://localhost/itmacrosolution.com/FichiersUploades/Data1.png", PortalSettings.ActiveTab.TabID, ModuleId, True, True)

End Sub


Http address is valid. If I copy it in my browser, the file opens.
When I select a line in my gridview, there is postback but nothing else happens.
Any idea ?

Thanks
JoceM
 
New Post
3/24/2011 8:39 PM
 
DotNetNuke.Common.Globals.LInkClick is a function which returns a string containing the download url which will include in its path the LinkClick.aspx and in its querystring either a file ticket or url encoded link to the file. DotNetNuke.Common.Globals LinkClick is NOT a subroutine which actually performs the download.

In most cases the string returned by LinkClick will then be assigned to the href attribute of an html anchor tag or to the PostbackUrl property of an ASP.Net ImageButton, LinkButton, etc. In your GridView's SelectedIndexChanged event handler you call LinkClick but then do nothing with the url string which is returned by the function. If you wish to handle a download request in this manner, you will need to perform a Redirect to the url returned by LinkClick. Something like the following:

Dim downloadLink As String = DotNetnuke.Common.Globals.LinkClick("http://localhost/itmacrosolution.com/FichiersUploades/Data1.png", _
PortalSettings.ActiveTab.TabID, ModuleId, True, True)

HttpContext.Current.Response.Redirect(downloadLink, True)


A more efficient way to start the download (without an extra postback to handle the SelectedIndexChanged event) would be to construct during databinding the grid an html anchor tag around the filename or file title in one of your grid's columns and use the url returned by LinkClick as the value for the anchor tag's href attribute. Take a look at the source of a module such as Documents or Links and I'm sure you'll find code similar to what you are trying to accomplish.

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
3/26/2011 5:35 PM
 
Bill,
Great advice, thanks. I have tried the first option as I'm not exactly sure how to code the second one. It works fine except that the force download des not work. 

HttpContext.Current.Response.Redirect opens the file in browser. Is there a way to force download that way ?
Joce

 
New Post
3/31/2011 9:07 AM
 
Hi,

Playing around trying to find a solution, I realized that if I zip the file, then I get the download dialog box. If I keep the png extention, then the file opens in browser. Can anyone direct me to a way to force download of png (and other non-zip) files ?

Thanks

Joce

 
New Post
3/31/2011 9:35 AM
 
Jocelyn

You should add this header to your response:

Response.AddHeader("Content-disposition", "attachment; filename=\"photo.png\"");

Hope this helps!

Sergey

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesLinkClick Function does not workLinkClick Function does not work


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