Link to home
Start Free TrialLog in
Avatar of tjpal
tjpalFlag for United States of America

asked on

CSV QUestion in VB.net

I could really use some help with this code here.  I have code that I was thought to only export 1 line with header than later found out that I need a number of them.  

The text coming in is less than cleaned up and I was able to do 1 line and strip all the characters out.

I am having a problem just getting it to loop through x amount of lines.


            ''Dim filePathcopy As String = Server.MapPath("hcfilesbk/Post" & "-" & DateTime.Now.ToString("MM-dd-yy-HH-mm") & ".csv")

            ''Dim delimiterCopy As String = ","
            ''Dim TheJobDescriptioncopy As String
            ''TheJobDescriptioncopy = (Replace(JobDescription.Text, "•", "<li>"))
            ''TheJobDescriptioncopy = (Replace(JobDescription.Text, "•", "<li>"))
            ''TheJobDescriptioncopy = (Replace(JobDescription.Text, "’", "&quot;"))
            ''TheJobDescriptioncopy = (Replace(JobDescription.Text, vbCrLf, ""))

            ''Dim TheBenefitsRequirementscopy As String
            ''TheBenefitsRequirementscopy = (Replace(BenefitsRequirements.Text, "•", "<li>"))
            ''TheBenefitsRequirementscopy = (Replace(BenefitsRequirements.Text, "•", "<li>"))
            ''TheBenefitsRequirementscopy = (Replace(BenefitsRequirements.Text, "’", "&quot;"))
            ''TheBenefitsRequirementscopy = (Replace(BenefitsRequirements.Text, vbCrLf, ""))

            ''Dim TheCompanyOverviewcopy As String
            ''TheCompanyOverviewcopy = (Replace(CompanyOverview.Text, "•", "<li>"))
            ''TheCompanyOverviewcopy = (Replace(CompanyOverview.Text, "•", "<li>"))
            ''TheCompanyOverviewcopy = (Replace(CompanyOverview.Text, "’", "&quot;"))
            ''TheCompanyOverviewcopy = (Replace(CompanyOverview.Text, vbCrLf, ""))


            ''Dim outputcopy As String()() = New String()() _
            ''{New String() {"SR_ID", "SR_Name", "SR_Name_Show", "SR_Address", "SR_City", "SR_State", "SR_zip", "SR_Phone", "SR_Phone_Show", "SR_Fax", "SR_Fax_Show", "SR_Email", "SR_JobID", "SR_OpeningsID", "SR_JobTitle", "JobTypeCode", "SR_MCA_Other_Text", "SR_SalaryRangeBase", "SR_SalaryRangeHigh", "SR_LocName", "SR_City1", "SR_State1", "SR_Zip1", "SR_PosReqs", "PositionSummary", "SR_Date", "SR_Discipline_ID", "SR_Job_Status"}, _
            '' New String() {(Request.QueryString("ID")), (Replace(FullName.Text, ",", "&#44;")), _
            '' (SR_Name_Show.Text), (Replace(SR_Address.Text, ",", "&#44;")), (Replace(SR_City.Text, ",", "&#44;")), _
            '' (selStateCode.Text), (SR_Zip.Text), (Replace(SR_Phone.Text, ",", "&#44;")), (SR_Phone_Show.Text), _
            '' (Replace(SR_Fax.Text, ",", "&#44;")), (SR_Fax_Show.Text), (Replace(email.Text, ",", "&#44;")), _
            '' (SR_JobID.Text), (Replace(PrimaryIndustry.Text, ",", "&#44;")), (Replace(JobTitle.Text, ",", "&#44;")), _
            '' (JobTypeCode.Text), (Replace(TheCompanyOverview, ",", "&#44;")), (Replace(BasePayL.Text, ",", "&#44;")), _
            '' (Replace(BasePayH.Text, ",", "&#44;")), (Country.Text), (Replace(City.Text, ",", "&#44;")), (State.Text), _
            '' (Replace(USZip5.Text, ",", "&#44;")), (Replace(TheBenefitsRequirements, ",", "&#44;")), _
            '' (Replace(TheJobDescription, ",", "&#44;")), (Replace(SR_Date.Text, ",", "&#44;")), _
            '' (SR_Job_Status.Text)}}

            ''Dim lengthc As Integer = outputcopy.GetLength(0)
            ''Dim sbc As New StringBuilder()

            ''For index As Integer = 0 To length - 1
            ''    sbc.AppendLine(String.Join(delimiterCopy, outputcopy(index)))
            ''Next

            ''File.WriteAllText(filePathcopy, sbc.ToString())


            'objCmd = New System.Data.OleDb.OleDbCommand()
            'With objCmd
            '    .Connection = objConn
            '    .CommandType = CommandType.Text
            '    .CommandText = strSQL
            'End With

            'objCmd.ExecuteNonQuery()

            'Next
Avatar of tjpal
tjpal
Flag of United States of America image

ASKER

a claner description is :
I'm just trying to get it to loop all records and not loop the header I resear I have researched many ways of exporting, but this was the only way I could find to get the result I needed.
 


output = New String()() _
            '{New String() {"SR_ID", "SR_Name", "SR_Name_Show", "SR_Address", "SR_City", "SR_State", "SR_zip", "SR_Phone", "SR_Phone_Show", "SR_Fax", "SR_Fax_Show", "SR_Email", "SR_JobID", "SR_OpeningsID", "SR_JobTitle", "JobTypeCode", "SR_MCA_Other_Text", "SR_SalaryRangeBase", "SR_SalaryRangeHigh", "SR_LocName", "SR_City1", "SR_State1", "SR_Zip1", "SR_PosReqs", "PositionSummary", "SR_Date", "SR_Job_Status"}, _
            ' New String() {(Request.QueryString("ID")), (Replace(FullName.Text, ",", "&#44;")), _
            ' (SR_Name_Show.Text), (Replace(SR_Address.Text, ",", "&#44;")), (Replace(SR_City.Text, ",", "&#44;")), _
            ' (selStateCode.Text), (SR_Zip.Text), (Replace(SR_Phone.Text, ",", "&#44;")), (SR_Phone_Show.Text), _
            ' (Replace(SR_Fax.Text, ",", "&#44;")), (SR_Fax_Show.Text), (Replace(email.Text, ",", "&#44;")), _
            ' (SR_JobID.Text), (Replace(PrimaryIndustry.Text, ",", "&#44;")), (Replace(JobTitle.Text, ",", "&#44;")), _
            ' (JobTypeCode.Text), (Replace(TheCompanyOverview, ",", "&#44;")), (Replace(BasePayL.Text, ",", "&#44;")), _
            ' (Replace(BasePayH.Text, ",", "&#44;")), (Country.Text), (Replace(City.Text, ",", "&#44;")), (State.Text), _
            ' (Replace(USZip5.Text, ",", "&#44;")), (Replace(TheBenefitsRequirements, ",", "&#44;")), _
            ' (Replace(TheJobDescription, ",", "&#44;")), (Replace(SR_Date.Text, ",", "&#44;")), _
            ' (SR_Job_Status.Text)}}
            ''(Replace(longtext, ",", "&#44;", "'", "&#39;"))
            'Dim length As Integer = output.GetLength(0)
            'Dim sb As New StringBuilder()

            'For index As Integer = 0 To length - 1
            '    sb.AppendLine(String.Join(delimiter, output(index)))
            'Next




            'File.WriteAllText(thefilePath, sb.ToString())
ASKER CERTIFIED SOLUTION
Avatar of Paul_Harris_Fusion
Paul_Harris_Fusion
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tjpal

ASKER

I was hoping to use what I had and though I was just missing a loop around it.  I'm only gfetting 1 row and the header.  I'd like to keep the header and loop my rows,   but this is very helpful
Avatar of Amandeep Singh Bhullar
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.