?
Solved

DataNavigateUrlFormatString Question

Posted on 2009-04-02
2
Medium Priority
?
272 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 2000 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

Technology Partners: 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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

752 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