CSV QUestion in

Posted on 2011-05-05
Last Modified: 2012-05-11
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)))

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

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


Question by:tjpal

    Author Comment

    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)))

                'File.WriteAllText(thefilePath, sb.ToString())
    LVL 12

    Accepted Solution

    Not sure where to start...this is not how I would approach the problem.   However,  i know it is irritating to get told to do a complete re-write so I will try to help with the code you provide...

    The technique of putting everyting into an array of string arrays is not very will suited to looping.   Looping implies that you would extend the master array dynamically and arrays are not great for this.

    You could declare output as List (of string()) instead which will allow you to add values to the list.

    So, try the following.....

    Create a function BuildHeaderArray to return a string array containing column names
       -- basically split off the first part of the code you show above

    Create a function BuildValueArray to return a string array containing then next set of field values
       -- it is not obvious from your sample code how the looping will work and what the muilti-line data source is -   you will have to research this yourself. show above

    Then use the following pattern

    dim outputs as new List (of string())
    dim header() as string = BuildHeaderArray()

    do while (some condition)
        outputs.add( BuildValueArray()  )

    dim sb as new system.text.stringbuilder
    For index as integer = 0 to outputs.count
                sb.AppendLine(String.Join(delimiter, output(index)))


    Author Comment

    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
    LVL 19

    Expert Comment

    by: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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now