GridView HyperLinkField problem...

G

Guest

I am trying to get a list of files from a specified directory using the
System.IO namespace classes, and then use that list as the datasource for a
GridView. I have been able to do this successfully.

The problem is when I try to hook up a HyperLinkField it's not working.
Basically, what I want to end up with is to have the file name listed in the
column and have the link point to the full file path, for each file in the
list. I've been attempting to use the DataNavigateUrlFields property with no
success, it seems to recognize some fields but not others (for example, it
will recognize the field "name", but not "directory", with the former a
HyperLink will be created, but that later it will not, even though you can
see the directory in debug mode).

Any ideas, would be greatly appreciated!
Thanks,
- Mike
 
B

bpd

I am trying to get a list of files from a specified directory using the
System.IO namespace classes, and then use that list as the datasource for a
GridView. I have been able to do this successfully.

The problem is when I try to hook up a HyperLinkField it's not working.
Basically, what I want to end up with is to have the file name listed in the
column and have the link point to the full file path, for each file in the
list. I've been attempting to use the DataNavigateUrlFields property with no
success, it seems to recognize some fields but not others (for example, it
will recognize the field "name", but not "directory", with the former a
HyperLink will be created, but that later it will not, even though you can
see the directory in debug mode).

Any ideas, would be greatly appreciated!
Thanks,
- Mike

How are you hooking up the HL field? Can you show us your code?
 
G

Guest

bpd,
Here is the latest version (I have modified this several times, with no
success):

FileInfo[] myList = StoresServ.stores.getDocList_New();
gvwFiles.DataSource = myList;

gvwFiles.Columns.Add(new HyperLinkField());
HyperLinkField hfld = (HyperLinkField)gvwFiles.Columns[0];
hfld.DataNavigateUrlFields = new string[] { "FullName" };
hfld.DataNavigateUrlFormatString = "{0}";
hfld.DataTextField = "name";
gvwFiles.DataBind();

Thanks for taking the time to look at this!
- Mike
 
G

Guest

Hi Mike,

I prepared a working example for you. Importnat note: if your document
folder is not a part of the web application you have to map it under IIS (for
below example I simply created an empty folder called Documents in
application's root and put some tex files in it).

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateData();
}
}

private void PopulateData()
{
const string DocumentVirtualPath = "~/Documents/";

HyperLinkField hyperLinkField = new HyperLinkField();
hyperLinkField.DataTextField = "FullName";
hyperLinkField.DataNavigateUrlFields = new string[] { "Name" };
hyperLinkField.DataNavigateUrlFormatString =
ResolveUrl(DocumentVirtualPath) + "{0}";

gridView.Columns.Add(hyperLinkField);
gridView.DataSource = GetDocuments(DocumentVirtualPath);
gridView.DataBind();
}

private System.IO.FileInfo[] GetDocuments(string relativePath)
{
string physicalPath = Server.MapPath(relativePath);

System.IO.DirectoryInfo directory =
new System.IO.DirectoryInfo(physicalPath);

if (directory.Exists)
{
return directory.GetFiles();
}
else
{
throw new System.IO.DirectoryNotFoundException(physicalPath);
}
}


Hope this helps
--
Milosz


Mike Rand said:
bpd,
Here is the latest version (I have modified this several times, with no
success):

FileInfo[] myList = StoresServ.stores.getDocList_New();
gvwFiles.DataSource = myList;

gvwFiles.Columns.Add(new HyperLinkField());
HyperLinkField hfld = (HyperLinkField)gvwFiles.Columns[0];
hfld.DataNavigateUrlFields = new string[] { "FullName" };
hfld.DataNavigateUrlFormatString = "{0}";
hfld.DataTextField = "name";
gvwFiles.DataBind();

Thanks for taking the time to look at this!
- Mike

bpd said:
How are you hooking up the HL field? Can you show us your code?
 
G

Guest

Milosz,
Your example worked (unaltered). To do what I need to be able to do I mapped
a folder in IIS under the project as you suggested. But, I was unable to use
it as a Virtual Path (e.g., "~/MyNewFolder/", which points to a folder
outside the application directory) in the code. So, I tried to use the fully
qualified path. This worked but I had to comment out the Server.MapPath line
of code. This allowed me to see the files in that folder, but again they
weren't links.

Where am I going wrong with this?
Thanks,
- Mike


Milosz Skalecki said:
Hi Mike,

I prepared a working example for you. Importnat note: if your document
folder is not a part of the web application you have to map it under IIS (for
below example I simply created an empty folder called Documents in
application's root and put some tex files in it).

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateData();
}
}

private void PopulateData()
{
const string DocumentVirtualPath = "~/Documents/";

HyperLinkField hyperLinkField = new HyperLinkField();
hyperLinkField.DataTextField = "FullName";
hyperLinkField.DataNavigateUrlFields = new string[] { "Name" };
hyperLinkField.DataNavigateUrlFormatString =
ResolveUrl(DocumentVirtualPath) + "{0}";

gridView.Columns.Add(hyperLinkField);
gridView.DataSource = GetDocuments(DocumentVirtualPath);
gridView.DataBind();
}

private System.IO.FileInfo[] GetDocuments(string relativePath)
{
string physicalPath = Server.MapPath(relativePath);

System.IO.DirectoryInfo directory =
new System.IO.DirectoryInfo(physicalPath);

if (directory.Exists)
{
return directory.GetFiles();
}
else
{
throw new System.IO.DirectoryNotFoundException(physicalPath);
}
}


Hope this helps
--
Milosz


Mike Rand said:
bpd,
Here is the latest version (I have modified this several times, with no
success):

FileInfo[] myList = StoresServ.stores.getDocList_New();
gvwFiles.DataSource = myList;

gvwFiles.Columns.Add(new HyperLinkField());
HyperLinkField hfld = (HyperLinkField)gvwFiles.Columns[0];
hfld.DataNavigateUrlFields = new string[] { "FullName" };
hfld.DataNavigateUrlFormatString = "{0}";
hfld.DataTextField = "name";
gvwFiles.DataBind();

Thanks for taking the time to look at this!
- Mike

bpd said:
On Jan 31, 1:31 pm, Mike Rand <[email protected]>
wrote:
I am trying to get a list of files from a specified directory using the
System.IO namespace classes, and then use that list as the datasource for a
GridView. I have been able to do this successfully.

The problem is when I try to hook up a HyperLinkField it's not working.
Basically, what I want to end up with is to have the file name listed in the
column and have the link point to the full file path, for each file in the
list. I've been attempting to use the DataNavigateUrlFields property with no
success, it seems to recognize some fields but not others (for example, it
will recognize the field "name", but not "directory", with the former a
HyperLink will be created, but that later it will not, even though you can
see the directory in debug mode).

Any ideas, would be greatly appreciated!
Thanks,
- Mike

How are you hooking up the HL field? Can you show us your code?
 
G

Guest

No worries Mike,

You have to amend the code a little bit. Because documents directory is
outside application, you have to know its physical location (in previous
example i used server.mappath to automatically determine virtual directory
phycical location). The only difference now, you must know both, full url to
the document folder exposed through IIS and physical location in ordrer to
get file list (remember asp.net account need read permission on this folder):

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateData();
}
}

private void PopulateData()
{
const string DocumentFolderPhysicalPath =
"c:\\temp\\physicaldocumentlocation\\";
const string DocumentFolderUrl =
"http://localhost/virtualfoldernameyouexposed/"; // now it is hardcoded but
you could retreive it automatically

HyperLinkField hyperLinkField = new HyperLinkField();
hyperLinkField.DataTextField = "FullName";
hyperLinkField.DataNavigateUrlFields = new string[] { "Name" };
hyperLinkField.DataNavigateUrlFormatString = DocumentFolderUrl + "{0}";

gridView.Columns.Add(hyperLinkField);
gridView.DataSource = GetDocuments(DocumentFolderPhysicalPath);
gridView.DataBind();
}

private System.IO.FileInfo[] GetDocuments(string physicalPath)
{
System.IO.DirectoryInfo directory =
new System.IO.DirectoryInfo(physicalPath);

if (directory.Exists)
{
return directory.GetFiles();
}
else
{
throw new System.IO.DirectoryNotFoundException(physicalPath);
}
}

I don't have IIS at home so i cannot test it, but it should work.

Hope this helps

--
Milosz


Mike Rand said:
Milosz,
Your example worked (unaltered). To do what I need to be able to do I mapped
a folder in IIS under the project as you suggested. But, I was unable to use
it as a Virtual Path (e.g., "~/MyNewFolder/", which points to a folder
outside the application directory) in the code. So, I tried to use the fully
qualified path. This worked but I had to comment out the Server.MapPath line
of code. This allowed me to see the files in that folder, but again they
weren't links.

Where am I going wrong with this?
Thanks,
- Mike


Milosz Skalecki said:
Hi Mike,

I prepared a working example for you. Importnat note: if your document
folder is not a part of the web application you have to map it under IIS (for
below example I simply created an empty folder called Documents in
application's root and put some tex files in it).

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateData();
}
}

private void PopulateData()
{
const string DocumentVirtualPath = "~/Documents/";

HyperLinkField hyperLinkField = new HyperLinkField();
hyperLinkField.DataTextField = "FullName";
hyperLinkField.DataNavigateUrlFields = new string[] { "Name" };
hyperLinkField.DataNavigateUrlFormatString =
ResolveUrl(DocumentVirtualPath) + "{0}";

gridView.Columns.Add(hyperLinkField);
gridView.DataSource = GetDocuments(DocumentVirtualPath);
gridView.DataBind();
}

private System.IO.FileInfo[] GetDocuments(string relativePath)
{
string physicalPath = Server.MapPath(relativePath);

System.IO.DirectoryInfo directory =
new System.IO.DirectoryInfo(physicalPath);

if (directory.Exists)
{
return directory.GetFiles();
}
else
{
throw new System.IO.DirectoryNotFoundException(physicalPath);
}
}


Hope this helps
--
Milosz


Mike Rand said:
bpd,
Here is the latest version (I have modified this several times, with no
success):

FileInfo[] myList = StoresServ.stores.getDocList_New();
gvwFiles.DataSource = myList;

gvwFiles.Columns.Add(new HyperLinkField());
HyperLinkField hfld = (HyperLinkField)gvwFiles.Columns[0];
hfld.DataNavigateUrlFields = new string[] { "FullName" };
hfld.DataNavigateUrlFormatString = "{0}";
hfld.DataTextField = "name";
gvwFiles.DataBind();

Thanks for taking the time to look at this!
- Mike

:

On Jan 31, 1:31 pm, Mike Rand <[email protected]>
wrote:
I am trying to get a list of files from a specified directory using the
System.IO namespace classes, and then use that list as the datasource for a
GridView. I have been able to do this successfully.

The problem is when I try to hook up a HyperLinkField it's not working.
Basically, what I want to end up with is to have the file name listed in the
column and have the link point to the full file path, for each file in the
list. I've been attempting to use the DataNavigateUrlFields property with no
success, it seems to recognize some fields but not others (for example, it
will recognize the field "name", but not "directory", with the former a
HyperLink will be created, but that later it will not, even though you can
see the directory in debug mode).

Any ideas, would be greatly appreciated!
Thanks,
- Mike

How are you hooking up the HL field? Can you show us your code?
 
G

Guest

Milosz,
Thanks for helping me with this problem. The only problem that I am
encountering now is that the links start with "http://localhost/etc.", rather
than the true physical path. I tried a few settings in IIS, but no success.
Thanks,
- Mike

Milosz Skalecki said:
No worries Mike,

You have to amend the code a little bit. Because documents directory is
outside application, you have to know its physical location (in previous
example i used server.mappath to automatically determine virtual directory
phycical location). The only difference now, you must know both, full url to
the document folder exposed through IIS and physical location in ordrer to
get file list (remember asp.net account need read permission on this folder):

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateData();
}
}

private void PopulateData()
{
const string DocumentFolderPhysicalPath =
"c:\\temp\\physicaldocumentlocation\\";
const string DocumentFolderUrl =
"http://localhost/virtualfoldernameyouexposed/"; // now it is hardcoded but
you could retreive it automatically

HyperLinkField hyperLinkField = new HyperLinkField();
hyperLinkField.DataTextField = "FullName";
hyperLinkField.DataNavigateUrlFields = new string[] { "Name" };
hyperLinkField.DataNavigateUrlFormatString = DocumentFolderUrl + "{0}";

gridView.Columns.Add(hyperLinkField);
gridView.DataSource = GetDocuments(DocumentFolderPhysicalPath);
gridView.DataBind();
}

private System.IO.FileInfo[] GetDocuments(string physicalPath)
{
System.IO.DirectoryInfo directory =
new System.IO.DirectoryInfo(physicalPath);

if (directory.Exists)
{
return directory.GetFiles();
}
else
{
throw new System.IO.DirectoryNotFoundException(physicalPath);
}
}

I don't have IIS at home so i cannot test it, but it should work.

Hope this helps

--
Milosz


Mike Rand said:
Milosz,
Your example worked (unaltered). To do what I need to be able to do I mapped
a folder in IIS under the project as you suggested. But, I was unable to use
it as a Virtual Path (e.g., "~/MyNewFolder/", which points to a folder
outside the application directory) in the code. So, I tried to use the fully
qualified path. This worked but I had to comment out the Server.MapPath line
of code. This allowed me to see the files in that folder, but again they
weren't links.

Where am I going wrong with this?
Thanks,
- Mike


Milosz Skalecki said:
Hi Mike,

I prepared a working example for you. Importnat note: if your document
folder is not a part of the web application you have to map it under IIS (for
below example I simply created an empty folder called Documents in
application's root and put some tex files in it).

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateData();
}
}

private void PopulateData()
{
const string DocumentVirtualPath = "~/Documents/";

HyperLinkField hyperLinkField = new HyperLinkField();
hyperLinkField.DataTextField = "FullName";
hyperLinkField.DataNavigateUrlFields = new string[] { "Name" };
hyperLinkField.DataNavigateUrlFormatString =
ResolveUrl(DocumentVirtualPath) + "{0}";

gridView.Columns.Add(hyperLinkField);
gridView.DataSource = GetDocuments(DocumentVirtualPath);
gridView.DataBind();
}

private System.IO.FileInfo[] GetDocuments(string relativePath)
{
string physicalPath = Server.MapPath(relativePath);

System.IO.DirectoryInfo directory =
new System.IO.DirectoryInfo(physicalPath);

if (directory.Exists)
{
return directory.GetFiles();
}
else
{
throw new System.IO.DirectoryNotFoundException(physicalPath);
}
}


Hope this helps
--
Milosz


:

bpd,
Here is the latest version (I have modified this several times, with no
success):

FileInfo[] myList = StoresServ.stores.getDocList_New();
gvwFiles.DataSource = myList;

gvwFiles.Columns.Add(new HyperLinkField());
HyperLinkField hfld = (HyperLinkField)gvwFiles.Columns[0];
hfld.DataNavigateUrlFields = new string[] { "FullName" };
hfld.DataNavigateUrlFormatString = "{0}";
hfld.DataTextField = "name";
gvwFiles.DataBind();

Thanks for taking the time to look at this!
- Mike

:

On Jan 31, 1:31 pm, Mike Rand <[email protected]>
wrote:
I am trying to get a list of files from a specified directory using the
System.IO namespace classes, and then use that list as the datasource for a
GridView. I have been able to do this successfully.

The problem is when I try to hook up a HyperLinkField it's not working.
Basically, what I want to end up with is to have the file name listed in the
column and have the link point to the full file path, for each file in the
list. I've been attempting to use the DataNavigateUrlFields property with no
success, it seems to recognize some fields but not others (for example, it
will recognize the field "name", but not "directory", with the former a
HyperLink will be created, but that later it will not, even though you can
see the directory in debug mode).

Any ideas, would be greatly appreciated!
Thanks,
- Mike

How are you hooking up the HL field? Can you show us your code?
 
G

Guest

That's desired result - you cannot allow people to see true, physical
location files on the server or i got you wrong and you're building server
file browser to show the content of the server directory?

Regards
--
Milosz


Mike Rand said:
Milosz,
Thanks for helping me with this problem. The only problem that I am
encountering now is that the links start with "http://localhost/etc.", rather
than the true physical path. I tried a few settings in IIS, but no success.
Thanks,
- Mike

Milosz Skalecki said:
No worries Mike,

You have to amend the code a little bit. Because documents directory is
outside application, you have to know its physical location (in previous
example i used server.mappath to automatically determine virtual directory
phycical location). The only difference now, you must know both, full url to
the document folder exposed through IIS and physical location in ordrer to
get file list (remember asp.net account need read permission on this folder):

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateData();
}
}

private void PopulateData()
{
const string DocumentFolderPhysicalPath =
"c:\\temp\\physicaldocumentlocation\\";
const string DocumentFolderUrl =
"http://localhost/virtualfoldernameyouexposed/"; // now it is hardcoded but
you could retreive it automatically

HyperLinkField hyperLinkField = new HyperLinkField();
hyperLinkField.DataTextField = "FullName";
hyperLinkField.DataNavigateUrlFields = new string[] { "Name" };
hyperLinkField.DataNavigateUrlFormatString = DocumentFolderUrl + "{0}";

gridView.Columns.Add(hyperLinkField);
gridView.DataSource = GetDocuments(DocumentFolderPhysicalPath);
gridView.DataBind();
}

private System.IO.FileInfo[] GetDocuments(string physicalPath)
{
System.IO.DirectoryInfo directory =
new System.IO.DirectoryInfo(physicalPath);

if (directory.Exists)
{
return directory.GetFiles();
}
else
{
throw new System.IO.DirectoryNotFoundException(physicalPath);
}
}

I don't have IIS at home so i cannot test it, but it should work.

Hope this helps

--
Milosz


Mike Rand said:
Milosz,
Your example worked (unaltered). To do what I need to be able to do I mapped
a folder in IIS under the project as you suggested. But, I was unable to use
it as a Virtual Path (e.g., "~/MyNewFolder/", which points to a folder
outside the application directory) in the code. So, I tried to use the fully
qualified path. This worked but I had to comment out the Server.MapPath line
of code. This allowed me to see the files in that folder, but again they
weren't links.

Where am I going wrong with this?
Thanks,
- Mike


:

Hi Mike,

I prepared a working example for you. Importnat note: if your document
folder is not a part of the web application you have to map it under IIS (for
below example I simply created an empty folder called Documents in
application's root and put some tex files in it).

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateData();
}
}

private void PopulateData()
{
const string DocumentVirtualPath = "~/Documents/";

HyperLinkField hyperLinkField = new HyperLinkField();
hyperLinkField.DataTextField = "FullName";
hyperLinkField.DataNavigateUrlFields = new string[] { "Name" };
hyperLinkField.DataNavigateUrlFormatString =
ResolveUrl(DocumentVirtualPath) + "{0}";

gridView.Columns.Add(hyperLinkField);
gridView.DataSource = GetDocuments(DocumentVirtualPath);
gridView.DataBind();
}

private System.IO.FileInfo[] GetDocuments(string relativePath)
{
string physicalPath = Server.MapPath(relativePath);

System.IO.DirectoryInfo directory =
new System.IO.DirectoryInfo(physicalPath);

if (directory.Exists)
{
return directory.GetFiles();
}
else
{
throw new System.IO.DirectoryNotFoundException(physicalPath);
}
}


Hope this helps
--
Milosz


:

bpd,
Here is the latest version (I have modified this several times, with no
success):

FileInfo[] myList = StoresServ.stores.getDocList_New();
gvwFiles.DataSource = myList;

gvwFiles.Columns.Add(new HyperLinkField());
HyperLinkField hfld = (HyperLinkField)gvwFiles.Columns[0];
hfld.DataNavigateUrlFields = new string[] { "FullName" };
hfld.DataNavigateUrlFormatString = "{0}";
hfld.DataTextField = "name";
gvwFiles.DataBind();

Thanks for taking the time to look at this!
- Mike

:

On Jan 31, 1:31 pm, Mike Rand <[email protected]>
wrote:
I am trying to get a list of files from a specified directory using the
System.IO namespace classes, and then use that list as the datasource for a
GridView. I have been able to do this successfully.

The problem is when I try to hook up a HyperLinkField it's not working.
Basically, what I want to end up with is to have the file name listed in the
column and have the link point to the full file path, for each file in the
list. I've been attempting to use the DataNavigateUrlFields property with no
success, it seems to recognize some fields but not others (for example, it
will recognize the field "name", but not "directory", with the former a
HyperLink will be created, but that later it will not, even though you can
see the directory in debug mode).

Any ideas, would be greatly appreciated!
Thanks,
- Mike

How are you hooking up the HL field? Can you show us your code?
 
G

Guest

Milosz,
The desired result is that the link will open the file that it points to. It
would be nice to be able to use a "virtual" path to hide the true file path,
but so far that doesn't work (the url uses the virtual path in the examples
that you've provided, but the links don't open the files). I'm thinking that
it's likely that I don't have the folder setup correctly in IIS (i.e., the
alias isn't being resolved to a true path properly). I'll have to read up on
setting up those paths and security settings correctly.
Thank you for all of your help with this, very much appreciated!
- Mike

Milosz Skalecki said:
That's desired result - you cannot allow people to see true, physical
location files on the server or i got you wrong and you're building server
file browser to show the content of the server directory?

Regards
--
Milosz


Mike Rand said:
Milosz,
Thanks for helping me with this problem. The only problem that I am
encountering now is that the links start with "http://localhost/etc.", rather
than the true physical path. I tried a few settings in IIS, but no success.
Thanks,
- Mike

Milosz Skalecki said:
No worries Mike,

You have to amend the code a little bit. Because documents directory is
outside application, you have to know its physical location (in previous
example i used server.mappath to automatically determine virtual directory
phycical location). The only difference now, you must know both, full url to
the document folder exposed through IIS and physical location in ordrer to
get file list (remember asp.net account need read permission on this folder):

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateData();
}
}

private void PopulateData()
{
const string DocumentFolderPhysicalPath =
"c:\\temp\\physicaldocumentlocation\\";
const string DocumentFolderUrl =
"http://localhost/virtualfoldernameyouexposed/"; // now it is hardcoded but
you could retreive it automatically

HyperLinkField hyperLinkField = new HyperLinkField();
hyperLinkField.DataTextField = "FullName";
hyperLinkField.DataNavigateUrlFields = new string[] { "Name" };
hyperLinkField.DataNavigateUrlFormatString = DocumentFolderUrl + "{0}";

gridView.Columns.Add(hyperLinkField);
gridView.DataSource = GetDocuments(DocumentFolderPhysicalPath);
gridView.DataBind();
}

private System.IO.FileInfo[] GetDocuments(string physicalPath)
{
System.IO.DirectoryInfo directory =
new System.IO.DirectoryInfo(physicalPath);

if (directory.Exists)
{
return directory.GetFiles();
}
else
{
throw new System.IO.DirectoryNotFoundException(physicalPath);
}
}

I don't have IIS at home so i cannot test it, but it should work.

Hope this helps

--
Milosz


:

Milosz,
Your example worked (unaltered). To do what I need to be able to do I mapped
a folder in IIS under the project as you suggested. But, I was unable to use
it as a Virtual Path (e.g., "~/MyNewFolder/", which points to a folder
outside the application directory) in the code. So, I tried to use the fully
qualified path. This worked but I had to comment out the Server.MapPath line
of code. This allowed me to see the files in that folder, but again they
weren't links.

Where am I going wrong with this?
Thanks,
- Mike


:

Hi Mike,

I prepared a working example for you. Importnat note: if your document
folder is not a part of the web application you have to map it under IIS (for
below example I simply created an empty folder called Documents in
application's root and put some tex files in it).

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateData();
}
}

private void PopulateData()
{
const string DocumentVirtualPath = "~/Documents/";

HyperLinkField hyperLinkField = new HyperLinkField();
hyperLinkField.DataTextField = "FullName";
hyperLinkField.DataNavigateUrlFields = new string[] { "Name" };
hyperLinkField.DataNavigateUrlFormatString =
ResolveUrl(DocumentVirtualPath) + "{0}";

gridView.Columns.Add(hyperLinkField);
gridView.DataSource = GetDocuments(DocumentVirtualPath);
gridView.DataBind();
}

private System.IO.FileInfo[] GetDocuments(string relativePath)
{
string physicalPath = Server.MapPath(relativePath);

System.IO.DirectoryInfo directory =
new System.IO.DirectoryInfo(physicalPath);

if (directory.Exists)
{
return directory.GetFiles();
}
else
{
throw new System.IO.DirectoryNotFoundException(physicalPath);
}
}


Hope this helps
--
Milosz


:

bpd,
Here is the latest version (I have modified this several times, with no
success):

FileInfo[] myList = StoresServ.stores.getDocList_New();
gvwFiles.DataSource = myList;

gvwFiles.Columns.Add(new HyperLinkField());
HyperLinkField hfld = (HyperLinkField)gvwFiles.Columns[0];
hfld.DataNavigateUrlFields = new string[] { "FullName" };
hfld.DataNavigateUrlFormatString = "{0}";
hfld.DataTextField = "name";
gvwFiles.DataBind();

Thanks for taking the time to look at this!
- Mike

:

On Jan 31, 1:31 pm, Mike Rand <[email protected]>
wrote:
I am trying to get a list of files from a specified directory using the
System.IO namespace classes, and then use that list as the datasource for a
GridView. I have been able to do this successfully.

The problem is when I try to hook up a HyperLinkField it's not working.
Basically, what I want to end up with is to have the file name listed in the
column and have the link point to the full file path, for each file in the
list. I've been attempting to use the DataNavigateUrlFields property with no
success, it seems to recognize some fields but not others (for example, it
will recognize the field "name", but not "directory", with the former a
HyperLink will be created, but that later it will not, even though you can
see the directory in debug mode).

Any ideas, would be greatly appreciated!
Thanks,
- Mike

How are you hooking up the HL field? Can you show us your code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top