动态保存文件位置
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该尝试:
在 *.aspx.cs 文件中:
我没有在这里测试的工具,但我认为代码是正确的。
You should try :
In the *.aspx.cs file :
I don't have the tools to test here, but I think the code is right.
看一下
Path.GetDirectoryName(Request.ServerVariables("SCRIPT_NAME"))
。Take a look at
Path.GetDirectoryName(Request.ServerVariables("SCRIPT_NAME"))
.您应该向 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.