Greetings!
I want to open a PDF file in a new window, not in the current page.
It was a friend who did this and he is on vacation, so I must figure it
out by my own :)
I have the following ascx code:
<asp:DataList id="lstAnexos" Runat="server"
EnableViewState="false" BorderStyle="Solid" BorderWidth="1"
Width="100%"> <ItemTemplate>
<!--<asp:HyperLink
id="anexoLink_old" runat="server" Visible="true" Target=_blank
text='<%# DataBinder.Eval(Container.DataItem,"text") %>'
navigateurl='<%#
FormatURL(DataBinder.Eval(Container.DataItem,"NavigateUrl")) %>'
BorderStyle="NotSet" width=100%/>-->
<asp:LinkButton
ID="anexoLink" CssClass="Normal" Runat="server"
OnCommand="lnkDLFile_Command" CommandArgument='<%#
DataBinder.Eval(Container.DataItem,"NavigateUrl")%>'><%#
DataBinder.Eval(Container.DataItem,"NavigateUrl")%></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
And in the Vb file:
Private Sub loadAnexos(ByVal objArticle As ArticleInfo)
Dim sAnexos As String = objArticle.Anexos
Dim arAnexos As New ArrayList
Dim item As HyperLink
Dim sText As String
Dim sURL As String
If (Not sAnexos Is Nothing) And (sAnexos <> "") Then
For Each sURL In sAnexos.Split(",")
If sURL <> "" Then
Dim fc As New DotNetNuke.Services.FileSystem.FileController
Dim fi As DotNetNuke.Services.FileSystem.FileInfo
If sURL.StartsWith("FileID=") Then
fi = fc.GetFileById(sURL.Substring(7), PortalId)
Else
fi = fc.GetFile(sURL, PortalId, "")
End If
If Not fi Is Nothing Then
sText = fi.Folder & fi.FileName
item = New HyperLink
item.Text = sText
item.NavigateUrl = sText
arAnexos.Add(item)
End If
End If
Next
End If
lstAnexos.DataSource = arAnexos
lstAnexos.DataBind()
End Sub
(I don't know why the friend who implement this module put the comments on the hyperlink and used a linkbutton instead!)
I suppose maybe with item.Attributes.Add(..) or javascript window.open I could get something...
Concerning the hyperlink, I thought the same and switched comments, but
no result! I tried item.Target = "_new" or
item.Attributes.Add("target", "_new") and it still opened in the same
window. Even with javascript (but here I don't think I did it right)...
I also tried the linkbutton solution, but I cannot seem to enter
the lnkDLFile_Command method (I experimented the ItemCommmand which I
successfully use in other situations, but I think it requires DataGrid
and not DataList. When I changed from Grid to List I got this odd
error: The base class includes the field 'attachmentGrid', but its type
System.Web.UI.WebControls.DataGrid is not compatible with the type of
control System.Web.UI.WebControls.DataList).
The code in lnkDLFile_Command is the following:
'Protected Sub lnkDLFile_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
'DownloadFile(e.CommandArgument.ToString())
'BindFolderTree()
'End Sub
As you can see it is commented. These methods are used in another module of this DotNetNuke portal and they are working.
I
really believe the hyperlink is the better solution (as it is the
control created in runtime) so if you can give some help with this I'd
really thank you! I've been working on this during the last two days
and still no light!
Thanks in advance for your help!
Best regards,
Ricardo Pinto