C# obtain data from file name
-
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?
-
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?
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
-
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?
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.
-
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.
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?
-
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?
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.
-
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?
string.Trim()