troubleshooting Question

Fixed Width Visual Studio C# Export File

Avatar of rwheeler23
rwheeler23Flag for United States of America asked on
.NET Programming
3 Comments2 Solutions791 ViewsLast Modified:
I am reading a table in SQL and then I am trying to write the values out into a format based on UNSPSC layouts. The layout is a fixed width layout. I thought by using the construct in my code that I could control how wide each column is. Two things appear to be happening. If the field is wider than I am specifying it just keeps writing as opposed to truncating and my strings appear to be right justified. How do I force the string to only be as wide as the format and how do I get them to be left justified?
foreach (DataRow dr_loopvariable in dt.Rows)
                {
                    dr = dr_loopvariable;
                    tw.WriteLine("{0,3}{1,1}{2,5}{3,18}{4,10}{5,1}{6,10}{7,1}{8,4}{9,254}{10,3}{11,15}{12,10}{13,18}{14,30}{15,10}{16,30}{17,20}{18,18}{19,10}{20,1}{21,1}{22,17}{23,17}{24,17}{25,17}{26,17}{27,5}{28,10}{29,30}{30,60}{31,10}{32,1}{33,2}{33,1}{34,1}{35,3}{36,3}{37,3}", ECFILEROWID_INVENTORY, AUDIT_ACTN, SETID, INV_ITEM_ID, ITM_STATUS_EFFDT, ITM_STATUS_CURRENT, ITM_STAT_DT_FUTURE, ITM_STATUS_FUTURE, AVAIL_LEAD_TIME, dr["ITEMDESC"], dr["USCATVLS_4"], INV_ITEM_GROUP, INV_PROD_FAM_CD, dr["USCATVLS_6"], DESCR_CAT, MFG_ID, DESCR_MFG, MFG_ITM_ID, UPC_ID, COMMODITY_CD, LOT_CONTROL, SERIAL_CONTROL, INV_ITEM_HEIGHT, INV_ITEM_LENGTH, INV_ITEM_WIDTH, INV_ITEM_WEIGHT, INV_ITEM_VOLUME, INV_ITEM_SIZE, INV_ITEM_COLOR, DESCR, DESCR60, DESCRSHORT, MATERIAL_RECON_FLG, USG_TRCKNG_METHOD, CONSIGNED_FLAG, DISPOSABLE_FLAG, UNIT_MEASURE_DIM, UNIT_MEASURE_WT, UNIT_MEASURE_VOL);
                    tw.WriteLine("{0,3}{1,1}{2,5}{3,18}{4,10}{5,1}{6,1}{7,10}{8,3}{9,10}{10,10}{11,10}{12,8}{13,6}{14,5}{15,5}{16,5}{17,8}{18,5}{19,10}{20,10}{21,10}{22,10}{23,10}{24,15}{25,14}{26,6}{27,1}{28,14}{29,6}{30,6}{31,1}{32,30}{33,1}{33,3}{34,4}{35,10}{36,10}{37,16}{38,254}{39,30}{40,10}{41,14}{42,6}{43,14}{44,6}{45,17}{46,17}{47,3}{48,3}{49,4}{50,10}{51,1}{52,6}{53,6}{54,6}{55,6}{56,1}", ECFILEROWID_PURCHASE, AUDIT_ACTN, SETID, INV_ITEM_ID, PROFILE_ID, INSPECT_CD, INSPECT_UOM_TYPE, ROUTING_ID, REJECT_DAYS, ACCOUNT, ALTACCT, DEPTID, OPERATING_UNIT, PRODUCT, FUND_CODE, CLASS_FLD, PROGRAM_CODE, BUDGET_REF, AFFILIATE, AFFILIATE_INTRA1, AFFILIATE_INTRA2, CHARTFIELD1, CHARTFIELD2, CHARTFIELD3, PROJECT_ID, UNIT_PRC_TOL, PCT_UNIT_PRC_TOL, RECV_REQ, EXT_PRC_TOL, PCT_EXT_PRC_TOL, QTY_RECV_TOL_PCT, RJCT_OVER_TOL_FLAG, PRIMARY_BUYER, RECV_PARTIAL_FLG, CURRENCY_CD, PCT_UNDER_QTY, PO_AVAIL_DT, PO_UNAVAIL_DT, dr["CURRCOST"], dr["ITEMDESC"], DESCR, DESCRSHORT, UNIT_PRC_TOL_L, PCT_UNIT_PRC_TOL_L, EXT_PRC_TOL_L, PCT_EXT_PRC_TOL_L, PACKING_VOLUME, PACKING_WEIGHT, UNIT_MEASURE_VOL, UNIT_MEASURE_WT, SHIP_LATE_DAYS, SHIP_TYPE_ID, SRC_METHOD, PRICE_IMP, SHIPTO_PR_IMP, VNDR_PR_IMP, TAXABLE_CD);
                    tw.WriteLine("{0,3}{1,1}{2,5}{3,18}{4,20}{5,20}{6,10}{7,10}{8,10}{9,16}{10,3}{11,17}{12,16}{13,1}{14,12}{15,3}{16,16}{17,1}{18,3}{19,16}{20,254}{21,1}", ECFILEROWID_VENDOR, AUDIT_ACTN, SETID, dr["ITEMNMBR"], VNDR_CATALOG_ID, dr["VNDITNUM"], dr["VENDORID"], VNDR_LOC, EFFDT_CATALOG, dr["CURRCOST"], dr["USCATVLS_4"], CONVERSION_RATE, QTY_MIN, QTY_PRECISION, ROUND_TOL, CURRENCY_CD, PRICE_VNDR, DFLT_UOM, LEAD_TIME, LEAD_TIME_IMP, COMMENTS_254, dr["USCATVLS_5"]);
                }
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros