Solved

DataNavigateUrlFormatString Question

Posted on 2009-04-02
2
257 Views
Last Modified: 2012-08-13
I am using Visual Studio 2003 and using a datagrid to display and link to files in a certain folder. Originally, the files were all pdf but now, I need to link to other types of files.
The files exist in a virtual directory on the intranet server.
I list the files in the datagrid without the file extension but I will need the extension for the hyperlink in the datagrid.
I'm attaching the code that gets the files into an array without the file extension.
I set up the variable "fn" to hold the filename with the extension but I'm not exactly sure how to get it.
And then I need to reference it in the datagrid:
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataNavigateUrlFormatString="http://myintranet.com/p1/csr/" ??? DataTextField="Name" Target="_blank">
The ??? is where I need help
I hope this makes sense.
Thanks!
Dim dirInfo as New DirectoryInfo(Server.MapPath("/p1/csr"))		

Dim arrFileInfo  As Array

Dim filesInfo   As FileInfo

Dim filesTable   As New DataTable

Dim drFiles    As DataRow

Dim dvFiles   As DataView

Dim ofn,ext As String

Dim charCt as Integer

Dim fn as String

				

filesTable.Columns.Add("Name", Type.GetType("System.String"))

filesTable.Columns.Add("LastWriteTime", Type.GetType("System.DateTime"))

		

' Get File Info

arrFileInfo = dirInfo.GetFiles

For Each filesInfo In arrFileInfo

  drFiles = filesTable.NewRow()

  drFiles("Name") = System.IO.Path.GetFileNameWithoutExtension(filesInfo.Name)

  drFiles("LastWriteTime") = filesInfo.LastWriteTime					

  filesTable.Rows.Add(drFiles)

Next filesInfo

				

dvFiles = filesTable.DefaultView

dvFiles.Sort = "LastWriteTime DESC"
 

dg1.DataSource = dvFiles

dg1.DataBind()

Open in new window

0
Comment
Question by:lakhi
2 Comments
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 500 total points
ID: 24057665
Hi lakhi,
You can define another column to store the exact file name. Then, bind this datafield under part of required parameter(s) inside DataNavigateUrlFormatString property.
http://geekswithblogs.net/AzamSharp/archive/2006/09/18/91514.aspx

eg:

vb
==========
filesTable.Columns.Add("FileName", Type.GetType("System.String"))'this column to store exact file name
filesTable.Columns.Add("Name", Type.GetType("System.String"))
....

  drFiles = filesTable.NewRow()
  drFiles("FileName") = filesInfo.Name
  drFiles("Name") = System.IO.Path.GetFileNameWithoutExtension(filesInfo.Name)
  ...

aspx
========
<asp:HyperLinkColumn DataNavigateUrlField="FileName" DataNavigateUrlFormatString="http://myintranet.com/p1/csr/{0}" DataTextField="Name" Target="_blank">

0
 

Author Comment

by:lakhi
ID: 24061487
Perfect! That's just what I needed. Thanks!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now