473,232 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,232 software developers and data experts.

GridView HyperLinkField problem...

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

Jan 31 '07 #1
8 9632
bpd
On Jan 31, 1:31 pm, Mike Rand <MikeR...@discussions.microsoft.com>
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?

Jan 31 '07 #2
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" wrote:
On Jan 31, 1:31 pm, Mike Rand <MikeR...@discussions.microsoft.com>
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?

Jan 31 '07 #3
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" wrote:
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" wrote:
On Jan 31, 1:31 pm, Mike Rand <MikeR...@discussions.microsoft.com>
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?
Feb 1 '07 #4
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 [MCAD]" wrote:
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" wrote:
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" wrote:
On Jan 31, 1:31 pm, Mike Rand <MikeR...@discussions.microsoft.com>
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?
>
>
Feb 1 '07 #5
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" wrote:
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 [MCAD]" wrote:
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" wrote:
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" wrote:
>
On Jan 31, 1:31 pm, Mike Rand <MikeR...@discussions.microsoft.com>
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?
Feb 1 '07 #6
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 [MCAD]" wrote:
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" wrote:
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 [MCAD]" wrote:
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" wrote:
>
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" wrote:

On Jan 31, 1:31 pm, Mike Rand <MikeR...@discussions.microsoft.com>
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?
>
>
Feb 1 '07 #7
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" wrote:
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 [MCAD]" wrote:
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" wrote:
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 [MCAD]" wrote:
>
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" wrote:

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" wrote:
>
On Jan 31, 1:31 pm, Mike Rand <MikeR...@discussions.microsoft.com>
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?
Feb 2 '07 #8
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 [MCAD]" wrote:
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" wrote:
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 [MCAD]" wrote:
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" wrote:
>
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 [MCAD]" wrote:

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" wrote:
>
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" wrote:

On Jan 31, 1:31 pm, Mike Rand <MikeR...@discussions.microsoft.com>
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?
>
>
Feb 2 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: willip | last post by:
I have a Gridview control with a Databound Hyperlink. e.g.: <asp:HyperLinkField HeaderText="MyTitle" DataNavigateUrlFields="MyID" DataNavigateUrlFormatString="~/ShowMe.aspx?MyID={0}"...
1
by: le0 | last post by:
Guys, Im a newbies in asp.net and i have this big prob. How can i get the ID or the primary key of a table? Im using GridView to display all the data. I want to pass that value to another page...
2
by: SP | last post by:
Hi, I need a GridView that when I click on a row or on a HyperLinkField a javascript call raise . It is possible? The grid is in a window open from a parent window. Onclick in a row selected,...
0
by: CK | last post by:
Hi All, I have a gridview that contains a column that has a repeater inside it. My intent is to put every comment for an album into the repeater in the comments column. I am using a SQLDataSource...
0
by: joebob8000 | last post by:
This seems like a simple task, but my 6 year old roots in classic ASP must be causing me trouble with my current problem. I am looking to provide a search for users in which they can select...
0
by: rmgalante | last post by:
Hi, I've been experimenting with the ASP.Net GridView and encountered some interesting issues that I thought I would share. I have a page that loads a GridView with a generic collection of...
0
by: bodamithun | last post by:
Hi all, For some weird reason my hyperlinkfield does not work. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" > ...
1
by: boevermann | last post by:
I prototyped an html table that has a hyperlink that pops a window showing a map of the entry from the that table. The link looks like this: <a href="authenticate.asp"...
1
by: sweatha | last post by:
Hi I connected SQLDataSource in GridView by using coding <asp:GridView ID="Search_GridView" runat="server" Style="z-index: 100; left: 2px; position: absolute; top: 270px"...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.