mlagrange
asked on
DataNavigateUrlFormatString question
Hello - I've got a DataGrid with a data source populated from GetFiles()
I'm trying to use the "FullName" in a HyperLinkField, with the DataNavigateUrlFields = "FullName". Shouldn't I be able to set the DataNavigateUrlFormatStrin g = "{0}", since that has the full path name of the file?
<asp:HyperLinkField
DataNavigateUrlFields="Ful lName"
DataNavigateUrlFormatStrin g="{0}"
DataTextField="Name"
HeaderText="File Name" />
But when I set it uplike this, the file name appears as text, not as a link
What am I doing wrong, please?
Thanks
Mark
I'm trying to use the "FullName" in a HyperLinkField, with the DataNavigateUrlFields = "FullName". Shouldn't I be able to set the DataNavigateUrlFormatStrin
<asp:HyperLinkField
DataNavigateUrlFields="Ful
DataNavigateUrlFormatStrin
DataTextField="Name"
HeaderText="File Name" />
But when I set it uplike this, the file name appears as text, not as a link
What am I doing wrong, please?
Thanks
Mark
Hi,
you have setup parameters in wrong way...
Try using this exaple:
<asp:HyperLinkColumn Text="Click me"
DataNavigateUrlField="Id"
DataNavigateUrlFormatStrin g="My_Page .aspx?Id={ 0}"
HeaderText="Link column">
</asp:HyperLinkColumn>
you have setup parameters in wrong way...
Try using this exaple:
<asp:HyperLinkColumn Text="Click me"
DataNavigateUrlField="Id"
DataNavigateUrlFormatStrin
HeaderText="Link column">
</asp:HyperLinkColumn>
ASKER
Hi, aki4u - I should provide more details. I am not trying to move to another aspx. I'm displaying a list of pdf files down a particular directory path on the server, down a path like C:\Websites\WebProject\Cli entArea\(C lient#)\(Y ear)\(File Name)
I want the clients to be able to click the HyperLink of a given file, so it will prompt them to open or save the that pdf
The GridView gets populated from GetFiles(), so the "FullName" property is there. But when I use "FullName" as the DataNavigateUrlFields value, it does not show up like a link anymore.
As a test, I switched the DataNavigateUrlField to the "Path" property, and hard-coded a path name to a particular client/year in the DataNavigateUrlFormatStrin g, and it works fine IF I start from just the right directory level:
DataNavigateUrlField="Name "
DataNavigateUrlFormatStrin g="\WebPro ject\Clien tArea\0001 64\2001\{0 }"
Is there a way to use a string function in the DataNavigateUrlFormatStrin g to trim off the drive and parent folder name in the FullName ?
Or is there a smarter way?
Thanks
Mark
I want the clients to be able to click the HyperLink of a given file, so it will prompt them to open or save the that pdf
The GridView gets populated from GetFiles(), so the "FullName" property is there. But when I use "FullName" as the DataNavigateUrlFields value, it does not show up like a link anymore.
As a test, I switched the DataNavigateUrlField to the "Path" property, and hard-coded a path name to a particular client/year in the DataNavigateUrlFormatStrin
DataNavigateUrlField="Name
DataNavigateUrlFormatStrin
Is there a way to use a string function in the DataNavigateUrlFormatStrin
Or is there a smarter way?
Thanks
Mark
Why don't you build a full path when you are retriving these files and then just assign it to link control?
mlagrange, what is the root http path of your project? Is it http://localhost/WebProject/ ?
-Nauman.
-Nauman.
ASKER
Then DataNavigateUrlFormatStrin g="\WebPro ject\Clien tArea\0001 64\2001\{0 }" should be
DataNavigateUrlFormatStrin g="WebProj ect/Client Area/00016 4/2001/{0} "
I still recommend you use the TemplateColumn
<TemplateColumn>
<ItemTemplate>
<a href='WebProject/ClientAre a/000164/2 001/<%#Dat aBinder.Ev al(Contain er.DataIte m,"FullNam e")%><%#Da taBinder.E val(Contai ner.DataIt em,"FullNa me")%></a>
</ItemTemplate>
</TemplateColumn>
-Nauman.
DataNavigateUrlFormatStrin
I still recommend you use the TemplateColumn
<TemplateColumn>
<ItemTemplate>
<a href='WebProject/ClientAre
</ItemTemplate>
</TemplateColumn>
-Nauman.
ASKER
Thanks for your response, Nauman, but FullName is the *FULL* name, all the way back to to the C: drive:
C:\Websites\WebProject\Cli entArea\00 0164\2001\ (FileName)
and when I've tried that (even hard-coding it), the pathname no longer displays as a link, just text
Maybe I don't understand what the "DataBinder.Eval(Container .DataItem, "FullName" )" is doing
I tried to "Edit Templates" on that GridView, and the only options in the template drop-down are "EmptyDataTemplate" and "PagerTemplate". The GridView is bound to the result of a GetFiles() call that occurs when the user clicks a node on an accompanying TreeView control:
Protected Sub TreeView1_SelectedNodeChan ged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChan ged
Dim directory As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(Me .TreeView1 .SelectedN ode.Value)
Me.GridView1.DataSource = directory.GetFiles()
Me.GridView1.DataBind()
End Sub
The TreeView is populated from a routine in the page OnLoad event that recursed the directories down that path doing DirectoryInfo's
Sorry if this is getting confusing; I will post the code for the page, if you like
Thanks for trying to help
Mark
C:\Websites\WebProject\Cli
and when I've tried that (even hard-coding it), the pathname no longer displays as a link, just text
Maybe I don't understand what the "DataBinder.Eval(Container
I tried to "Edit Templates" on that GridView, and the only options in the template drop-down are "EmptyDataTemplate" and "PagerTemplate". The GridView is bound to the result of a GetFiles() call that occurs when the user clicks a node on an accompanying TreeView control:
Protected Sub TreeView1_SelectedNodeChan
Dim directory As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(Me
Me.GridView1.DataSource = directory.GetFiles()
Me.GridView1.DataBind()
End Sub
The TreeView is populated from a routine in the page OnLoad event that recursed the directories down that path doing DirectoryInfo's
Sorry if this is getting confusing; I will post the code for the page, if you like
Thanks for trying to help
Mark
Why don't you build a full path when you are retriving these files and then just assign it to link control?
E.G.
When you call directory.GetFiles() why not create a column where the link to the file is going to be and just assign that fileld in href?
This is simple and effective solution without "breaking walls" or anything like that.
If you see it difficult, please post a code for GetFiles() function so I can set it up for you.
E.G.
When you call directory.GetFiles() why not create a column where the link to the file is going to be and just assign that fileld in href?
This is simple and effective solution without "breaking walls" or anything like that.
If you see it difficult, please post a code for GetFiles() function so I can set it up for you.
ASKER
Sounds good to me! Here's the whoooooole thing:
Partial Class FileDnLoad
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim node As TreeNode = New TreeNode()
'-- strPlanID is a 6-digit account #, formatted with leading zero's
node.Value = "C:\Websites\WebProject\Cl ientArea\P DFs\" & Session("strPlanID") & "\"
node.Text = "Client " & Session("strPlanID")
LoadDirectories(node, "C:\Websites\WebProject\Cl ientArea\P DFs\" & Session("strPlanID") & "\")
Me.TreeView1.Nodes.Add(nod e)
End If
End Sub
Private Sub LoadDirectories(ByVal parent As TreeNode, ByVal path As String)
Dim directory As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(pa th)
Try
For Each d As System.IO.DirectoryInfo In directory.GetDirectories()
Dim node As TreeNode = New TreeNode(d.Name, d.FullName)
parent.ChildNodes.Add(node )
'Recurse the current directory
LoadDirectories(node, d.FullName)
Next
Catch ex As System.UnauthorizedAccessE xception
parent.Text += " (Access Denied)"
Catch ex As Exception
parent.Text += " (Unknown Error: " + ex.Message + ")"
End Try
End Sub
Protected Sub TreeView1_SelectedNodeChan ged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChan ged
Dim directory As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(Me .TreeView1 .SelectedN ode.Value)
Me.GridView1.DataSource = directory.GetFiles()
Me.GridView1.DataBind()
End Sub
End Class
Partial Class FileDnLoad
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim node As TreeNode = New TreeNode()
'-- strPlanID is a 6-digit account #, formatted with leading zero's
node.Value = "C:\Websites\WebProject\Cl
node.Text = "Client " & Session("strPlanID")
LoadDirectories(node, "C:\Websites\WebProject\Cl
Me.TreeView1.Nodes.Add(nod
End If
End Sub
Private Sub LoadDirectories(ByVal parent As TreeNode, ByVal path As String)
Dim directory As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(pa
Try
For Each d As System.IO.DirectoryInfo In directory.GetDirectories()
Dim node As TreeNode = New TreeNode(d.Name, d.FullName)
parent.ChildNodes.Add(node
'Recurse the current directory
LoadDirectories(node, d.FullName)
Next
Catch ex As System.UnauthorizedAccessE
parent.Text += " (Access Denied)"
Catch ex As Exception
parent.Text += " (Unknown Error: " + ex.Message + ")"
End Try
End Sub
Protected Sub TreeView1_SelectedNodeChan
Dim directory As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(Me
Me.GridView1.DataSource = directory.GetFiles()
Me.GridView1.DataBind()
End Sub
End Class
Please send me the html code of your datagrid.
ASKER
<%@ Page Language="VB" MasterPageFile="~/MasterPa ge.master" AutoEventWireup="false" CodeFile="FileDnLoad.aspx. vb" Inherits="FileDnLoad" title="WebProject: File Download" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main Content" Runat="Server">
<h3>File Download</h3>
<hr />
<h4>To download a report, select the desired year, then click the link of the desired report. You will then be prompted to "Open" or "Save" the report. </h4>
<table width="100%" border=0 cellspacing=1>
<tr></tr>
<tr>
<td style="width: 20%" valign="top">
<asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows" Font-Size="Medium">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px"
VerticalPadding="0px" ForeColor="#5555DD" />
<NodeStyle Font-Names="Verdana" Font-Size="10pt" ForeColor="Black" HorizontalPadding="5px"
NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
</td>
<td style="width: 80%" valign="top">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False " BackColor="White" BorderColor="#999999"
BorderStyle="None" BorderWidth="1px" CellPadding="1" GridLines="Vertical" Font-Size="Small">
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="#E0E0E0" Font-Bold="True" ForeColor="Black" HorizontalAlign="Center" VerticalAlign="Top" />
<AlternatingRowStyle BackColor="Gainsboro" />
<Columns>
<asp:HyperLinkField
DataNavigateUrlFields="Nam e"
DataNavigateUrlFormatStrin g="\WebPro ject\Clien tArea\PDFs \000164\20 03\{0}"
DataTextField="Name"
HeaderText="File Name" />
<asp:BoundField DataField="Length" HeaderText="Size">
<ItemStyle HorizontalAlign="Right" Width="12%" />
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="LastWriteTime" HeaderText="Date Modified">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
<ItemStyle Width="30%" />
</asp:BoundField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
<br />
<h4>You will need the Adobe Reader to view these reports, which can be downloaded for free from
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="http://www.adobe.com/products/acrobat/readstep2.html">Adobe's website</asp:HyperLink>.
</h4>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="Main
<h3>File Download</h3>
<hr />
<h4>To download a report, select the desired year, then click the link of the desired report. You will then be prompted to "Open" or "Save" the report. </h4>
<table width="100%" border=0 cellspacing=1>
<tr></tr>
<tr>
<td style="width: 20%" valign="top">
<asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows" Font-Size="Medium">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px"
VerticalPadding="0px" ForeColor="#5555DD" />
<NodeStyle Font-Names="Verdana" Font-Size="10pt" ForeColor="Black" HorizontalPadding="5px"
NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
</td>
<td style="width: 80%" valign="top">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False
BorderStyle="None" BorderWidth="1px" CellPadding="1" GridLines="Vertical" Font-Size="Small">
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="#E0E0E0" Font-Bold="True" ForeColor="Black" HorizontalAlign="Center" VerticalAlign="Top" />
<AlternatingRowStyle BackColor="Gainsboro" />
<Columns>
<asp:HyperLinkField
DataNavigateUrlFields="Nam
DataNavigateUrlFormatStrin
DataTextField="Name"
HeaderText="File Name" />
<asp:BoundField DataField="Length" HeaderText="Size">
<ItemStyle HorizontalAlign="Right" Width="12%" />
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="LastWriteTime" HeaderText="Date Modified">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
<ItemStyle Width="30%" />
</asp:BoundField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
<br />
<h4>You will need the Adobe Reader to view these reports, which can be downloaded for free from
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="http://www.adobe.com/products/acrobat/readstep2.html">Adobe's website</asp:HyperLink>.
</h4>
</asp:Content>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Don't forget to replace (Client#) and (Year()) with data that you are getting from login and dropdownlist.
ASKER
THANKS!
But - is this in VB? I'm getting error flags on:
"As FileInfo" - should this be IO.FileInfo?
"As DataTable" - should this be Data.DataTable?
Thanks again, aki4u
Mark
But - is this in VB? I'm getting error flags on:
"As FileInfo" - should this be IO.FileInfo?
"As DataTable" - should this be Data.DataTable?
Thanks again, aki4u
Mark
Add this at the top of your page:
Imports System.Data
Imports System.IO
Imports System.Data
Imports System.IO
ASKER
That does it!
Thank you very much, aki4u!
Can I contact you offline? If so, please reply to mlagrange@myway.com
Thanks again
Mark
Thank you very much, aki4u!
Can I contact you offline? If so, please reply to mlagrange@myway.com
Thanks again
Mark
<TemplateColumn>
<ItemTemplate>
<a href='MyPage.aspx?FileName
</ItemTemplate>
</TemplateColumn>
Notice the use of single quotes in a tag.
-Nauman.