K
KNE
I'm writing some code that is formating an output file being generated
within a web app. I want to allow the site administrator to configure the
characters that will mark the end of each line/record in the file.
Therefore, I added a key to my web.config appSettings section similar to the
following:
<add key="EORMarker" value="\r\n" />
This way, the setting can be changed to use "\r", "\n", "\n\r", "\r\n\n",
etc. I retrieve the appSetting value with code in the Global.asax and load
it into the application cache for quick access as in:
string eorMarker =
((NameValueCollection)ConfigurationSettings.GetConfig("appSettings"))["EORMa
rker"];
Context.Cache.Insert("EORMarker", eorMarker, new
CacheDependency(Server.MapPath("web.config")));
I have a static lookup method I use to pull the string out of the cache when
needed:
public static string EORMarker()
{
return (string)HttpContext.Current.Cache["EORMarker"];
}
When I write a record/line to the output file, I tack on the characters
intended to serve as the End Of Record marker:
myStream.Write(this.myHeader + Lookup.EORMarker());
However, instead of getting an expected carriage return and line feed at the
end of the record/line, I literally get the "\r\n" characters in the output.
If I put the literal string in place of the lookup method:
myStream.Write(this.myHeader + "\r\n");
I get the desired / correct effect (a CR/LF to a new line). What can I do
to make pulling the End of Record Marker from the appSettings give me the
effect I want?
Thanks,
Ken
within a web app. I want to allow the site administrator to configure the
characters that will mark the end of each line/record in the file.
Therefore, I added a key to my web.config appSettings section similar to the
following:
<add key="EORMarker" value="\r\n" />
This way, the setting can be changed to use "\r", "\n", "\n\r", "\r\n\n",
etc. I retrieve the appSetting value with code in the Global.asax and load
it into the application cache for quick access as in:
string eorMarker =
((NameValueCollection)ConfigurationSettings.GetConfig("appSettings"))["EORMa
rker"];
Context.Cache.Insert("EORMarker", eorMarker, new
CacheDependency(Server.MapPath("web.config")));
I have a static lookup method I use to pull the string out of the cache when
needed:
public static string EORMarker()
{
return (string)HttpContext.Current.Cache["EORMarker"];
}
When I write a record/line to the output file, I tack on the characters
intended to serve as the End Of Record marker:
myStream.Write(this.myHeader + Lookup.EORMarker());
However, instead of getting an expected carriage return and line feed at the
end of the record/line, I literally get the "\r\n" characters in the output.
If I put the literal string in place of the lookup method:
myStream.Write(this.myHeader + "\r\n");
I get the desired / correct effect (a CR/LF to a new line). What can I do
to make pulling the End of Record Marker from the appSettings give me the
effect I want?
Thanks,
Ken