这些是从数据库读出来的附件路径,请问如何只显示文件名,还有就是在点击的时候能能下载到本地?
我现在用的是BulletedList控件,ListView控件也试了下,但是没有思路!!!
1:IO.Path.GetFileName(path)
2:点击时,读取成byte[],然后输出即可,参考代码:
/// <summary> /// 输出文件 /// </summary> /// <param name="filePath">文件所在路径</param> private void OutPutFile(string filePath, string outPutName) { Byte[] fileData = DownFileFromUrlPath(filePath); if (fileData == null) { HttpContext.Current.Response.Write("file not exist!!"); HttpContext.Current.Response.End(); } try { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearHeaders(); // HttpContext.Current.Response.BufferOutput = false; HttpContext.Current.Response.ContentType = "application/force-download"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(outPutName, System.Text.Encoding.UTF8)); HttpContext.Current.Response.AddHeader("Content-Length", fileData.Length.ToString()); HttpContext.Current.Response.BinaryWrite(fileData); HttpContext.Current.Response.Flush(); } catch { } finally { fileData = null; } HttpContext.Current.Response.End(); }
楼上正解