用于在数据库中存储组件的文件路径的选项
我有一组文件(本质上是“.exe”文件),允许用户从我的网站下载。要获得更清晰的图片,请查看此屏幕截图(这只是一个学术项目)。现在我拥有管理员权限,可以将新的软件文件上传到网站根目录的文件夹(componentsFolder)中,同时我还将文件路径添加到数据库表中。
我使用以下代码来执行此操作:
string componentRelativeFilePath = @"/ComponentsFolder/" + ComponentName;
我以以下格式将文件路径存储在数据库文件中: /ComponentsFolder/FileName.exe
以以下格式存储文件有什么区别?
- /ComponentsFolder/FileName.exe
- \ComponentsFolder\FileName.exe
- ~/ComponentsFolder/FileName.exe
- ~\ComponentsFolder\FileName.exe
我正在使用 server.mappath 从根文件夹检索文件。
我想知道这些格式之间的区别(在这种情况下),以及哪种格式是在数据库表中存储相对路径的标准/适当/技术上正确的格式。
I have set of files (which are essentially ".exe" files) that I allow the users to download from my website. To have a clearer picture have a look at the this screenshot (it is just a academic project). Now I have administrator privilege in which I can upload a new software file to a folder (componentsFolder) to the root of my website and I also add the filepath to the database table at the same time.
I'm using the following code to do that:
string componentRelativeFilePath = @"/ComponentsFolder/" + ComponentName;
I'm storing the filepath in the following format in the database file:
/ComponentsFolder/FileName.exe
What is the difference between storing the files in the following formats?
- /ComponentsFolder/FileName.exe
- \ComponentsFolder\FileName.exe
- ~/ComponentsFolder/FileName.exe
- ~\ComponentsFolder\FileName.exe
I'm using server.mappath to retrieve the file from the root folder.
I want to know the difference (in this context) between these formats and which one is the standard/appropriate/technically correct format to store the relative paths in database table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就 Asp.Net 而言,假设您将图像路径设置为“
/Image/pic1.jpeg
”,以便在位于网站根目录的Image
文件夹中搜索图像,并且在该文件夹中搜索pic1.jpeg
。如果您将图像源设置为“~/Image/pic1.jpeg
”,在这种情况下,图像文件也会从直接位于Web 应用程序的根目录,无论该页面位于网站的哪个位置。但 '~/
' 只能与服务器控件一起使用。如果路径为“
../Image/pic1.jpeg
”,则在当前网页的文件夹中搜索图像文件夹。根据我的观点,就 Asp.Net 而言,以“
~/Image/
”格式存储路径是更好的选择。希望我能回答你的问题。
In terms of Asp.Net lets suppose you set your image path as "
/Image/pic1.jpeg
" so the image would be searched inImage
folder located in website root and in that folderpic1.jpeg
is searched. If your set you image source to "~/Image/pic1.jpeg
" in that case as well the image file is read from theImage
folder that is located directly under the root of the Web application, regardless of where in the Web site the page is located. But '~/
' this could only be used with server controls.If path is "
../Image/pic1.jpeg
", in that case Image folder is searched in the current webpage's folder.As per my opinion storing path in "
~/Image/
" format is a better choice in terms of Asp.Net.Hope I answer your question.