ProcessStartInfo Multiple Arguments

≡放荡痞女 提交于 2019-12-01 13:12:32

问题


I have an ASP.NET Web Form which was timing out when sending over 1800 emails whose addresses were being obtained from a DB. So I'm attempting to send the emails from a console application instead - I will access the DB there.

I need to pass the email subject line and body text as parameters to the ProcessStartInfo method but need guidance with the syntax. Can anyone help? Specifically, if I concatenate the subject and body vars and separate them with a space, will that suffice or will spaces in the vars cause problems?


回答1:


Both the email subject and body should already contain spaces so you need to obey the same rules as if you were calling the program from the command line and enclose in " the arguments that contain spaces, otherwise each space in the subject will delimit a new argument.

Another special case is if the subject and body already contain the " character so you also need to account for that.

I think this should do the trick:

string subject = "Hello World!";

string body = @"This has "" quotes """;

string arguments = string.Format(
    @"""{0}"" ""{1}""", 
    subject.Replace(@"""", @""""""),
    body.Replace(@"""", @""""""));


来源:https://stackoverflow.com/questions/8054178/processstartinfo-multiple-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!