动态保存文件位置

发布于 2024-07-11 11:54:17 字数 217 浏览 5 评论 0原文

我有一个 asp.net 应用程序,我正在尝试将文本文件保存到随每个客户端而更改的文件夹中。 我该如何编写它以将文件保存到更改的文件夹中。 例如,一个客户可能是 C:\inetpub\wwwroot\site1\,另一个客户可能是 C:\inetpub\wwwroot\site2。 相对路径似乎不起作用,我尝试过 GetCurrentDirectory 但它一直给我错误的目录。

谢谢

I have an asp.net app and I am trying to save a text file to a folder that changes with each client. How can I write it to save the files to a folder that changes. For example one customer might be C:\inetpub\wwwroot\site1\ another might be C:\inetpub\wwwroot\site2.
Relative paths don't seem to work, and I've tried GetCurrentDirectory but it kept giving me the wrong directory.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

幻想少年梦 2024-07-18 11:54:17

您应该尝试:

在 *.aspx.cs 文件中:

string currentPath = Server.MapPath("~");

我没有在这里测试的工具,但我认为代码是正确的。

You should try :

In the *.aspx.cs file :

string currentPath = Server.MapPath("~");

I don't have the tools to test here, but I think the code is right.

雨落星ぅ辰 2024-07-18 11:54:17

看一下 Path.GetDirectoryName(Request.ServerVariables("SCRIPT_NAME"))

Take a look at Path.GetDirectoryName(Request.ServerVariables("SCRIPT_NAME")).

傲性难收 2024-07-18 11:54:17

您应该向 web.config 文件添加一个值,该值设置为保存文件的路径。

然后,在您的代码中,从文档中检索该值,并在保存时使用该路径。

You should add a value to the web.config file which is set to the path where the file is saved.

Then, in you code, retrieve this value from the documentation, and use that path when saving.

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