471,582 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,582 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 9522
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by le0 | last post: by
reply views Thread by CK | last post: by
reply views Thread by rmgalante | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
1 post views Thread by lumer26 | last post: by

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.