Does C# have something like PHP's mb_convert_encoding()? - c#

Is there a way on C# that I can convert unicode strings into ASCII + html entities, and then back again? See, in PHP, I can do it like so:
<?php
// RUN ME AT COMMAND LINE
$sUnicode = '<b>Jöhan Strauß</b>';
echo "UNICODE: $sUnicode\n";
$sASCII = mb_convert_encoding($sUnicode, 'HTML-ENTITIES','UTF-8');
echo "ASCII: $sASCII\n";
$sUnicode = mb_convert_encoding($sASCII, 'UTF-8', 'HTML-ENTITIES');
echo "UNICODE (TRANSLATED BACK): $sUnicode\n";
Background:
I need this to work in C# .NET 2 because we are constrained and can't use a higher .NET library in an older application.
I handle the PHP backend on this application. I wanted to share some tips with the C# frontend team on this project.

Yes, there's Encoding.Convert, although I rarely use it myself:
string text = "<b>Jöhan Strauß</b>";
byte[] ascii = Encoding.ASCII.GetBytes(text);
byte[] utf8 = Encoding.Convert(Encoding.ASCII, Encoding.UTF8, ascii);
I rarely find I want to convert from one encoded form to another - it's much more common to perform a one way conversion from text to binary (Encoding.GetBytes) or vice versa (Encoding.GetString).

HTML-ENTITIES isn't really a character encoding even though the PHP API might hint so. <b>Jöhan Strauß</b> is still UTF-8 encoded text (or even ASCII, ISO-8859-1, pretty much anything).
I couldn't find anything premade, except html encoding functions which are not the same thing at all since they encode &, < etc while mb_convert_encoding doesn't. I made t his class that should work:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class HtmlEntities
{
private static Dictionary<string, int> EntitiesToCodePoints;
private static Dictionary<int, string> CodePointsToEntities;
private static void Init()
{
if (EntitiesToCodePoints == null || CodePointsToEntities == null)
{
EntitiesToCodePoints = new Dictionary<string, int>();
CodePointsToEntities = new Dictionary<int, string>();
EntitiesToCodePoints["nbsp"] = 160; EntitiesToCodePoints["iexcl"] = 161; EntitiesToCodePoints["cent"] = 162; EntitiesToCodePoints["pound"] = 163; EntitiesToCodePoints["curren"] = 164; EntitiesToCodePoints["yen"] = 165; EntitiesToCodePoints["brvbar"] = 166; EntitiesToCodePoints["sect"] = 167; EntitiesToCodePoints["uml"] = 168; EntitiesToCodePoints["copy"] = 169; EntitiesToCodePoints["ordf"] = 170; EntitiesToCodePoints["laquo"] = 171; EntitiesToCodePoints["not"] = 172; EntitiesToCodePoints["shy"] = 173; EntitiesToCodePoints["reg"] = 174; EntitiesToCodePoints["macr"] = 175; EntitiesToCodePoints["deg"] = 176; EntitiesToCodePoints["plusmn"] = 177; EntitiesToCodePoints["sup2"] = 178; EntitiesToCodePoints["sup3"] = 179; EntitiesToCodePoints["acute"] = 180; EntitiesToCodePoints["micro"] = 181; EntitiesToCodePoints["para"] = 182; EntitiesToCodePoints["middot"] = 183; EntitiesToCodePoints["cedil"] = 184; EntitiesToCodePoints["sup1"] = 185; EntitiesToCodePoints["ordm"] = 186; EntitiesToCodePoints["raquo"] = 187; EntitiesToCodePoints["frac14"] = 188; EntitiesToCodePoints["frac12"] = 189; EntitiesToCodePoints["frac34"] = 190; EntitiesToCodePoints["iquest"] = 191; EntitiesToCodePoints["Agrave"] = 192; EntitiesToCodePoints["Aacute"] = 193; EntitiesToCodePoints["Acirc"] = 194; EntitiesToCodePoints["Atilde"] = 195; EntitiesToCodePoints["Auml"] = 196; EntitiesToCodePoints["Aring"] = 197; EntitiesToCodePoints["AElig"] = 198; EntitiesToCodePoints["Ccedil"] = 199; EntitiesToCodePoints["Egrave"] = 200; EntitiesToCodePoints["Eacute"] = 201; EntitiesToCodePoints["Ecirc"] = 202; EntitiesToCodePoints["Euml"] = 203; EntitiesToCodePoints["Igrave"] = 204; EntitiesToCodePoints["Iacute"] = 205; EntitiesToCodePoints["Icirc"] = 206; EntitiesToCodePoints["Iuml"] = 207; EntitiesToCodePoints["ETH"] = 208; EntitiesToCodePoints["Ntilde"] = 209; EntitiesToCodePoints["Ograve"] = 210; EntitiesToCodePoints["Oacute"] = 211; EntitiesToCodePoints["Ocirc"] = 212; EntitiesToCodePoints["Otilde"] = 213; EntitiesToCodePoints["Ouml"] = 214; EntitiesToCodePoints["times"] = 215; EntitiesToCodePoints["Oslash"] = 216; EntitiesToCodePoints["Ugrave"] = 217; EntitiesToCodePoints["Uacute"] = 218; EntitiesToCodePoints["Ucirc"] = 219; EntitiesToCodePoints["Uuml"] = 220; EntitiesToCodePoints["Yacute"] = 221; EntitiesToCodePoints["THORN"] = 222; EntitiesToCodePoints["szlig"] = 223; EntitiesToCodePoints["agrave"] = 224; EntitiesToCodePoints["aacute"] = 225; EntitiesToCodePoints["acirc"] = 226; EntitiesToCodePoints["atilde"] = 227; EntitiesToCodePoints["auml"] = 228; EntitiesToCodePoints["aring"] = 229; EntitiesToCodePoints["aelig"] = 230; EntitiesToCodePoints["ccedil"] = 231; EntitiesToCodePoints["egrave"] = 232; EntitiesToCodePoints["eacute"] = 233; EntitiesToCodePoints["ecirc"] = 234; EntitiesToCodePoints["euml"] = 235; EntitiesToCodePoints["igrave"] = 236; EntitiesToCodePoints["iacute"] = 237; EntitiesToCodePoints["icirc"] = 238; EntitiesToCodePoints["iuml"] = 239; EntitiesToCodePoints["eth"] = 240; EntitiesToCodePoints["ntilde"] = 241; EntitiesToCodePoints["ograve"] = 242; EntitiesToCodePoints["oacute"] = 243; EntitiesToCodePoints["ocirc"] = 244; EntitiesToCodePoints["otilde"] = 245; EntitiesToCodePoints["ouml"] = 246; EntitiesToCodePoints["divide"] = 247; EntitiesToCodePoints["oslash"] = 248; EntitiesToCodePoints["ugrave"] = 249; EntitiesToCodePoints["uacute"] = 250; EntitiesToCodePoints["ucirc"] = 251; EntitiesToCodePoints["uuml"] = 252; EntitiesToCodePoints["yacute"] = 253; EntitiesToCodePoints["thorn"] = 254; EntitiesToCodePoints["yuml"] = 255; EntitiesToCodePoints["OElig"] = 338; EntitiesToCodePoints["oelig"] = 339; EntitiesToCodePoints["Scaron"] = 352; EntitiesToCodePoints["scaron"] = 353; EntitiesToCodePoints["Yuml"] = 376; EntitiesToCodePoints["fnof"] = 402; EntitiesToCodePoints["circ"] = 710; EntitiesToCodePoints["tilde"] = 732; EntitiesToCodePoints["Alpha"] = 913; EntitiesToCodePoints["Beta"] = 914; EntitiesToCodePoints["Gamma"] = 915; EntitiesToCodePoints["Delta"] = 916; EntitiesToCodePoints["Epsilon"] = 917; EntitiesToCodePoints["Zeta"] = 918; EntitiesToCodePoints["Eta"] = 919; EntitiesToCodePoints["Theta"] = 920; EntitiesToCodePoints["Iota"] = 921; EntitiesToCodePoints["Kappa"] = 922; EntitiesToCodePoints["Lambda"] = 923; EntitiesToCodePoints["Mu"] = 924; EntitiesToCodePoints["Nu"] = 925; EntitiesToCodePoints["Xi"] = 926; EntitiesToCodePoints["Omicron"] = 927; EntitiesToCodePoints["Pi"] = 928; EntitiesToCodePoints["Rho"] = 929; EntitiesToCodePoints["Sigma"] = 931; EntitiesToCodePoints["Tau"] = 932; EntitiesToCodePoints["Upsilon"] = 933; EntitiesToCodePoints["Phi"] = 934; EntitiesToCodePoints["Chi"] = 935; EntitiesToCodePoints["Psi"] = 936; EntitiesToCodePoints["Omega"] = 937; EntitiesToCodePoints["alpha"] = 945; EntitiesToCodePoints["beta"] = 946; EntitiesToCodePoints["gamma"] = 947; EntitiesToCodePoints["delta"] = 948; EntitiesToCodePoints["epsilon"] = 949; EntitiesToCodePoints["zeta"] = 950; EntitiesToCodePoints["eta"] = 951; EntitiesToCodePoints["theta"] = 952; EntitiesToCodePoints["iota"] = 953; EntitiesToCodePoints["kappa"] = 954; EntitiesToCodePoints["lambda"] = 955; EntitiesToCodePoints["mu"] = 956; EntitiesToCodePoints["nu"] = 957; EntitiesToCodePoints["xi"] = 958; EntitiesToCodePoints["omicron"] = 959; EntitiesToCodePoints["pi"] = 960; EntitiesToCodePoints["rho"] = 961; EntitiesToCodePoints["sigmaf"] = 962; EntitiesToCodePoints["sigma"] = 963; EntitiesToCodePoints["tau"] = 964; EntitiesToCodePoints["upsilon"] = 965; EntitiesToCodePoints["phi"] = 966; EntitiesToCodePoints["chi"] = 967; EntitiesToCodePoints["psi"] = 968; EntitiesToCodePoints["omega"] = 969; EntitiesToCodePoints["thetasym"] = 977; EntitiesToCodePoints["upsih"] = 978; EntitiesToCodePoints["piv"] = 982; EntitiesToCodePoints["ensp"] = 8194; EntitiesToCodePoints["emsp"] = 8195; EntitiesToCodePoints["thinsp"] = 8201; EntitiesToCodePoints["zwnj"] = 8204; EntitiesToCodePoints["zwj"] = 8205; EntitiesToCodePoints["lrm"] = 8206; EntitiesToCodePoints["rlm"] = 8207; EntitiesToCodePoints["ndash"] = 8211; EntitiesToCodePoints["mdash"] = 8212; EntitiesToCodePoints["lsquo"] = 8216; EntitiesToCodePoints["rsquo"] = 8217; EntitiesToCodePoints["sbquo"] = 8218; EntitiesToCodePoints["ldquo"] = 8220; EntitiesToCodePoints["rdquo"] = 8221; EntitiesToCodePoints["bdquo"] = 8222; EntitiesToCodePoints["dagger"] = 8224; EntitiesToCodePoints["Dagger"] = 8225; EntitiesToCodePoints["bull"] = 8226; EntitiesToCodePoints["hellip"] = 8230; EntitiesToCodePoints["permil"] = 8240; EntitiesToCodePoints["prime"] = 8242; EntitiesToCodePoints["Prime"] = 8243; EntitiesToCodePoints["lsaquo"] = 8249; EntitiesToCodePoints["rsaquo"] = 8250; EntitiesToCodePoints["oline"] = 8254; EntitiesToCodePoints["frasl"] = 8260; EntitiesToCodePoints["euro"] = 8364; EntitiesToCodePoints["weierp"] = 8472; EntitiesToCodePoints["image"] = 8465; EntitiesToCodePoints["real"] = 8476; EntitiesToCodePoints["trade"] = 8482; EntitiesToCodePoints["alefsym"] = 8501; EntitiesToCodePoints["larr"] = 8592; EntitiesToCodePoints["uarr"] = 8593; EntitiesToCodePoints["rarr"] = 8594; EntitiesToCodePoints["darr"] = 8595; EntitiesToCodePoints["harr"] = 8596; EntitiesToCodePoints["crarr"] = 8629; EntitiesToCodePoints["lArr"] = 8656; EntitiesToCodePoints["uArr"] = 8657; EntitiesToCodePoints["rArr"] = 8658; EntitiesToCodePoints["dArr"] = 8659; EntitiesToCodePoints["hArr"] = 8660; EntitiesToCodePoints["forall"] = 8704; EntitiesToCodePoints["part"] = 8706; EntitiesToCodePoints["exist"] = 8707; EntitiesToCodePoints["empty"] = 8709; EntitiesToCodePoints["nabla"] = 8711; EntitiesToCodePoints["isin"] = 8712; EntitiesToCodePoints["notin"] = 8713; EntitiesToCodePoints["ni"] = 8715; EntitiesToCodePoints["prod"] = 8719; EntitiesToCodePoints["sum"] = 8721; EntitiesToCodePoints["minus"] = 8722; EntitiesToCodePoints["lowast"] = 8727; EntitiesToCodePoints["radic"] = 8730; EntitiesToCodePoints["prop"] = 8733; EntitiesToCodePoints["infin"] = 8734; EntitiesToCodePoints["ang"] = 8736; EntitiesToCodePoints["and"] = 8743; EntitiesToCodePoints["or"] = 8744; EntitiesToCodePoints["cap"] = 8745; EntitiesToCodePoints["cup"] = 8746; EntitiesToCodePoints["int"] = 8747; EntitiesToCodePoints["there4"] = 8756; EntitiesToCodePoints["sim"] = 8764; EntitiesToCodePoints["cong"] = 8773; EntitiesToCodePoints["asymp"] = 8776; EntitiesToCodePoints["ne"] = 8800; EntitiesToCodePoints["equiv"] = 8801; EntitiesToCodePoints["le"] = 8804; EntitiesToCodePoints["ge"] = 8805; EntitiesToCodePoints["sub"] = 8834; EntitiesToCodePoints["sup"] = 8835; EntitiesToCodePoints["nsub"] = 8836; EntitiesToCodePoints["sube"] = 8838; EntitiesToCodePoints["supe"] = 8839; EntitiesToCodePoints["oplus"] = 8853; EntitiesToCodePoints["otimes"] = 8855; EntitiesToCodePoints["perp"] = 8869; EntitiesToCodePoints["sdot"] = 8901; EntitiesToCodePoints["lceil"] = 8968; EntitiesToCodePoints["rceil"] = 8969; EntitiesToCodePoints["lfloor"] = 8970; EntitiesToCodePoints["rfloor"] = 8971; EntitiesToCodePoints["lang"] = 9001; EntitiesToCodePoints["rang"] = 9002; EntitiesToCodePoints["loz"] = 9674; EntitiesToCodePoints["spades"] = 9824; EntitiesToCodePoints["clubs"] = 9827; EntitiesToCodePoints["hearts"] = 9829; EntitiesToCodePoints["diams"] = 9830;
CodePointsToEntities[160] = "nbsp"; CodePointsToEntities[161] = "iexcl"; CodePointsToEntities[162] = "cent"; CodePointsToEntities[163] = "pound"; CodePointsToEntities[164] = "curren"; CodePointsToEntities[165] = "yen"; CodePointsToEntities[166] = "brvbar"; CodePointsToEntities[167] = "sect"; CodePointsToEntities[168] = "uml"; CodePointsToEntities[169] = "copy"; CodePointsToEntities[170] = "ordf"; CodePointsToEntities[171] = "laquo"; CodePointsToEntities[172] = "not"; CodePointsToEntities[173] = "shy"; CodePointsToEntities[174] = "reg"; CodePointsToEntities[175] = "macr"; CodePointsToEntities[176] = "deg"; CodePointsToEntities[177] = "plusmn"; CodePointsToEntities[178] = "sup2"; CodePointsToEntities[179] = "sup3"; CodePointsToEntities[180] = "acute"; CodePointsToEntities[181] = "micro"; CodePointsToEntities[182] = "para"; CodePointsToEntities[183] = "middot"; CodePointsToEntities[184] = "cedil"; CodePointsToEntities[185] = "sup1"; CodePointsToEntities[186] = "ordm"; CodePointsToEntities[187] = "raquo"; CodePointsToEntities[188] = "frac14"; CodePointsToEntities[189] = "frac12"; CodePointsToEntities[190] = "frac34"; CodePointsToEntities[191] = "iquest"; CodePointsToEntities[192] = "Agrave"; CodePointsToEntities[193] = "Aacute"; CodePointsToEntities[194] = "Acirc"; CodePointsToEntities[195] = "Atilde"; CodePointsToEntities[196] = "Auml"; CodePointsToEntities[197] = "Aring"; CodePointsToEntities[198] = "AElig"; CodePointsToEntities[199] = "Ccedil"; CodePointsToEntities[200] = "Egrave"; CodePointsToEntities[201] = "Eacute"; CodePointsToEntities[202] = "Ecirc"; CodePointsToEntities[203] = "Euml"; CodePointsToEntities[204] = "Igrave"; CodePointsToEntities[205] = "Iacute"; CodePointsToEntities[206] = "Icirc"; CodePointsToEntities[207] = "Iuml"; CodePointsToEntities[208] = "ETH"; CodePointsToEntities[209] = "Ntilde"; CodePointsToEntities[210] = "Ograve"; CodePointsToEntities[211] = "Oacute"; CodePointsToEntities[212] = "Ocirc"; CodePointsToEntities[213] = "Otilde"; CodePointsToEntities[214] = "Ouml"; CodePointsToEntities[215] = "times"; CodePointsToEntities[216] = "Oslash"; CodePointsToEntities[217] = "Ugrave"; CodePointsToEntities[218] = "Uacute"; CodePointsToEntities[219] = "Ucirc"; CodePointsToEntities[220] = "Uuml"; CodePointsToEntities[221] = "Yacute"; CodePointsToEntities[222] = "THORN"; CodePointsToEntities[223] = "szlig"; CodePointsToEntities[224] = "agrave"; CodePointsToEntities[225] = "aacute"; CodePointsToEntities[226] = "acirc"; CodePointsToEntities[227] = "atilde"; CodePointsToEntities[228] = "auml"; CodePointsToEntities[229] = "aring"; CodePointsToEntities[230] = "aelig"; CodePointsToEntities[231] = "ccedil"; CodePointsToEntities[232] = "egrave"; CodePointsToEntities[233] = "eacute"; CodePointsToEntities[234] = "ecirc"; CodePointsToEntities[235] = "euml"; CodePointsToEntities[236] = "igrave"; CodePointsToEntities[237] = "iacute"; CodePointsToEntities[238] = "icirc"; CodePointsToEntities[239] = "iuml"; CodePointsToEntities[240] = "eth"; CodePointsToEntities[241] = "ntilde"; CodePointsToEntities[242] = "ograve"; CodePointsToEntities[243] = "oacute"; CodePointsToEntities[244] = "ocirc"; CodePointsToEntities[245] = "otilde"; CodePointsToEntities[246] = "ouml"; CodePointsToEntities[247] = "divide"; CodePointsToEntities[248] = "oslash"; CodePointsToEntities[249] = "ugrave"; CodePointsToEntities[250] = "uacute"; CodePointsToEntities[251] = "ucirc"; CodePointsToEntities[252] = "uuml"; CodePointsToEntities[253] = "yacute"; CodePointsToEntities[254] = "thorn"; CodePointsToEntities[255] = "yuml"; CodePointsToEntities[338] = "OElig"; CodePointsToEntities[339] = "oelig"; CodePointsToEntities[352] = "Scaron"; CodePointsToEntities[353] = "scaron"; CodePointsToEntities[376] = "Yuml"; CodePointsToEntities[402] = "fnof"; CodePointsToEntities[710] = "circ"; CodePointsToEntities[732] = "tilde"; CodePointsToEntities[913] = "Alpha"; CodePointsToEntities[914] = "Beta"; CodePointsToEntities[915] = "Gamma"; CodePointsToEntities[916] = "Delta"; CodePointsToEntities[917] = "Epsilon"; CodePointsToEntities[918] = "Zeta"; CodePointsToEntities[919] = "Eta"; CodePointsToEntities[920] = "Theta"; CodePointsToEntities[921] = "Iota"; CodePointsToEntities[922] = "Kappa"; CodePointsToEntities[923] = "Lambda"; CodePointsToEntities[924] = "Mu"; CodePointsToEntities[925] = "Nu"; CodePointsToEntities[926] = "Xi"; CodePointsToEntities[927] = "Omicron"; CodePointsToEntities[928] = "Pi"; CodePointsToEntities[929] = "Rho"; CodePointsToEntities[931] = "Sigma"; CodePointsToEntities[932] = "Tau"; CodePointsToEntities[933] = "Upsilon"; CodePointsToEntities[934] = "Phi"; CodePointsToEntities[935] = "Chi"; CodePointsToEntities[936] = "Psi"; CodePointsToEntities[937] = "Omega"; CodePointsToEntities[945] = "alpha"; CodePointsToEntities[946] = "beta"; CodePointsToEntities[947] = "gamma"; CodePointsToEntities[948] = "delta"; CodePointsToEntities[949] = "epsilon"; CodePointsToEntities[950] = "zeta"; CodePointsToEntities[951] = "eta"; CodePointsToEntities[952] = "theta"; CodePointsToEntities[953] = "iota"; CodePointsToEntities[954] = "kappa"; CodePointsToEntities[955] = "lambda"; CodePointsToEntities[956] = "mu"; CodePointsToEntities[957] = "nu"; CodePointsToEntities[958] = "xi"; CodePointsToEntities[959] = "omicron"; CodePointsToEntities[960] = "pi"; CodePointsToEntities[961] = "rho"; CodePointsToEntities[962] = "sigmaf"; CodePointsToEntities[963] = "sigma"; CodePointsToEntities[964] = "tau"; CodePointsToEntities[965] = "upsilon"; CodePointsToEntities[966] = "phi"; CodePointsToEntities[967] = "chi"; CodePointsToEntities[968] = "psi"; CodePointsToEntities[969] = "omega"; CodePointsToEntities[977] = "thetasym"; CodePointsToEntities[978] = "upsih"; CodePointsToEntities[982] = "piv"; CodePointsToEntities[8194] = "ensp"; CodePointsToEntities[8195] = "emsp"; CodePointsToEntities[8201] = "thinsp"; CodePointsToEntities[8204] = "zwnj"; CodePointsToEntities[8205] = "zwj"; CodePointsToEntities[8206] = "lrm"; CodePointsToEntities[8207] = "rlm"; CodePointsToEntities[8211] = "ndash"; CodePointsToEntities[8212] = "mdash"; CodePointsToEntities[8216] = "lsquo"; CodePointsToEntities[8217] = "rsquo"; CodePointsToEntities[8218] = "sbquo"; CodePointsToEntities[8220] = "ldquo"; CodePointsToEntities[8221] = "rdquo"; CodePointsToEntities[8222] = "bdquo"; CodePointsToEntities[8224] = "dagger"; CodePointsToEntities[8225] = "Dagger"; CodePointsToEntities[8226] = "bull"; CodePointsToEntities[8230] = "hellip"; CodePointsToEntities[8240] = "permil"; CodePointsToEntities[8242] = "prime"; CodePointsToEntities[8243] = "Prime"; CodePointsToEntities[8249] = "lsaquo"; CodePointsToEntities[8250] = "rsaquo"; CodePointsToEntities[8254] = "oline"; CodePointsToEntities[8260] = "frasl"; CodePointsToEntities[8364] = "euro"; CodePointsToEntities[8472] = "weierp"; CodePointsToEntities[8465] = "image"; CodePointsToEntities[8476] = "real"; CodePointsToEntities[8482] = "trade"; CodePointsToEntities[8501] = "alefsym"; CodePointsToEntities[8592] = "larr"; CodePointsToEntities[8593] = "uarr"; CodePointsToEntities[8594] = "rarr"; CodePointsToEntities[8595] = "darr"; CodePointsToEntities[8596] = "harr"; CodePointsToEntities[8629] = "crarr"; CodePointsToEntities[8656] = "lArr"; CodePointsToEntities[8657] = "uArr"; CodePointsToEntities[8658] = "rArr"; CodePointsToEntities[8659] = "dArr"; CodePointsToEntities[8660] = "hArr"; CodePointsToEntities[8704] = "forall"; CodePointsToEntities[8706] = "part"; CodePointsToEntities[8707] = "exist"; CodePointsToEntities[8709] = "empty"; CodePointsToEntities[8711] = "nabla"; CodePointsToEntities[8712] = "isin"; CodePointsToEntities[8713] = "notin"; CodePointsToEntities[8715] = "ni"; CodePointsToEntities[8719] = "prod"; CodePointsToEntities[8721] = "sum"; CodePointsToEntities[8722] = "minus"; CodePointsToEntities[8727] = "lowast"; CodePointsToEntities[8730] = "radic"; CodePointsToEntities[8733] = "prop"; CodePointsToEntities[8734] = "infin"; CodePointsToEntities[8736] = "ang"; CodePointsToEntities[8743] = "and"; CodePointsToEntities[8744] = "or"; CodePointsToEntities[8745] = "cap"; CodePointsToEntities[8746] = "cup"; CodePointsToEntities[8747] = "int"; CodePointsToEntities[8756] = "there4"; CodePointsToEntities[8764] = "sim"; CodePointsToEntities[8773] = "cong"; CodePointsToEntities[8776] = "asymp"; CodePointsToEntities[8800] = "ne"; CodePointsToEntities[8801] = "equiv"; CodePointsToEntities[8804] = "le"; CodePointsToEntities[8805] = "ge"; CodePointsToEntities[8834] = "sub"; CodePointsToEntities[8835] = "sup"; CodePointsToEntities[8836] = "nsub"; CodePointsToEntities[8838] = "sube"; CodePointsToEntities[8839] = "supe"; CodePointsToEntities[8853] = "oplus"; CodePointsToEntities[8855] = "otimes"; CodePointsToEntities[8869] = "perp"; CodePointsToEntities[8901] = "sdot"; CodePointsToEntities[8968] = "lceil"; CodePointsToEntities[8969] = "rceil"; CodePointsToEntities[8970] = "lfloor"; CodePointsToEntities[8971] = "rfloor"; CodePointsToEntities[9001] = "lang"; CodePointsToEntities[9002] = "rang"; CodePointsToEntities[9674] = "loz"; CodePointsToEntities[9824] = "spades"; CodePointsToEntities[9827] = "clubs"; CodePointsToEntities[9829] = "hearts"; CodePointsToEntities[9830] = "diams";
}
}
public static string Decode(string str)
{
Init();
return Regex.Replace(str, #"&(?:#(?<num>[0-9]+)|(?<named>[0-9A-Za-z]+));", delegate(Match m)
{
int charCode;
string captured;
if (m.Groups["num"].Captures.Count > 0)
{
if (!int.TryParse(m.Groups["num"].ToString(), out charCode))
{//Return unaffected
return m.Groups[0].ToString();
}
}
else
{
captured = m.Groups["named"].ToString();
if( EntitiesToCodePoints.ContainsKey(captured) ) {
charCode = EntitiesToCodePoints[captured];
}
else {
//Return unaffected
return m.Groups[0].ToString();
}
}
return Convert.ToChar(charCode).ToString();
});
}
public static string Encode(string str)
{
Init();
return Regex.Replace(str, #"[\u0080-\uDAFF\uE000-\uFFFF]", delegate(Match m)
{
int codePoint = (int)m.Value[0];
if (CodePointsToEntities.ContainsKey(codePoint))
{
return "&" + CodePointsToEntities[codePoint] + ";";
}
return "&#" + codePoint + ";";
});
}
}
}
PHP:
$a = "ɢ♠♤ä<>&'\"";
$b = mb_convert_encoding( $a, "HTML-ENTITIES", "UTF-8" );
echo $b; //ɢ♠♤ä<>&'"
echo mb_convert_encoding( $b, "UTF-8", "HTML-ENTITIES"); //ɢ♠♤ä<>&'"
C#
string a = "ɢ♠♤ä<>&'\"";
string b = HtmlEntities.Encode(a);
Console.WriteLine(b); //ɢ♠♤ä<>&'"
Console.WriteLine(HtmlEntities.Decode(b)); //ɢ♠♤ä<>&'"
Note: This cannot handle characters outside BMP, though such a requirement is so rare that it should be explicitly mentioned.

Here are some examples of conversions. The first two show how to convert, the last one can be turned into a function that takes two encoding names as strings, and convert.
A list of encoding names can be found here.
Encoding.UTF8.GetString(Encoding.ASCII.GetBytes(str));
Encoding.UTF8.GetString(Encoding.Unicode.GetBytes(str));
Encoding.GetEncoding("UTF-8").GetString(Encoding.GetEncoding("ASCII").GetBytes(str));

Related

SQL select query excluding a value in EF CORE

I have the LINQ query with the simple select statement which maps the columns from a table to the custom entity.
I have quite a few fields so I'm trying to select one by one and leave one field out. This way seems pretty silly to me. There was an option such as not select in SQL, it should have a counterpart in the entity framework.
I don't want to select the image area in this query. Do I have to write such a long code for this?
var result = from ch in _tenantDbContext.CariHesap
where ch.KartTipi == cariHesapKartTip
select new CariHesap
{
Id = ch.Id,
HesapKodu = ch.HesapKodu,
Unvan = ch.Unvan,
Ad = ch.Ad,
Soyad = ch.Soyad,
AktifPasif = ch.AktifPasif,
KartTipi = ch.KartTipi,
IslemTipi = ch.IslemTipi,
BakGostSekli = ch.BakGostSekli,
DvzTL = ch.DvzTL,
DovizCinsi = ch.DovizCinsi,
KrediLimiti = ch.KrediLimiti,
DvzKrediLimiti = ch.DvzKrediLimiti,
BolgeKod = ch.BolgeKod,
OzelKod = ch.OzelKod,
GrupKod = ch.GrupKod,
TipKod = ch.TipKod,
MhsKod = ch.MhsKod,
MasrafMerkezi = ch.MasrafMerkezi,
VergiDairesi = ch.VergiDairesi,
HesapNo = ch.HesapNo,
FaturaChk = ch.FaturaChk,
IskontoOran = ch.IskontoOran,
OpsiyonGunu = ch.OpsiyonGunu,
OdemeGunu = ch.OdemeGunu,
OdemePlani = ch.OdemePlani,
KulSatisFiyat = ch.KulSatisFiyat,
CHKodu = ch.CHKodu,
KDVTevfikatUygula = ch.KDVTevfikatUygula,
KDVMuaf = ch.KDVMuaf,
KDVMuafAck = ch.KDVMuafAck,
FormBaBsUnvan = ch.FormBaBsUnvan,
SirketEMail = ch.SirketEMail,
SirketWebAdres = ch.SirketWebAdres,
SatIslemEMail = ch.SatIslemEMail,
SatAlmaIslemEMail = ch.SatAlmaIslemEMail,
FinIslemEMail = ch.FinIslemEMail,
UnvanFaturadan = ch.UnvanFaturadan,
EFatSenaryo = ch.EFatSenaryo,
EIrsSenaryo = ch.EIrsSenaryo,
EMMSenaryo = ch.EMMSenaryo,
EFatEtiket = ch.EFatEtiket,
EIrsEtiket = ch.EIrsEtiket,
MusBrmSubeTanim = ch.MusBrmSubeTanim,
MusBrmSubeDeger = ch.MusBrmSubeDeger,
MusCHKoduTanim = ch.MusCHKoduTanim,
MusCHKoduDeger = ch.MusCHKoduDeger,
LegalEntityID = ch.LegalEntityID,
LegalEntityName = ch.LegalEntityName,
EArsivTeslimSekli = ch.EArsivTeslimSekli,
EArsivTeslimEMail1 = ch.EArsivTeslimEMail1,
EArsivTeslimEMail2 = ch.EArsivTeslimEMail2,
EArsivTeslimEMail3 = ch.EArsivTeslimEMail3,
FaturaXSLT = ch.FaturaXSLT,
IrsaliyeXSLT = ch.IrsaliyeXSLT,
SGKChk = ch.SGKChk,
SGKFaturaTipi = ch.SGKFaturaTipi,
KamuChk = ch.KamuChk,
Kod1 = ch.Kod1,
Kod2 = ch.Kod2,
Kod3 = ch.Kod3,
Kod4 = ch.Kod4,
Kod5 = ch.Kod5,
Kod6 = ch.Kod6,
Kod7 = ch.Kod7,
Kod8 = ch.Kod8,
Kod9 = ch.Kod9,
Kod10 = ch.Kod10,
Kod11 = ch.Kod11,
Kod12 = ch.Kod12,
Kod13 = ch.Kod13,
Kod14 = ch.Kod14,
Kod15 = ch.Kod15,
Nesne1 = ch.Nesne1,
Nesne2 = ch.Nesne2,
};

Dealing with bloomberg Blpapi element that returns HasElement() as True but causes not found exception

I am consuming trade and quote data with BLPAPI in C#. When I process a LAST_TRADE_PRICE_TIME_TODAY_RT like this using //blp/mktdata service and processing the SUBCRIPTION_DATA event fine except for this message element:
{MarketDataEvents = {
RT_TIME_OF_TRADE = 2022-06-23
INDICATIVE_NEAR =
IMBALANCE_BUY =
IMBALANCE_SELL =
ORDER_IMB_BUY_VOLUME =
ORDER_IMB_SELL_VOLUME =
THEO_PRICE =
IMBALANCE_INDIC_RT =
PREV_CLOSE_VALUE_REALTIME = 11737.5
TRADING_DT_REALTIME = 2022-06-24
PREV_TRADING_DT_REALTIME = 2022-06-23
PX_ASK_LME_OFFICIAL_RT =
NUM_TRADES_RT = 0
PX_OFFICIAL_AUCTION_RT =
LAST_UPDATE_BID_RT = 2022-06-23
LAST_UPDATE_ASK_RT = 2022-06-23
OFFICIAL_AUCTION_VOLUME_RT =
IN_AUCTION_RT =
TURNOVER_TODAY_REALTIME =
OFFICIAL_OPEN_AUCTION_PRICE_RT =
OFFICIAL_OPEN_AUCTION_VOLUME_RT =
OFFICIAL_CLOSE_AUCTION_PRICE_RT =
OFFICIAL_CLOSE_AUCTION_VOLUME_RT =
AUCTION_EXTENSION_RT =
BLOCK_TRADE_ACCUM_VOLUME_RT =
TOTAL_MSG_SCRAPED_OFFERS_RT =
EVENT_TIME = 22:30:00.000
VOLUME_THEO =
OPEN_YLD_TDY_RT =
HIGH_YLD_TDY_RT =
LOW_YLD_TDY_RT =
LAST_YLD_TDY =
MID_TDY =
SIZE_LAST_TRADE_TDY =
RT_PX_CHG_NET_1D = 171.75
RT_PX_CHG_PCT_1D = 1.485
OPEN_TDY =
ASK_SIZE_TDY =
BID_SIZE_TDY =
VOLUME_TDY =
LAST_PRICE_TDY =
BID_TDY =
ASK_TDY =
HIGH_TDY =
LOW_TDY =
BID_YLD_TDY =
ASK_YLD_TDY =
TIME = 2022-06-23
LAST_UPDATE_ALL_SESSIONS_RT =
PX_OPEN_ALL_WITH_SWITCHOVER_RT =
BID_ALL_SESSION_TDY_RT =
ASK_ALL_SESSION_TDY_RT =
CONTINUOUS_TRAD_CLOS_BID_PX_RT =
CONTINUOUS_TRAD_CLOS_ASK_PX_RT =
POST_CLOSING_AUCTION_BID_PX_RT =
POST_CLOSING_AUCTION_ASK_PX_RT =
LAST_TRADE_RECEIVED_TIME_RT =
PRICE_CHANGE_ON_DAY_RT = 171.75
PRICE_LAST_ASK_RT =
PRICE_LAST_BID_RT =
PRICE_HIGH_RT =
PRICE_LOW_RT =
PRICE_OPEN_RT =
LAST_TRADE_PRICE_TODAY_RT =
PREVIOUS_TOTAL_VOLUME_RT = 622197
PREVIOUS_CLOSE_ADJ_BY_GR_DVD_RT =
TIME_AUCTION_CALL_CONCLUSION_RT =
PER_TRADE_VWAP_REALTIME =
PER_TRADE_VWAP_TURNOVER_RT =
PER_TRADE_VWAP_VOLUME_RT =
OPEN_HIGH_PRICE_REALTIME =
OPEN_LOW_PRICE_REALTIME =
CLOSE_HIGH_PRICE_REALTIME =
CLOSE_LOW_PRICE_REALTIME =
EXCHANGE_FOR_PHYSICAL_VOLUME_RT =
EXCHANGE_FOR_SWAP_VOLUME_RT =
LAST_BID_TIME_TODAY_REALTIME =
LAST_ASK_TIME_TODAY_REALTIME =
LAST_MID_TIME_TODAY_REALTIME =
LAST_PRICE_TIME_TODAY_REALTIME =
LAST_TRADE_PRICE_TIME_TODAY_RT =
MINIMUM_ORDER_LIMIT_PRICE_RT =
MAXIMUM_ORDER_LIMIT_PRICE_RT =
MIN_DYNAMIC_TRADING_LIMIT_PX_RT =
MAX_DYNAMIC_TRADING_LIMIT_PX_RT =
15_SECOND_PRICE_CHANGE_RT =
1_MINUTE_PRICE_CHANGE_RT =
5_MINUTE_PRICE_CHANGE_RT =
15_MINUTE_PRICE_CHANGE_RT =
1_HOUR_PRICE_CHANGE_RT =
CIRCUIT_BREAKER_TRIG_SIGNAL_RT =
LAST_CONTINUOUS_TRADE_PRICE_RT =
DYNAMIC_TRADING_LIMITS_REF_PX_RT =
LAST_OFF_BOOK_TRADE_PRICE_RT =
CB_TRIGGER_SIGNAL_START_TIME_RT =
CB_TRIGGER_SIGNAL_END_TIME_RT =
EFFECTIVE_DATE_RT =
OPEN_TRADE_PRICE_TODAY_RT =
HIGH_TRADE_PRICE_TODAY_RT =
LOW_TRADE_PRICE_TODAY_RT =
EXCHANGE_FOR_RISK_VOLUME_RT =
BLOOMBERG_CLOSE_PRICE_TODAY_RT =
PRICE_CLOSE_CC_TODAY_RT =
SUB_SEC_TM_AUCT_CALL_CNCLSN_RT =
THEORETICAL_TIME_TODAY_RT =
ON_EXCHANGE_VOLUME_TODAY_RT =
ON_BOOK_VOLUME_TODAY_RT =
LIT_BOOK_VOLUME_TODAY_RT =
CONTINUOUS_VOLUME_TODAY_RT =
AUCTION_VOLUME_TODAY_RT =
SCHEDULED_AUCT_VOLUME_TODAY_RT =
OPENING_AUCTION_VOLUME_RT =
CLOSING_AUCTION_VOLUME_RT =
INTRADAY_AUCTION_VOLUME_TODAY_RT =
UNSCHEDULED_AUCT_VOLUME_TODAY_RT =
TRADE_LAST_CLOSE_VOLUME_TODAY_RT =
PRE_POST_AUTO_EXECTN_VOL_TDY_RT =
DARK_BOOK_VOLUME_TODAY_RT =
ON_BK_NEG_BTF_OR_CC_VOL_TDY_RT =
ODD_LOT_BOOK_VOLUME_TODAY_RT =
OFF_BOOK_VOLUME_TODAY_RT =
NEGOTIATED_VOLUME_TODAY_RT =
OFF_BK_BLOCK_OR_CC_VOLUME_TDY_RT =
OFF_BOOK_ODD_LOT_VOLUME_TODAY_RT =
OTC_VOLUME_TODAY_RT =
SYSTEMATIC_INTERNAL_VOL_TDY_RT =
REPORTED_DARK_VOLUME_TODAY_RT =
PERCENT_CHANGE_ON_DAY_TODAY_RT =
NET_CHANGE_ON_DAY_TODAY_RT =
LAST_TRADE_AM_SESSION_TODAY_RT =
OPEN_PRICE_AM_SESSION_TODAY_RT =
HIGH_PRICE_AM_SESSION_TODAY_RT =
LOW_PRICE_AM_SESSION_TODAY_RT =
VOLUME_AM_SESSION_TODAY_RT =
LAST_TRADE_PM_SESSION_TODAY_RT =
OPEN_PRICE_PM_SESSION_TODAY_RT =
HIGH_PRICE_PM_SESSION_TODAY_RT =
LOW_PRICE_PM_SESSION_TODAY_RT =
VOLUME_PM_SESSION_TODAY_RT =
EXCHANGE_VWAP_TODAY_RT =
SETTLEMENT_PRESENT_VALUE_RT =
MATURITY_CALIBRATION_RATE_RT =
MATURITY_CALIBRATION_PV_RT =
CONTRIBUTED_RECOVERY_RATE_RT =
PAR_SPREAD_BID_RT =
PAR_SPREAD_ASK_RT =
LIQUIDITY_INDICATOR_RT =
PRICE_BID_CLOSE_TODAY_RT =
PRICE_ASK_CLOSE_TODAY_RT =
OFFICIAL_CLOSE_TODAY_RT =
PREVIOUS_BLOOMBERG_CLOSE_PX_RT = 11737.5
PREVIOUS_LAST_TRADE_PRICE_RT = 11688
BLOOMBERG_SEND_TIME_RT = 2022-06-23T21:31:23.469+00:00
10_MINUTE_PRICE_CHANGE_RT =
30_MINUTE_PRICE_CHANGE_RT =
BLOOMBERG_CLOSE_PX_AM_TODAY_RT =
PERIODIC_AUCT_ON_DMD_VOL_TDY_RT =
PERIODIC_AUCT_ON_DMD_THEO_PX_RT =
CHG_NET_REG_SES_PRV_RG_SES_CL_RT =
CHG_PCT_REG_SES_PRV_RG_SES_CL_RT =
ACTUAL_TRADED_PRICE_RT =
MIN_DYNMC_BID_ORDR_LIMT_PX_RT =
MAXMM_DYNMC_BID_ORDR_LIMT_PX_RT =
MIN_DYNMC_ASK_ORDR_LIMT_PX_RT =
MAXMM_DYNMC_ASK_ORDR_LIMT_PX_RT =
MKTDATA_EVENT_TYPE = SUMMARY
MKTDATA_EVENT_SUBTYPE = NEWDAY
DELTA_AVAT_30_DAY_INTERVAL =
DELTA_AVAT_1_DAY_INTERVAL =
DELTA_AVAT_5_DAY_INTERVAL =
DELTA_AVAT_10_DAY_INTERVAL =
DELTA_AVAT_20_DAY_INTERVAL =
DELTA_AVAT_100_DAY_INTERVAL =
DELTA_AVAT_180_DAY_INTERVAL =
DELTA_ATAT_1_DAY_INTERVAL =
DELTA_ATAT_5_DAY_INTERVAL =
DELTA_ATAT_10_DAY_INTERVAL =
DELTA_ATAT_20_DAY_INTERVAL =
DELTA_ATAT_30_DAY_INTERVAL =
DELTA_ATAT_100_DAY_INTERVAL =
DELTA_ATAT_180_DAY_INTERVAL =
REALTIME_15_SEC_PRICE_PCT_CHG =
REALTIME_ONE_MIN_PRICE_PCT_CHG =
REALTIME_FIVE_MIN_PRICE_PCT_CHG =
REALTIME_15_MIN_PRICE_PCT_CHG =
REALTIME_ONE_HOUR_PRICE_PCT_CHG =
REALTIME_VOLUME_5_DAY_INTERVAL =
CURRENT_SESSION_RT = 4
IMPLIED_BID_PRICE_RT =
IMPLIED_ASK_PRICE_RT =
IMPLIED_BID_SIZE_RT =
IMPLIED_ASK_SIZE_RT =
IS_DELAYED_STREAM = false
}
}
I use this to check the datetime and emit a trade event:
if (message.HasElement(LAST_TIME))
{
if (message.GetElementAsDatetime(LAST_TIME).IsValid())
{
DateTime time = message.GetElementAsDatetime(LAST_TIME).ToSystemDateTime();
if (message.HasElement(LAST) && message.HasElement(SIZE))
{
double last = message.GetElementAsFloat64(LAST);
int last_size = message.GetElementAsInt32(SIZE);
long volume = message.GetElementAsInt64(VOLUME); ...
I receive:
'Bloomberglp.Blpapi.NotFoundException: LAST_TRADE_PRICE_TIME_TODAY_RT has no value in MarketDataUpdate.'
I have tried converting to string first and checking if empty and checking null. Any ideas would be helpful...
I don't think checking the DataType is what you want. The
DataType is part of the schema. It should always be set even when there is no value. If it seems to be working, it is possibly because the element's data type is not DATETIME. For instance, if it is of type DATE, or TIME, GetAsDateTime would still work, but the DataType will never be DATETIME—meaning the code path will never get hit. What you want to check is if it has a value.
HasElement is saying that the schema contains such an element, but if the schema definition allows for there to be zero values (optional), it might not have a value. GetValueAsDatetime() is really GetValueAsDatetime(0), meaning the 0th value which may not exist. Note the same function can be used for array type items that have more than one value. I think the correct way to check this would be:
Element lastTime = message.GetElement(LAST_TIME);
if (lastTime.NumValues > 0) {
DateTime dt = lastTime.GetValueAsDatetime();
I suspect that
if (message.HasElement(LAST_TIME))
returns true because the field is there (but empty). However when you call:
if (message.GetElementAsDatetime(LAST_TIME).IsValid())
GetElementAsDatetime throws an exception because the value (which is empty) is not a valid datetime.
I think something like this may work:
Element lastTime = message.GetElement(LAST_TIME);
if (lastTime.Datatype() == Schema.Datatype.DATETIME) {
DateTime dt = lastTime.GetValueAsDatetime();

You must write ContentLength bytes to the request stream before calling [Begin]GetResponse UPS

i know there are other questions that have been asked like that but that seems to be different, this error happens when i want to get quote for the shipping in UPS
RateReturn returnObject = new RateReturn();
UPSParamShipmentRequest shipRequest = UPS_ShipRequest();
returnObject = _UpsShipping.GetQuote(shipRequest)
shipRequest is parameters that i fill to send :
private UPSParamShipmentRequest UPS_ShipRequest()
{
UPSParamShipmentRequest shipRequest = new UPSParamShipmentRequest();
#region shipRequest
shipRequest.ServiceCode = rcbUPSServiceType.Text;
shipRequest.PackageCount = "1";
shipRequest.PackagingType = rcbUPSPackagingType.Text;
//shipRequest.FreightClass = rcbUPSFreightClass.Text;
shipRequest.PackageWeight = Utilities.NumberUtils.ConvertToInt(rtbUPSWeight.Value).ToString();
shipRequest.CommodityValueCurrencyCode = "USD";
shipRequest.CommodityValueMonetaryValue = rtbUPSValue.Text;
shipRequest.CommodityDescription = rtbUPSDescription.Text;
//shipRequest.HandlingUnitType = rcbUPSHandlingType.Text;
shipRequest.UnitOfMeasurementCode = rcbUPSWeightUnit.Text.Split('-')[0].TrimEnd(); //"lbs";
shipRequest.UnitOfMeasurementDescription = rcbUPSWeightUnit.Text.Split('-')[1].TrimStart();// "pounds";
shipRequest.CommodityLength = Utilities.NumberUtils.ConvertToInt(rtbUPSLength.Value).ToString();
shipRequest.CommodityHeight = Utilities.NumberUtils.ConvertToInt(rtbUPSHeight.Value).ToString();
shipRequest.CommodityWidth = Utilities.NumberUtils.ConvertToInt(rtbUPSWidth.Value).ToString();
shipRequest.CommodityDimensionsUnitOfMeasurementCode = rcbUPSDimensionUnit.Text.Split('-')[0].TrimEnd();
shipRequest.CommodityDimensionsUnitOfMeasurementDesc = rcbUPSDimensionUnit.Text.Split('-')[1].TrimStart();
#endregion
#region ShipmentSender
Sender oSender = new Sender();
oSender.PersonName = rtbSenderName.Text;//
oSender.CompanyName = rtbSenderCompany.Text;//
oSender.PhoneNumber = rtbSenderPhone.Text;//
oSender.Address1 = rtbSenderAddress1.Text;//
oSender.Address2 = rtbSenderAddress2.Text;//
oSender.City = rtbSenderCity.Text;// "Austin";
oSender.StateOrProvinceCode = rtbSenderState.Text;//
oSender.PostalCode = rtbSenderZip.Text;//
oSender.CountryCode = rtbSenderCountry.Text;//
shipRequest.ShipmentSender = oSender;
#endregion
#region ShipmentRecipient
Recipient oRecipient = new Recipient();
oRecipient.TinType = "BUSINESS_UNION";
oRecipient.TinNumber = "XXX"; //
oRecipient.PersonName = rtbRecipientName.Text;//
oRecipient.CompanyName = rtbRecipientCompany.Text;//
oRecipient.PhoneNumber = rtbRecipientPhone.Text;//
oRecipient.Address1 = rtbRecipientAddress1.Text;//
oRecipient.Address2 = rtbRecipientAddress2.Text;//
oRecipient.City = rtbRecipientCity.Text;//
oRecipient.StateOrProvinceCode = rtbRecipientState.Text;//
oRecipient.PostalCode = rtbRecipientZip.Text;//
oRecipient.CountryCode = rtbRecipientCountry.Text;//
oRecipient.IsResidential = false;
shipRequest.ShipmentRecipient = oRecipient;
#endregion
#region ShipmentPayer
Payer oPayer = new Payer();
oPayer.PersonName = rtbUPSPayerName.Text;//
oPayer.CompanyName = rtbUPSPayerCompany.Text;//
oPayer.PhoneNumber = rtbUPSPayerPhone.Text;//
oPayer.Address1 = rtbUPSPayerAddress1.Text;//
oPayer.Address2 = rtbUPSPayerAddress2.Text;//
oPayer.City = rtbUPSPayerCity.Text;//
oPayer.StateOrProvinceCode = rtbUPSPayerState.Text;//
oPayer.PostalCode = rtbUPSPayerZip.Text;//
oPayer.CountryCode = rtbUPSPayerCountry.Text;//
shipRequest.ShipmentPayer = oPayer;
#endregion
#region Payment
shipRequest.ShipBillOption = rcpUPSBillOption.Text;
#endregion
return shipRequest;
}
solutions in other question was to "stream.Close()" after writing the stream but i can't seem to be able to control that because it is a request to UPS, is there a way to be able to close that stream ?

How can i change the cursor (image) in the whole windows OS

I need to change the cursor in all windows, not just in the application, i have try this:
this.Cursor = Cursors.WaitCursor;
And this:
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
But it only changes the cursor in my application.
Any idea?
Assuming you have your own cursor file (.cur) to apply you could hack this.
First you will have to change thje default Arrow cursor in the Registry, then you will need to call some P-Invoke to allow the OS to update the current sytem paramerters so the cursor actually changes.
Somthing like:
private void ChangeCursor(string curFile)
{
Registry.SetValue(#"HKEY_CURRENT_USER\Control Panel\Cursors\", "Arrow", curFile);
SystemParametersInfo(SPI_SETCURSORS, 0, null, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
}
const int SPI_SETCURSORS = 0x0057;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDCHANGE = 0x02;
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint? pvParam, uint fWinIni);
Usage:
ChangeCursor(#"C:\MyCursor.cur");
You cannot change the cursor of the entire OS without modifying the registry.
You need to modify the registry to change the cursor.
See here for a tutorial and the exact Registry keys you need to modify - programmatically.
http://www.thebitguru.com/articles/14-Programmatically+Changing+Windows+Mouse+Cursors
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref uint pvParam, uint fWinIni);
public enum SystemParametersInfoAction : uint
{
SPI_GETBEEP = 0x0001,
SPI_SETBEEP = 0x0002,
SPI_GETMOUSE = 0x0003,
SPI_SETMOUSE = 0x0004,
SPI_GETBORDER = 0x0005,
SPI_SETBORDER = 0x0006,
SPI_GETKEYBOARDSPEED = 0x000A,
SPI_SETKEYBOARDSPEED = 0x000B,
SPI_LANGDRIVER = 0x000C,
SPI_ICONHORIZONTALSPACING = 0x000D,
SPI_GETSCREENSAVETIMEOUT = 0x000E,
SPI_SETSCREENSAVETIMEOUT = 0x000F,
SPI_GETSCREENSAVEACTIVE = 0x0010,
SPI_SETSCREENSAVEACTIVE = 0x0011,
SPI_GETGRIDGRANULARITY = 0x0012,
SPI_SETGRIDGRANULARITY = 0x0013,
SPI_SETDESKWALLPAPER = 0x0014,
SPI_SETDESKPATTERN = 0x0015,
SPI_GETKEYBOARDDELAY = 0x0016,
SPI_SETKEYBOARDDELAY = 0x0017,
SPI_ICONVERTICALSPACING = 0x0018,
SPI_GETICONTITLEWRAP = 0x0019,
SPI_SETICONTITLEWRAP = 0x001A,
SPI_GETMENUDROPALIGNMENT = 0x001B,
SPI_SETMENUDROPALIGNMENT = 0x001C,
SPI_SETDOUBLECLKWIDTH = 0x001D,
SPI_SETDOUBLECLKHEIGHT = 0x001E,
SPI_GETICONTITLELOGFONT = 0x001F,
SPI_SETDOUBLECLICKTIME = 0x0020,
SPI_SETMOUSEBUTTONSWAP = 0x0021,
SPI_SETICONTITLELOGFONT = 0x0022,
SPI_GETFASTTASKSWITCH = 0x0023,
SPI_SETFASTTASKSWITCH = 0x0024,
SPI_SETDRAGFULLWINDOWS = 0x0025,
SPI_GETDRAGFULLWINDOWS = 0x0026,
SPI_GETNONCLIENTMETRICS = 0x0029,
SPI_SETNONCLIENTMETRICS = 0x002A,
SPI_GETMINIMIZEDMETRICS = 0x002B,
SPI_SETMINIMIZEDMETRICS = 0x002C,
SPI_GETICONMETRICS = 0x002D,
SPI_SETICONMETRICS = 0x002E,
SPI_SETWORKAREA = 0x002F,
SPI_GETWORKAREA = 0x0030,
SPI_SETPENWINDOWS = 0x0031,
SPI_GETHIGHCONTRAST = 0x0042,
SPI_SETHIGHCONTRAST = 0x0043,
SPI_GETKEYBOARDPREF = 0x0044,
SPI_SETKEYBOARDPREF = 0x0045,
SPI_GETSCREENREADER = 0x0046,
SPI_SETSCREENREADER = 0x0047,
SPI_GETANIMATION = 0x0048,
SPI_SETANIMATION = 0x0049,
SPI_GETFONTSMOOTHING = 0x004A,
SPI_SETFONTSMOOTHING = 0x004B,
SPI_SETDRAGWIDTH = 0x004C,
SPI_SETDRAGHEIGHT = 0x004D,
SPI_SETHANDHELD = 0x004E,
SPI_GETLOWPOWERTIMEOUT = 0x004F,
SPI_GETPOWEROFFTIMEOUT = 0x0050,
SPI_SETLOWPOWERTIMEOUT = 0x0051,
SPI_SETPOWEROFFTIMEOUT = 0x0052,
SPI_GETLOWPOWERACTIVE = 0x0053,
SPI_GETPOWEROFFACTIVE = 0x0054,
SPI_SETLOWPOWERACTIVE = 0x0055,
SPI_SETPOWEROFFACTIVE = 0x0056,
SPI_SETCURSORS = 0x0057,
SPI_SETICONS = 0x0058,
SPI_GETDEFAULTINPUTLANG = 0x0059,
SPI_SETDEFAULTINPUTLANG = 0x005A,
SPI_SETLANGTOGGLE = 0x005B,
SPI_GETWINDOWSEXTENSION = 0x005C,
SPI_SETMOUSETRAILS = 0x005D,
SPI_GETMOUSETRAILS = 0x005E,
SPI_SETSCREENSAVERRUNNING = 0x0061,
SPI_SCREENSAVERRUNNING = SPI_SETSCREENSAVERRUNNING,
SPI_GETFILTERKEYS = 0x0032,
SPI_SETFILTERKEYS = 0x0033,
SPI_GETTOGGLEKEYS = 0x0034,
SPI_SETTOGGLEKEYS = 0x0035,
SPI_GETMOUSEKEYS = 0x0036,
SPI_SETMOUSEKEYS = 0x0037,
SPI_GETSHOWSOUNDS = 0x0038,
SPI_SETSHOWSOUNDS = 0x0039,
SPI_GETSTICKYKEYS = 0x003A,
SPI_SETSTICKYKEYS = 0x003B,
SPI_GETACCESSTIMEOUT = 0x003C,
SPI_SETACCESSTIMEOUT = 0x003D,
SPI_GETSERIALKEYS = 0x003E,
SPI_SETSERIALKEYS = 0x003F,
SPI_GETSOUNDSENTRY = 0x0040,
SPI_SETSOUNDSENTRY = 0x0041,
SPI_GETSNAPTODEFBUTTON = 0x005F,
SPI_SETSNAPTODEFBUTTON = 0x0060,
SPI_GETMOUSEHOVERWIDTH = 0x0062,
SPI_SETMOUSEHOVERWIDTH = 0x0063,
SPI_GETMOUSEHOVERHEIGHT = 0x0064,
SPI_SETMOUSEHOVERHEIGHT = 0x0065,
SPI_GETMOUSEHOVERTIME = 0x0066,
SPI_SETMOUSEHOVERTIME = 0x0067,
SPI_GETWHEELSCROLLLINES = 0x0068,
SPI_SETWHEELSCROLLLINES = 0x0069,
SPI_GETMENUSHOWDELAY = 0x006A,
SPI_SETMENUSHOWDELAY = 0x006B,
SPI_GETWHEELSCROLLCHARS = 0x006C,
SPI_SETWHEELSCROLLCHARS = 0x006D,
SPI_GETSHOWIMEUI = 0x006E,
SPI_SETSHOWIMEUI = 0x006F,
SPI_GETMOUSESPEED = 0x0070,
SPI_SETMOUSESPEED = 0x0071,
SPI_GETSCREENSAVERRUNNING = 0x0072,
SPI_GETDESKWALLPAPER = 0x0073,
SPI_GETAUDIODESCRIPTION = 0x0074,
SPI_SETAUDIODESCRIPTION = 0x0075,
SPI_GETSCREENSAVESECURE = 0x0076,
SPI_SETSCREENSAVESECURE = 0x0077,
SPI_GETHUNGAPPTIMEOUT = 0x0078,
SPI_SETHUNGAPPTIMEOUT = 0x0079,
SPI_GETWAITTOKILLTIMEOUT = 0x007A,
SPI_SETWAITTOKILLTIMEOUT = 0x007B,
SPI_GETWAITTOKILLSERVICETIMEOUT = 0x007C,
SPI_SETWAITTOKILLSERVICETIMEOUT = 0x007D,
SPI_GETMOUSEDOCKTHRESHOLD = 0x007E,
SPI_SETMOUSEDOCKTHRESHOLD = 0x007F,
SPI_GETPENDOCKTHRESHOLD = 0x0080,
SPI_SETPENDOCKTHRESHOLD = 0x0081,
SPI_GETWINARRANGING = 0x0082,
SPI_SETWINARRANGING = 0x0083,
SPI_GETMOUSEDRAGOUTTHRESHOLD = 0x0084,
SPI_SETMOUSEDRAGOUTTHRESHOLD = 0x0085,
SPI_GETPENDRAGOUTTHRESHOLD = 0x0086,
SPI_SETPENDRAGOUTTHRESHOLD = 0x0087,
SPI_GETMOUSESIDEMOVETHRESHOLD = 0x0088,
SPI_SETMOUSESIDEMOVETHRESHOLD = 0x0089,
SPI_GETPENSIDEMOVETHRESHOLD = 0x008A,
SPI_SETPENSIDEMOVETHRESHOLD = 0x008B,
SPI_GETDRAGFROMMAXIMIZE = 0x008C,
SPI_SETDRAGFROMMAXIMIZE = 0x008D,
SPI_GETSNAPSIZING = 0x008E,
SPI_SETSNAPSIZING = 0x008F,
SPI_GETDOCKMOVING = 0x0090,
SPI_SETDOCKMOVING = 0x0091,
SPI_GETACTIVEWINDOWTRACKING = 0x1000,
SPI_SETACTIVEWINDOWTRACKING = 0x1001,
SPI_GETMENUANIMATION = 0x1002,
SPI_SETMENUANIMATION = 0x1003,
SPI_GETCOMBOBOXANIMATION = 0x1004,
SPI_SETCOMBOBOXANIMATION = 0x1005,
SPI_GETLISTBOXSMOOTHSCROLLING = 0x1006,
SPI_SETLISTBOXSMOOTHSCROLLING = 0x1007,
SPI_GETGRADIENTCAPTIONS = 0x1008,
SPI_SETGRADIENTCAPTIONS = 0x1009,
SPI_GETKEYBOARDCUES = 0x100A,
SPI_SETKEYBOARDCUES = 0x100B,
SPI_GETMENUUNDERLINES = SPI_GETKEYBOARDCUES,
SPI_SETMENUUNDERLINES = SPI_SETKEYBOARDCUES,
SPI_GETACTIVEWNDTRKZORDER = 0x100C,
SPI_SETACTIVEWNDTRKZORDER = 0x100D,
SPI_GETHOTTRACKING = 0x100E,
SPI_SETHOTTRACKING = 0x100F,
SPI_GETMENUFADE = 0x1012,
SPI_SETMENUFADE = 0x1013,
SPI_GETSELECTIONFADE = 0x1014,
SPI_SETSELECTIONFADE = 0x1015,
SPI_GETTOOLTIPANIMATION = 0x1016,
SPI_SETTOOLTIPANIMATION = 0x1017,
SPI_GETTOOLTIPFADE = 0x1018,
SPI_SETTOOLTIPFADE = 0x1019,
SPI_GETCURSORSHADOW = 0x101A,
SPI_SETCURSORSHADOW = 0x101B,
SPI_GETMOUSESONAR = 0x101C,
SPI_SETMOUSESONAR = 0x101D,
SPI_GETMOUSECLICKLOCK = 0x101E,
SPI_SETMOUSECLICKLOCK = 0x101F,
SPI_GETMOUSEVANISH = 0x1020,
SPI_SETMOUSEVANISH = 0x1021,
SPI_GETFLATMENU = 0x1022,
SPI_SETFLATMENU = 0x1023,
SPI_GETDROPSHADOW = 0x1024,
SPI_SETDROPSHADOW = 0x1025,
SPI_GETBLOCKSENDINPUTRESETS = 0x1026,
SPI_SETBLOCKSENDINPUTRESETS = 0x1027,
SPI_GETUIEFFECTS = 0x103E,
SPI_SETUIEFFECTS = 0x103F,
SPI_GETDISABLEOVERLAPPEDCONTENT = 0x1040,
SPI_SETDISABLEOVERLAPPEDCONTENT = 0x1041,
SPI_GETCLIENTAREAANIMATION = 0x1042,
SPI_SETCLIENTAREAANIMATION = 0x1043,
SPI_GETCLEARTYPE = 0x1048,
SPI_SETCLEARTYPE = 0x1049,
SPI_GETSPEECHRECOGNITION = 0x104A,
SPI_SETSPEECHRECOGNITION = 0x104B,
SPI_GETFOREGROUNDLOCKTIMEOUT = 0x2000,
SPI_SETFOREGROUNDLOCKTIMEOUT = 0x2001,
SPI_GETACTIVEWNDTRKTIMEOUT = 0x2002,
SPI_SETACTIVEWNDTRKTIMEOUT = 0x2003,
SPI_GETFOREGROUNDFLASHCOUNT = 0x2004,
SPI_SETFOREGROUNDFLASHCOUNT = 0x2005,
SPI_GETCARETWIDTH = 0x2006,
SPI_SETCARETWIDTH = 0x2007,
SPI_GETMOUSECLICKLOCKTIME = 0x2008,
SPI_SETMOUSECLICKLOCKTIME = 0x2009,
SPI_GETFONTSMOOTHINGTYPE = 0x200A,
SPI_SETFONTSMOOTHINGTYPE = 0x200B,
SPI_GETFONTSMOOTHINGCONTRAST = 0x200C,
SPI_SETFONTSMOOTHINGCONTRAST = 0x200D,
SPI_GETFOCUSBORDERWIDTH = 0x200E,
SPI_SETFOCUSBORDERWIDTH = 0x200F,
SPI_GETFOCUSBORDERHEIGHT = 0x2010,
SPI_SETFOCUSBORDERHEIGHT = 0x2011,
SPI_GETFONTSMOOTHINGORIENTATION = 0x2012,
SPI_SETFONTSMOOTHINGORIENTATION = 0x2013,
SPI_GETMINIMUMHITRADIUS = 0x2014,
SPI_SETMINIMUMHITRADIUS = 0x2015,
SPI_GETMESSAGEDURATION = 0x2016,
SPI_SETMESSAGEDURATION = 0x2017,
}

c#: Using Linq to get a IEnumerable collection of XML Nodes to Traverse

I have some code that is using the following xml file. Can someone tell me why my doc.Descendants is returning null?
Here is the XML File:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<EmployerTPASeparationResponseCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://uidataexchange.org/schemas SeparationResponse.xsd" xmlns="https://uidataexchange.org/schemas">
<EmployerTPASeparationResponse>
<StateRequestRecordGUID>94321098761987654321323456109883</StateRequestRecordGUID>
<BrokerRecordTransactionNumber>123456789</BrokerRecordTransactionNumber>
<SSN>999999999</SSN>
<ClaimEffectiveDate>2011-02-09</ClaimEffectiveDate>
<ClaimNumber>1234568010</ClaimNumber>
<StateEmployerAccountNbr>12345689</StateEmployerAccountNbr>
<ClaimantJobTitle>Assistant Manager</ClaimantJobTitle>
<EmployerReportedClaimantFirstDayofWork>2009-02-02</EmployerReportedClaimantFirstDayofWork>
<EmployerReportedClaimantLastDayofWork>2010-03-16</EmployerReportedClaimantLastDayofWork>
<TotalEarnedWagesNeededInd>2</TotalEarnedWagesNeededInd>
<TotalEarnedWages>15000.00</TotalEarnedWages>
<WagesEarnedAfterClaimEffectiveDate>20000.00</WagesEarnedAfterClaimEffectiveDate>
<NumberOfHoursWorkedAfterClaimEffectiveDate>80</NumberOfHoursWorkedAfterClaimEffectiveDate>
<AverageWeeklyWage>10.00</AverageWeeklyWage>
<EmployerSepReasonCode>2</EmployerSepReasonCode>
<EmployerSepReasonComments>Expected return date back to work is 4/25/11</EmployerSepReasonComments>
<PreparerTypeCode>T</PreparerTypeCode>
<PreparerCompanyName>Barnett Associates</PreparerCompanyName>
<PreparerTelephoneNumberPlusExt>5555555555</PreparerTelephoneNumberPlusExt>
<PreparerContactName>Diana Turkoane</PreparerContactName>
<PreparerTitle>CSR</PreparerTitle>
<PreparerFaxNbr>5555555555</PreparerFaxNbr>
<PreparerEmailAddress>asdf#asdf.com</PreparerEmailAddress>
</EmployerTPASeparationResponse>
<EmployerTPASeparationResponse>
<StateRequestRecordGUID>94321098761987654321323456109884</StateRequestRecordGUID>
<BrokerRecordTransactionNumber>123456789</BrokerRecordTransactionNumber>
<SSN>999999999</SSN>
<ClaimEffectiveDate>2011-02-10</ClaimEffectiveDate>
<ClaimNumber>1234568010</ClaimNumber>
<StateEmployerAccountNbr>12345689</StateEmployerAccountNbr>
<ClaimantJobTitle>Assistant Manager</ClaimantJobTitle>
<EmployerReportedClaimantFirstDayofWork>2009-02-03</EmployerReportedClaimantFirstDayofWork>
<EmployerReportedClaimantLastDayofWork>2010-03-17</EmployerReportedClaimantLastDayofWork>
<EmployerSepReasonCode>2</EmployerSepReasonCode>
<EmployerSepReasonComments>Expected return date back to work is 4/30/11</EmployerSepReasonComments>
<PreparerTypeCode>T</PreparerTypeCode>
<PreparerCompanyName>Barnett Associates</PreparerCompanyName>
<PreparerTelephoneNumberPlusExt>5555555555</PreparerTelephoneNumberPlusExt>
<PreparerContactName>Diana Turkoane</PreparerContactName>
<PreparerTitle>CSR</PreparerTitle>
<PreparerFaxNbr>5555555555</PreparerFaxNbr>
<PreparerEmailAddress>asdf#asdf.com</PreparerEmailAddress>
</EmployerTPASeparationResponse>
</EmployerTPASeparationResponseCollection>
Here is the code I am using. I first use some Linq to get the Anonymous values, then try to loop through each child node and populate with cmd.parameters.
Here is the code:
XDocument doc = XDocument.Load("XmlString.xml");
var EmployerTPASeparationResponse =
from node in doc.Descendants("EmployerTPASeparationResponse")
select new
{
param1 = node.Element("StateRequestRecordGUID").Value,
param2 = node.Element("BrokerRecordTransactionNumber").Value,
param3 = node.Element("SSN").Value,
param4 = node.Element("ClaimEffectiveDate").Value,
param5 = node.Element("ClaimNumber").Value,
param6 = node.Element("StateEmployerAccountNbr").Value,
param7 = node.Element("CorrectedEmployerName").Value,
param8 = node.Element("CorrectedStateEmployerAccountNbr").Value,
param9 = node.Element("CorrectedFEIN").Value,
param10 = node.Element("OtherSSN").Value,
param11 = node.Element("ClaimantNameWorkedAsForEmployers").Value,
param12 = node.Element("ClaimantJobTitle").Value,
param13 = node.Element("SeasonalEmploymentInd").Value,
param14 = node.Element("EmployerReportedClaimantFirstDayofWork").Value,
param15 = node.Element("EmployerReportedClaimantLastDayofWork").Value,
param16 = node.Element("EffectiveSeparationDate").Value,
param17 = node.Element("TotalEarnedWagesNeededInd").Value,
param18 = node.Element("TotalEarnedWages").Value,
param19 = node.Element("TotalWeeksWorkedNeededInd").Value,
param20 = node.Element("TotalWeeksWorked").Value,
param21 = node.Element("WagesEarnedAfterClaimEffectiveDate").Value,
param22 = node.Element("NumberOfHoursWorkedAfterClaimEffectiveDate").Value,
param23 = node.Element("AverageWeeklyWage").Value,
param24 = node.Element("EmployerSepReasonCode").Value,
param25 = node.Element("ReturnToWorkInd").Value,
param26 = node.Element("ReturnToWorkDate").Value,
param27 = node.Element("WorkingAllAvailableHoursInd").Value,
param28 = node.Element("NotWorkingAvailableHoursReason").Value,
param29 = node.Element("DischargeReasonCode").Value,
param30 = node.Element("FinalIncidentReason").Value,
param31 = node.Element("FinalIncidentDate").Value,
param32 = node.Element("ViolateCompanyPolicyInd").Value,
param33 = node.Element("DischargePolicyAwareInd").Value,
param34 = node.Element("DischargePolicyAwareExplanationCode").Value,
param35 = node.Element("WhoDischargedName").Value,
param36 = node.Element("WhoDischargedTitle").Value,
param37 = node.Element("DischargeReasonComments").Value,
param38 = node.Element("VoluntarySepReasonCode").Value,
param39 = node.Element("HiringAgreementChangesCode").Value,
param40 = node.Element("HiringAgreementChangeComments").Value,
param41 = node.Element("ClaimantActionstoAvoidQuitInd").Value,
param42 = node.Element("ActionTakenComments").Value,
param43 = node.Element("ContinuingWorkAvailableInd").Value,
param44 = node.Element("VoluntarySepReasonComments").Value,
param45 = node.Element("AmendedResponse").Value,
param46 = node.Element("AmendedResponseDescription").Value,
param47 = node.Element("EmployerSepReasonComments").Value,
param48 = node.Element("LaborDisputeTypeInd").Value,
param49 = node.Element("AttachmentID").Value,
param50 = node.Element("MandatoryRetirementInd").Value,
param51 = node.Element("PriorIncidentID").Value,
param52 = node.Element("PreparerTypeCode").Value,
param53 = node.Element("PreparerCompanyName").Value,
param54 = node.Element("PreparerTelephoneNumberPlusExt").Value,
param55 = node.Element("PreparerContactName").Value,
param56 = node.Element("PreparerTitle").Value,
param57 = node.Element("PreparerFaxNbr").Value,
param58 = node.Element("PreparerEmailAddress").Value,
};
foreach (var node in EmployerTPASeparationResponse)
{
cmd4.Parameters["StateRequestRecordGUID"].Value = node.param1;
cmd4.Parameters["BrokerRecordTransactionNumber"].Value = node.param2;
cmd4.Parameters["SSN"].Value = node.param3;
cmd4.Parameters["ClaimEffectiveDate"].Value = node.param4;
cmd4.Parameters["ClaimNumber"].Value = node.param5;
cmd4.Parameters["StateEmployerAccountNbr"].Value = node.param6;
cmd4.Parameters["CorrectedEmployerName"].Value = node.param7;
cmd4.Parameters["CorrectedStateEmployerAccountNbr"].Value = node.param8;
cmd4.Parameters["CorrectedFEIN"].Value = node.param9;
cmd4.Parameters["OtherSSN"].Value = node.param10;
cmd4.Parameters["ClaimantNameWorkedAsForEmployers"].Value = node.param11;
cmd4.Parameters["ClaimantJobTitle"].Value = node.param12;
cmd4.Parameters["SeasonalEmploymentInd"].Value = node.param13;
cmd4.Parameters["EmployerReportedClaimantFirstDayofWork"].Value = node.param14;
cmd4.Parameters["EmployerReportedClaimantLastDayofWork"].Value = node.param15;
cmd4.Parameters["EffectiveSeparationDate"].Value = node.param16;
cmd4.Parameters["TotalEarnedWagesNeededInd"].Value = node.param17;
cmd4.Parameters["TotalEarnedWages"].Value = node.param18;
cmd4.Parameters["TotalWeeksWorkedNeededInd"].Value = node.param19;
cmd4.Parameters["TotalWeeksWorked"].Value = node.param20;
cmd4.Parameters["WagesEarnedAfterClaimEffectiveDate"].Value = node.param21;
cmd4.Parameters["NumberOfHoursWorkedAfterClaimEffectiveDate"].Value = node.param22;
cmd4.Parameters["AverageWeeklyWage"].Value = node.param23;
cmd4.Parameters["EmployerSepReasonCode"].Value = node.param24;
cmd4.Parameters["ReturnToWorkInd"].Value = node.param25;
cmd4.Parameters["ReturnToWorkDate"].Value = node.param26;
cmd4.Parameters["WorkingAllAvailableHoursInd"].Value = node.param27;
cmd4.Parameters["NotWorkingAvailableHoursReason"].Value = node.param28;
cmd4.Parameters["DischargeReasonCode"].Value = node.param29;
cmd4.Parameters["FinalIncidentReason"].Value = node.param30;
cmd4.Parameters["FinalIncidentDate"].Value = node.param31;
cmd4.Parameters["ViolateCompanyPolicyInd"].Value = node.param32;
cmd4.Parameters["DischargePolicyAwareInd"].Value = node.param33;
cmd4.Parameters["DischargePolicyAwareExplanationCode"].Value = node.param34;
cmd4.Parameters["WhoDischargedName"].Value = node.param35;
cmd4.Parameters["WhoDischargedTitle"].Value = node.param36;
cmd4.Parameters["DischargeReasonComments"].Value = node.param37;
cmd4.Parameters["VoluntarySepReasonCode"].Value = node.param38;
cmd4.Parameters["HiringAgreementChangesCode"].Value = node.param39;
cmd4.Parameters["HiringAgreementChangeComments"].Value = node.param40;
cmd4.Parameters["ClaimantActionstoAvoidQuitInd"].Value = node.param41;
cmd4.Parameters["ActionTakenComments"].Value = node.param42;
cmd4.Parameters["ContinuingWorkAvailableInd"].Value = node.param43;
cmd4.Parameters["VoluntarySepReasonComments"].Value = node.param44;
cmd4.Parameters["AmendedResponse"].Value = node.param45;
cmd4.Parameters["AmendedResponseDescription"].Value = node.param46;
cmd4.Parameters["EmployerSepReasonComments"].Value = node.param47;
cmd4.Parameters["LaborDisputeTypeInd"].Value = node.param48;
cmd4.Parameters["AttachmentID"].Value = node.param49;
cmd4.Parameters["MandatoryRetirementInd"].Value = node.param50;
cmd4.Parameters["PriorIncidentID"].Value = node.param51;
cmd4.Parameters["PreparerTypeCode"].Value = node.param52;
cmd4.Parameters["PreparerCompanyName"].Value = node.param53;
cmd4.Parameters["PreparerTelephoneNumberPlusExt"].Value = node.param54;
cmd4.Parameters["PreparerContactName"].Value = node.param55;
cmd4.Parameters["PreparerTitle"].Value = node.param56;
cmd4.Parameters["PreparerFaxNbr"].Value = node.param57;
cmd4.Parameters["PreparerEmailAddress"].Value = node.param58;
cmd4.ExecuteNonQuery();
if (cmd4 != null)
{
cmd4 = null;
}
}
You need to include the namespace (xmlns) in all of the element names:
XNamespace ns = "https://uidataexchange.org/schemas";
doc.Descendants(ns + "EmployerTPASeparationResponse")
(And in all of the Element calls)
Note that your code can be made dramatically shorter by looping through the child elements and adding parameters with their names instead of using anonymous types.
For example:
var node = doc.Descendants(ns + "EmployerTPASeparationResponse").Single();
using (cmd4) {
foreach(var param in node.Elements()) {
cmd4.Parameters.AddWithValue(param.Name.LocalName, param.Value);
}
cmd4.ExecuteNonQuery();
}

Categories

Resources