Parsing a Path to the Server
-
Hello all I had posted this question in the wrong forum and was asked to move it here. I'm trying to download a file from a folder on the server but I don't know how to parse the path inside of the HREF attribute of the anchor tage. I'm trying to modify the following code to be used with HTML anchor tag:
protected void Page_PreRender(object sender, EventArgs e)
{
DataTable dt = new DataTable("INFO");
dt.Columns.Add("url", typeof(string));string\[\] fileEntries = Directory.GetFiles(Server.MapPath("~/Documents/")); dt.Rows.Add("~/Documents/" + Path.GetFileName(fileName)); grid.DataSource = dt; grid.DataBind(); }
I wanted to do something like the following on my Page.aspx file:
However, the above cannot be done. Please help me find and alternative, thanks in advance for your help.
-
Hello all I had posted this question in the wrong forum and was asked to move it here. I'm trying to download a file from a folder on the server but I don't know how to parse the path inside of the HREF attribute of the anchor tage. I'm trying to modify the following code to be used with HTML anchor tag:
protected void Page_PreRender(object sender, EventArgs e)
{
DataTable dt = new DataTable("INFO");
dt.Columns.Add("url", typeof(string));string\[\] fileEntries = Directory.GetFiles(Server.MapPath("~/Documents/")); dt.Rows.Add("~/Documents/" + Path.GetFileName(fileName)); grid.DataSource = dt; grid.DataBind(); }
I wanted to do something like the following on my Page.aspx file:
However, the above cannot be done. Please help me find and alternative, thanks in advance for your help.
Modify it like
protected void Page_PreRender(object sender, EventArgs e)
{
DataTable dt = new DataTable("INFO");
dt.Columns.Add("url", typeof(string));string\[\] fileEntries = Directory.GetFiles(Server.MapPath("~/Documents/")); foreach (string f in fileEntries) { DataRow dr = dt.NewRow(); dr\["url"\] = " [DOWNLOAD](~/Documents/" + Path.GetFileName\(f\) + ") "; dt.Rows.Add(dr); } grid.DataSource = dt; grid.DataBind(); }
-
Modify it like
protected void Page_PreRender(object sender, EventArgs e)
{
DataTable dt = new DataTable("INFO");
dt.Columns.Add("url", typeof(string));string\[\] fileEntries = Directory.GetFiles(Server.MapPath("~/Documents/")); foreach (string f in fileEntries) { DataRow dr = dt.NewRow(); dr\["url"\] = " [DOWNLOAD](~/Documents/" + Path.GetFileName\(f\) + ") "; dt.Rows.Add(dr); } grid.DataSource = dt; grid.DataBind(); }
Hum Dum wrote:
dr["url"] = "<a href='~/Documents/" + Path.GetFileName(f) + "'> DOWNLOAD </a>";
That just posts a string as the anchor tag, and doesn't resolve the
~
. That's the bit he needs help with.*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
Hum Dum wrote:
dr["url"] = "<a href='~/Documents/" + Path.GetFileName(f) + "'> DOWNLOAD </a>";
That just posts a string as the anchor tag, and doesn't resolve the
~
. That's the bit he needs help with.*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
A couple of ways to resolve urls. Virtual Path Utility[^] http://refactoringaspnet.blogspot.com/2009/09/different-approaches-for-resolving-urls.html[^]
-
A couple of ways to resolve urls. Virtual Path Utility[^] http://refactoringaspnet.blogspot.com/2009/09/different-approaches-for-resolving-urls.html[^]
Try replying to the OP, rather than me. He won't get emailed about answers to me.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier