Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# obtain data from file name

C# obtain data from file name

Scheduled Pinned Locked Moved C#
csharpdatabasesql-serversysadminhelp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    classy_dog
    wrote on last edited by
    #1

    My goal is to parse out a company name and contact name that is the actual filename of the excel spreadsheet. I will use this information in a sql server 2008 r2 database to obtain other related information for the company and contact person. My problem is the file name is manually keyed in my the user who runs the sql server 2008 r2 reports (ssrs) on the standard edition. Is there away you would suggest that I try to parse out the company and contact name from the file name? There are delimiters between the company and contact names how the delimiters may change. (Note: I am intending on using this method instead of opening up the excel spreadsheet to obtain the information I am looking for. I think that there would be alot of C#.net code that is required to open the excel spreadsheet and get the data I am looking for in certain rows and columns. If obtaining the code from an excel spreadsheet is not so bad, can you show me the code on how to accomplish this goal?) Can you show me in code and/or point me to a reference on how to accomplish my goal?

    P OriginalGriffO 2 Replies Last reply
    0
    • C classy_dog

      My goal is to parse out a company name and contact name that is the actual filename of the excel spreadsheet. I will use this information in a sql server 2008 r2 database to obtain other related information for the company and contact person. My problem is the file name is manually keyed in my the user who runs the sql server 2008 r2 reports (ssrs) on the standard edition. Is there away you would suggest that I try to parse out the company and contact name from the file name? There are delimiters between the company and contact names how the delimiters may change. (Note: I am intending on using this method instead of opening up the excel spreadsheet to obtain the information I am looking for. I think that there would be alot of C#.net code that is required to open the excel spreadsheet and get the data I am looking for in certain rows and columns. If obtaining the code from an excel spreadsheet is not so bad, can you show me the code on how to accomplish this goal?) Can you show me in code and/or point me to a reference on how to accomplish my goal?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You need to provide more detail, such as what the filenames look like, and what the delimiters could be.

      *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      1 Reply Last reply
      0
      • C classy_dog

        My goal is to parse out a company name and contact name that is the actual filename of the excel spreadsheet. I will use this information in a sql server 2008 r2 database to obtain other related information for the company and contact person. My problem is the file name is manually keyed in my the user who runs the sql server 2008 r2 reports (ssrs) on the standard edition. Is there away you would suggest that I try to parse out the company and contact name from the file name? There are delimiters between the company and contact names how the delimiters may change. (Note: I am intending on using this method instead of opening up the excel spreadsheet to obtain the information I am looking for. I think that there would be alot of C#.net code that is required to open the excel spreadsheet and get the data I am looking for in certain rows and columns. If obtaining the code from an excel spreadsheet is not so bad, can you show me the code on how to accomplish this goal?) Can you show me in code and/or point me to a reference on how to accomplish my goal?

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Easiest way will be either to use string.Split on the file name (if the delimiters are sensible) or a Regex: For example, if the file name was "2012-12-31 Oranges (Jaffa Co, John Smith).xlxs" The I would use a regex:

        (\((?.*?),(?.*?)\))

        Would match it and extract the company and contact as separate fields.

        If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        C 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Easiest way will be either to use string.Split on the file name (if the delimiters are sensible) or a Regex: For example, if the file name was "2012-12-31 Oranges (Jaffa Co, John Smith).xlxs" The I would use a regex:

          (\((?.*?),(?.*?)\))

          Would match it and extract the company and contact as separate fields.

          If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

          C Offline
          C Offline
          classy_dog
          wrote on last edited by
          #4

          The file name would look like the following: C:\\app1\12_2012\customer name_contact name.xls. The part of the file name I listed above is the following: customer name_contact name.xls. The customer name can contain all kinds of special characters like (,),'. Thus I need to be able to parse out the customer name with all the special characters. Note: It is my idea to have an underscore between customer name and contact name for the following reasons: 1. I need some kind of a delimiter, 2. I do not think alot of people's name have an 'underscore' as part of the name. 3. The underscore is a valid character for a filename. Note: these names may like like the following if it is entered incorrectly by a user: customer name _ contact name.xls. Thus can you tell me how you would parse out the names in that case?

          OriginalGriffO M 2 Replies Last reply
          0
          • C classy_dog

            The file name would look like the following: C:\\app1\12_2012\customer name_contact name.xls. The part of the file name I listed above is the following: customer name_contact name.xls. The customer name can contain all kinds of special characters like (,),'. Thus I need to be able to parse out the customer name with all the special characters. Note: It is my idea to have an underscore between customer name and contact name for the following reasons: 1. I need some kind of a delimiter, 2. I do not think alot of people's name have an 'underscore' as part of the name. 3. The underscore is a valid character for a filename. Note: these names may like like the following if it is entered incorrectly by a user: customer name _ contact name.xls. Thus can you tell me how you would parse out the names in that case?

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #5

            Try: string inp = Path.GetFilenameWithoutExtension(path); string[] parts = inp.Split('_'); parts[0] is the company, parts[1] is the contact.

            If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            1 Reply Last reply
            0
            • C classy_dog

              The file name would look like the following: C:\\app1\12_2012\customer name_contact name.xls. The part of the file name I listed above is the following: customer name_contact name.xls. The customer name can contain all kinds of special characters like (,),'. Thus I need to be able to parse out the customer name with all the special characters. Note: It is my idea to have an underscore between customer name and contact name for the following reasons: 1. I need some kind of a delimiter, 2. I do not think alot of people's name have an 'underscore' as part of the name. 3. The underscore is a valid character for a filename. Note: these names may like like the following if it is entered incorrectly by a user: customer name _ contact name.xls. Thus can you tell me how you would parse out the names in that case?

              M Offline
              M Offline
              micke andersson
              wrote on last edited by
              #6

              string.Trim()

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups