473,498 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9642
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
1260
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
324
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
17399
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
989
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
2735
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
4809
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
1262
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
11439
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
1154
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"...
0
7203
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.