开发者

Download link in asp.net mvc

I have uploaded the document from my asp.net mvc 2 application to application domain. there is a dir开发者_高级运维ectory name as "Docs". I want to create the link for download the document from my application . how to do that?

Edited:

I am taking this link from database. as "item.DownloadPath". I want to check that i this value is null or not .i can do that by <% if (item.DownloadPath!= null) %> but as i put this as: <% if (item.DownloadPath!= null) %> ">, it giving Error

Edited:- Thanks for answers , I tried these code it is working for the doc and docx document . but if i Uploads the .txt or any image like .jpg then it opens it in browser. it should be ask for the download. What Have to do ?


<a href="<%= Url.Content("~/docs/documentname.doc") %>"> download it </a>

should work.


Got the answer, you can try this:

<% if (item.DownloadPath!= null) %>
<% Response.Write("<a href='" + this.Url.Content("~/" + item.DownloadPath) + "' />Resume");%>
<% else %>
<% Response.Write("<a href='" + "#" + "' />#");%> 

And it is working fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜