Solved

DataNavigateUrlFormatString Question

Posted on 2009-04-02
2
254 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
Comment Utility
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
Comment Utility
Perfect! That's just what I needed. Thanks!!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

18 Experts available now in Live!

Get 1:1 Help Now