开发者

Making dyanamic link in dot net

I want a functionality in which i want following thing:

when i open a page created by me for download, it should dynamically create links for all 开发者_高级运维the documents present in particular directory.

for eg: if i have folder at web server as /download/document and i have following document in this folder

a.txt b.txt c.doc d.pdf

now when i open page then i should have 4 links each for these of documents n when i click on this link, the file can be downloaded


Using System.IO.Directory.GetFiles("Path to folder") you can get list of files directory contains and Request.PhysicalPath.Substring(0, Request.PhysicalPath.LastIndexOf("\\"))) will get you the physical path to the folder that contains your aspx file. Then iterating through each file and using Request.Url you can generate download link.


How about just enabling directory browsing in IIS? It ain't pretty, but it'll get the job done in 10 seconds. :)


additional to Waqas answer, you can create a panel (design time), then loop through all files in a specific directory, and create a Hyperlink Object for each file and assign the NavagationURL for it, and then add the hyperlink control to the panel

I guess this should helps

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜