locked
Need help on get value to when writing to a text value RRS feed

  • Question

  • User-501297529 posted

    I am currently writing the strings in a text file. When I open the text file all I get is numbers. I want to get the actual name of the counties as values when writing to the text file. How do I do that so it will display the names of the counties instead of numbers in the text file. I bolded the lines where I'm writing to the text file.

      if (osabasedCounty != "" && osabasedCounty != null)
                {
                    toCheck = cleanSQL(osabasedCounty);
                }
                else
                {
                    string theArea = (vloc != null ? vloc.AREA : "");
                    if (theArea == "NIPSCO")
                    {
                        //toCheck = splitOSA[0].Replace(" E", "");
                        //toCheck = toCheck.Replace(" C", "");
                        //toCheck = toCheck.Replace(" W", "");
                        //toCheck = toCheck.Replace(" 13", "");
                        //toCheck = toCheck.Replace(" 15", "");
                        //toCheck = toCheck.Replace(" 16", "");
    
                        //replace code above with next line to see if this will work
                        toCheck = splitOSA[0].Substring(0, 5).Trim();
    
                        //bNIPSCO = true;
                    }
                    else
                    {
                        if (splitOSA.Length - 1 > 0)
                        {
                            if (splitOSA[1] != "PI")
                            {
                                toCheck = splitOSA[1];
                            }
                        }
                    }
                }
                string state = (vloc != null ? vloc.STATE : "");
    
                if (state == null)
                {
                    state = "";
                }
    
                if (toCheck != "")
                {
    
                    COUNTY cnty = adc.COUNTies.FirstOrDefault(f => f.name.Contains(toCheck) && f.STATE == state);
                    if (cnty != null)
                    {
                        integCountyO = cnty.OPPCODE;
                        integCountyL = cnty.LABORCODE;
                        integCountyW = cnty.WELDERCODE;
                        integCountyWH = cnty.WELDHELPERCODE;
                        integCountyFC = cnty.FOREMANCODE;
    
                        if (splitOSA.Length - 1 > 1)
                        {
                            int kcPos = 0;
                            int stPos = 0;
                            string kcCheck = "";
                            string kcState = "";
    
                            foreach(string cty in splitOSA)
                            {
                                if(cty.ToUpper().Trim() == "KANSAS CITY")
                                {
                                    kcCheck = cty.ToUpper().Trim();
                                    break;
                                }
    
                                kcPos++;
                            }
    
                            foreach (string cty in splitOSA)
                            {
                                if (cty.ToUpper().Trim() == "MO")
                                {
                                    kcState = cty.ToUpper().Trim();
                                    break;
                                }
    
                                stPos++;
                            }
    
                            //if (splitOSA[2].ToUpper() == "KANSAS CITY")
                            System.Diagnostics.Debug.WriteLine(string.Format("kcCheck P = {0}", kcCheck));
    
                            if (kcCheck != "")
                            {
                                try
                                {
                                    string buildOSA = "";
    
                                    if (splitOSA.Length == 4)
                                    {
                                        if (kcPos == 2)
                                        {
                                            buildOSA = string.Format("{0}-{1}", splitOSA[kcPos], splitOSA[kcPos + 1]);
                                        }
                                        else
                                        {
                                            buildOSA = string.Format("{0}-{1}", splitOSA[kcPos], splitOSA[stPos]);
                                        }
                                    }
                                    else
                                    {
                                        buildOSA = string.Format("{0}-{1}", splitOSA[kcPos], splitOSA[stPos]);
                                    }
                                    
    
                                    WFSLOCP wfs = adc.WFSLOCPs.FirstOrDefault(f => f.WLNAME.Equals(buildOSA));
                                    integCity = wfs == null ? "0" : wfs.WLLOCL;
                                    System.Diagnostics.Debug.WriteLine(string.Format("integCity_Payroll_KC P = {0}", integCity));
                                }
                                catch (Exception exOSA)
                                {
                                    WFSLOCP wfs = adc.WFSLOCPs.FirstOrDefault(f => f.WLNAME.StartsWith(splitOSA[2]));
                                    integCity = wfs == null ? "0" : wfs.WLLOCL;
                                    System.Diagnostics.Debug.WriteLine(string.Format("integCity_Payroll_exOSA P = {0}", integCity));
                                }
                            }
                            else
                            {
                                WFSLOCP wfs = adc.WFSLOCPs.FirstOrDefault(f => f.WLNAME.StartsWith(splitOSA[2]));
                                integCity = wfs == null ? "0" : wfs.WLLOCL;
                                System.Diagnostics.Debug.WriteLine(string.Format("integCity_Payroll_nonKC P = {0}", integCity));
                            }
                        }
                    }
                }
                using (StreamWriter writer = File.CreateText(@"C:\users\marcusd\newfile.txt"))
                {
                    writer.WriteLine(integCountyO + ", " + integCountyL + ", " + integCountyW + ", " + integCountyWH + ", " + integCity + ", " + integCountyFC);
                    }
    
                return integCountyO + "," + integCountyL + "," + integCountyW + "," + integCountyWH + "," + integCity + "," + integCountyFC;
            }

    Friday, September 7, 2018 8:18 PM

Answers

  • User839733648 posted

    Hi  bootzilla,

    According to your codes, I found the value which written into the txt file is selected from the county table.

    If the result is the number, it will also write number into the txt file.

    I suggest you could set a breakpoint to check the value.

    More details about how to use the breakpoint in asp.net, you could refer to below article:

    https://docs.microsoft.com/en-us/visualstudio/debugger/using-breakpoints?view=vs-2017 

    Besides, I suggest you could also check your table to make sure it contains the county name or the right column which you want to insert into the txt file.

    Best Regards,

    Jenifer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 10, 2018 10:12 AM