How to dynamically add current item name to HyperLinkField

I am displaying file names from a document library. I want this name to be click able.

So let's say if file name being displayed is: my file.docx

When user clicks, it should take user to its respective item in document library: http://myserver/mylibrary/my file.docx

I am using following code to display file names but problem is I am unable to get current item name and it is actually displayed as: http://myserver/mylibrary/LinkFilename

name = new HyperLinkField();

name.DataTextField = "LinkFilename";

name.SortExpression = "LinkFilename";

name.HeaderText = "File Name";

name.NavigateUrl = SPContext.Current.Site.Url + "/" + libraryTitle + "/" + name.DataTextField;

grid.Columns.Add(name);

August 16th, 2015 4:34am

You can also try XSLT which need no server coding

https://www.youtube.com/watch?v=r2eODYHp73A

Free Windows Admin Tool Kit Click here and download it now
August 16th, 2015 11:39am

Found the solution:

name = new HyperLinkField();           

name.DataTextField = "LinkFilename";           

name.SortExpression = "LinkFilename";           

name.HeaderText = "File Name";           

name.DataNavigateUrlFields = new string[] { "LinkFilename" };           

name.DataNavigateUrlFormatString = SPContext.Current.Site.Url + mainSiteURL + "/" + libraryTitle + "/{0}";           

grid.Columns.Add(name);

August 17th, 2015 2:27am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics