使用物理路径在Gridview中创建可下载的Hperlink字段 [英] Make a downloadable Hperlink field in Gridview using Physical path

查看:66
本文介绍了使用物理路径在Gridview中创建可下载的Hperlink字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在gridview中设置一个下载链接,就是我在上传文件并在数据库中保存文件名及其pyshical路径时设置了物理路径



I want to set a download link in my gridview , the thing is that I have set a physical path while Uploading the file and saving the file name and its pyshical path in the database

if (fileUpTimeTable.HasFile)
{
    string TimeTableFileName = fileUpTimeTable.FileName;
    string TimeTableFilepath = "D:\\My_Drive\\Kunal_backup\\Kunal\\StudentDesk_aarti\\StudentDeskv2\\Download\\TimeTable\\";
fileUpTimeTable.SaveAs(TimeTableFilepath+fileUpTimeTable.FileName);
FillGrid();
}





上传工作正常,文件及其文件路径成功保存在数据库中。

gridview还显示正确的数据,但我无法从gridview下载上传的文件



以下是数据库字段

ID --Pkey

FILENAME - 例如abc.pdf

FILEPATH -



The Uploading works fine and the file and its filepath gets saved in the database successfully.
The gridview also shows the correct data but I am not able to download the uploaded file from the gridview

Following are Database fields
ID --Pkey
FILENAME -- e.g abc.pdf
FILEPATH --

D:\My_Drive\Kunal_backup\Kunal\StudentDesk_aarti\StudentDeskv2\Download\TimeTable\abc.pdf





请指导我如何实现相同的目标










Please guide me how can I accomplish the same




<asp:HyperLinkField DataNavigateUrlFields="FILENAME" DataNavigateUrlFormatString="{0}"

                            Text="&lt;img src='../IMAGES/download.jpg' style='border:none'&gt;" HeaderText="Download" Target="_blank"/>










P.S : I am not using Virtual path , but Physical because I need to share these uploaded file between two different Project Solutions

推荐答案

网站与项目解决方案无关(顺便说一下,它是什么?)。项目和解决方案只是开发的工件,在部署站点代码后它们不存在。问题是:是的,代码隐藏代码需要你所谓的物理路径;更确切地说,就服务器的主机文件系统而言,文件路径名称。使用 MapPath 方法获取此类路径名:

http://msdn.microsoft.com/en-us/library/ms524632%28v=vs.90%29.aspx [ ^ ]。



关于共享一些文件 - 谁知道什么,你可以做任何你想做的事,有一个重要的限制:通常,Web应用程序由HTTP服务器软件是一些沙盒环境。它不允许访问任何文件,除了那些放在目录下的文件,这些文件被设置为你网站的根目录。



如果你想分享一些不同站点之间的文件在同一主机中提供,没有文件路径重叠,共享文件相当困难。我想到的第一个解决方法是使用硬链接(不要将它们与.lnk文件混合使用;没有任何共同之处)。请参阅: http://en.wikipedia.org/wiki/Hard_link [ ^ ]。



如果是这种情况,最好避免这样的困难。例如,只要您在同一主机上提供服务,就可以随时正式合并以前不同的网站。由于你没有清楚地解释你的分享问题,我认为现在这已足够了。 :-)



-SA
A Web site has nothing to do with "Project Solutions" (what is it, by the way?). Project and solutions are just the artifact of development, they don't exist after you deploy the site code. The thing is: yes, the code-behind code needs what you call "physical paths"; more exactly, file path names in terms of the server's host file system. Such path names are obtained using the method MapPath:
http://msdn.microsoft.com/en-us/library/ms524632%28v=vs.90%29.aspx[^].

As to the sharing some files between-who-knows-what, you can do whatever you want, with one important limitation: usually, the Web applications are executed by the HTTP server software is some sandboxed environment. It won't allow access to to any files except those placed under the directory which is set up as a root directory for your site.

If you want to share some files between too different sites served up in the same host, without overlapping of the file paths, sharing the files is rather difficult. First work-around which comes to my mind would be the use of hard links (don't mix them up with .lnk files; nothing in common). Please see: http://en.wikipedia.org/wiki/Hard_link[^].

If this is the case, it's better to avoid such difficulties. For example, you can always formally merge too formerly different sites, as soon as you serve them up on the same host. As you did not clearly explain your sharing problem, I think this would be enough for now. :-)

—SA


这篇关于使用物理路径在Gridview中创建可下载的Hperlink字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆