I let users upload files using the asp.net upload control. I have a repeater on a page that list the files and users can click to download them:
protected void grdFiles_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.DataRow) return;
var fileNameFull = Common.FileHelper.UploadPath + e.Row.Cells[0].Text;
Request.MapPath(fileNameFull);
var hyp = new HyperLink
{
NavigateUrl = fileNameFull,
Text = e.Row.Cells[0].Text,
};
e.Row.Cells[0].Controls.Add(hyp);
}
this works fine when the files are on the same drive as the web application, fileNameFull looks like: ~\Uploads\some pdf.pdf
The requirement now is that files are going to be stored on a different drive so my question is how can I achieve this? Request.MapPath obviously expects a virtual path.
The files needs to be exposed to users over the web, security is not the main concern.
Thanks in advance.
You can’t create a hyperlink to a file that is not hosted within the web site. But you can create an http handler to serve the file. The http handler could accept an identifier for the file in the query string and write the file out to the response:
Then in the bind event of your page, you could set the
NavigateUrlto the handler, with an identifier for the file in the query string. Something like this: