Solved

DataNavigateUrlFormatString Question

Posted on 2009-04-02
2
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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