The reason you're getting the exception, The input string is not in the correct format
is due to the way you're constructing the string. In your variable you have two closing braces where string.Format expects only one: on arm ({1}}
. If you add this variable as a parameter to String.Format as shown in the first example below, it should resolve this issue.
Otherwise, if you are saying that the variable serviceEntry.ReasonForFailure
contains the characters {0}
and {1}
, and that when you place this variable inside a String.Format
, those characters are being replaced by the String.Format
arguments, then this is by design, at least the way you're constructing your string.
Instead of inserting your variable in the string using the +
operator, include it as another parameter to the String.Format
call. This way, the {0}
in your variable will be preserved.
message.Body = string.Format(
"<html><body>Request is complete<br/>" +
"Service Request initiated by you is Complete<br/>" +
"Please use the following link to access " +
"<a href=\"{0}{1}\">{0}{1}</a><br/>" +
"Reason For Failure: {2}<br/></body></html>",
RunLogURL, runLogID, serviceEntry.ReasonForFailure);
Now, if you want to replace the {0}
and {1}
in serviceEntry.ReasonForFailure
with some other values, you can nest a String.Format inside another:
serviceEntry.ReasonForFailure = "10003 Insufficient Liquid Level detected at " +
"pipettor channel ({0}) on arm ({1}) (82)";
var channelId = 87;
var armId = 42;
message.Body = string.Format(
"<html><body>Request is complete<br/>" +
"Service Request initiated by you is Complete<br/>" +
"Please use the following link to access " +
"<a href=\"{0}{1}\">{0}{1}</a><br/>" +
"Reason For Failure: {2}<br/></body></html>",
RunLogURL, runLogID,
String.Format(serviceEntry.ReasonForFailure, channelId, armId));
Or you can do it in two operations:
serviceEntry.ReasonForFailure = "10003 Insufficient Liquid Level detected at " +
"pipettor channel ({0}) on arm ({1}) (82)";
var channelId = 87;
var armId = 42;
var reasonForFailure = String.Format(serviceEntry.ReasonForFailure, channelId, armId);
message.Body = string.Format(
"<html><body>Request is complete<br/>" +
"Service Request initiated by you is Complete<br/>" +
"Please use the following link to access " +
"<a href=\"{0}{1}\">{0}{1}</a><br/>" +
"Reason For Failure: {2}<br/></body></html>",
RunLogURL, runLogID, reasonForFailure);