用于在数据库中存储组件的文件路径的选项

发布于 2024-11-05 23:15:21 字数 717 浏览 4 评论 0原文

我有一组文件(本质上是“.exe”文件),允许用户从我的网站下载。要获得更清晰的图片,请查看屏幕截图(这只是一个学术项目)。现在我拥有管理员权限,可以将新的软件文件上传到网站根目录的文件夹(componentsFolder)中,同时我还将文件路径添加到数据库表中。

我使用以下代码来执行此操作:

string componentRelativeFilePath = @"/ComponentsFolder/" + ComponentName;

我以以下格式将文件路径存储在数据库文件中: /ComponentsFolder/FileName.exe

以以下格式存储文件有什么区别?

  1. /ComponentsFolder/FileName.exe
  2. \ComponentsFolder\FileName.exe
  3. ~/ComponentsFolder/FileName.exe
  4. ~\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?

  1. /ComponentsFolder/FileName.exe
  2. \ComponentsFolder\FileName.exe
  3. ~/ComponentsFolder/FileName.exe
  4. ~\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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人间不值得 2024-11-12 23:15:21

就 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 in Image folder located in website root and in that folder pic1.jpeg is searched. If your set you image source to "~/Image/pic1.jpeg" in that case as well the image file is read from the Image 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文