c# - 如何在c#、mvc中为字符串分配映射路径

标签 c# model-view-controller smtp server.mappath

我正在发送带有我的 Web 项目的附件邮件。我使用以下代码提供本地路径

using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailStyle/TD-emailForCus.html")))
            {
                body = reader.ReadToEnd();
            }

那么这就可以正常工作了。但我想这样做。

stirng mypath = stirng.Format("~/EmailStyle/TD-emailForCus.html");
 using (StreamReader reader = new StreamReader(Server.MapPath(mypath)))
                {
                    body = reader.ReadToEnd();
                }

当我这样做时,它无法正常工作。我怎样才能给出这样的 map 路径。希望得到你的帮助。谢谢。

最佳答案

这样做。将完整的 Server.MapPath() 赋给这样的变量,然后调用它,

var mypath = Server.MapPath("~/EmailStyle/TD-emailForCus.html");
using (StreamReader reader = new StreamReader(mypath))
            {
                body = reader.ReadToEnd();
            }

这对你有帮助。

关于c# - 如何在c#、mvc中为字符串分配映射路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35645096/

相关文章:

c# - 使用 MVVM 模式在 WPF 中使用命令

ruby-on-rails - 如何在 MVC 中表示跨模型信息?

php - 开发joomla组件时如何调试它们

java - grails 应用程序 gmail smtp 无法在 ubuntu 上运行

c程序打开socket端口25

c# - 从队列中的所有用户运行方法

c# - 如何将方法从一种类型转换为另一种类型

c# - 在 c# 的 gridview 编辑模式下填充下拉列表的问题

c# - WPF - 将文本框的内容绑定(bind)到其他文本框

arduino - 我在尝试从 Arduino 和以太网扩展板发送电子邮件时收到来自 gmail 服务器的错误 530 5.7.0