如何从uploads文件夹中检索文档 [英] how to retrive documents from uploads folder
本文介绍了如何从uploads文件夹中检索文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
i上传文件如下。我正在上传到我的文件夹上传。
现在我想给一个链接按钮并访问附件file.how实现这个目标?
aspx
Hello,
i am uploading file like below.it is uplading to my folder called "Uploads".
now i want to give one link button and access the attached file.how to achieve this?
aspx
<asp:FileUpload ID="txtFileUpload" runat="server" Height="18px"/>
<asp:HyperLink ID ="lblUploadFileName1" runat="server" NavigateUrl="" Target="_new" Text=""></asp:HyperLink>
。上传文件代码
.Cs uploading file code
string filename = System.IO.Path.GetFileName(txtFileUpload.FileName);
txtFileUpload.SaveAs(Server.MapPath("~/Uploads/") + filename);
请帮助以下代码显示链接,点击附件应该打开
please help below code for show link and on click the attached file should open
lblUploadFileName1.NavigateUrl = Server.MapPath("~/Uploads/") + ds.Tables[0].Rows[0]["Attached_File_path"].ToString();
推荐答案
在LinkButton Onclick内尝试类似下面的内容
Try something like below inside LinkButton Onclick
string filePath = "ReplacethePathHereWithYours";
Response.ContentType = "ContentType"//Modify ContentType accordingly like pdf etc;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
Response.WriteFile(filePath);
Response.End();
这篇关于如何从uploads文件夹中检索文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文