How To Read A CSV With Embedded Commas In Fields
Oct 18, 2010
I am trying to read a CSV file which has commas embedded within certain fields.
Eg.
"Joe Bloggs", "123 Bloggs Street, Bloggsville, MA, USA", "123.34", "XYZ"
"John Doe", "12 JD Avenue, MA, USA", "53.2", "QRS"
As you can see I have the same amount of fields with a differing amount of comma characters in each. I was using the comma character (',') to split my string into different fields but this gave me varied results.
I have no control over the format of the file so restrucuring it is not an option.
Is there a way where I can split the string by using the comma and maintaining the address field as a single field.
View 2 Replies
Similar Messages:
May 7, 2015
I had gone through Fetching Email using Pop3. I am able to fetch all email using Pop3. Now i want read and download "CID" image. How can I ? Images which are being inserted inside Body.
View 1 Replies
Oct 9, 2012
Is it possible to use TextFieldParser and call .ReadFields and then use field name instead of field position?
For example, I have 40 columns in my .csv file.
field 0 = ID
field 1 = brand
field 2 = model
field 3 = price
field 4 = color
field 5 = something else.....
How the data would appear in the file:
ID,brand,model,price,color,somethingelse
1,Samsung,Galaxy S,200,black,xx
2,Samsung,Galaxy S II,300,black,xy
3,Samsung,Galaxy S III,500,black,xy
4,Samsung,Galaxy S III,500,white,xy
Right now I am calling the array like so CurrentRecord(4) which returns the color field value.
Can I call it like so, CurrentRecord("color") which would return the same value?
Code:
Dim afile As FileIO.TextFieldParser = New FileIO.TextFieldParser(sFullPath)
Dim CurrentRecord As String() ' this array will hold each line of data
afile.TextFieldType = FileIO.FieldType.Delimited
afile.Delimiters = New String() {","}
afile.HasFieldsEnclosedInQuotes = True
' parse the actual file
Dim iRow As Integer = 1
[Code] ....
View 2 Replies
Jan 22, 2010
I've a string builder, and I need to convert it to a string, and then trim any commas if there are any there (I need to get rid of them because I'm building an sql query).
Here's what I'm doing:
myStringBuilder.ToString().TrimEnd(',');
Why isn't this working??? It's not trimming any commas at the end!
I'm using c# :)
View 9 Replies
Jan 21, 2011
i am using the filtered text box extender.I want to allow commas like "," but not possible with the code below.how do i change this to make commas acceptable?
View 3 Replies
Aug 31, 2010
I had been doing a type check for Double for an input field on a web page but now I need to allow commas. Can this be done using a CompareValidator or do I need to use a regex validator?
View 1 Replies
Mar 10, 2011
I wish to implement a fairly simple CSV checker in my C#/ASP.NET application - my project automatically generates CSV's from GridView's for users, but I want to be able to quickly run through each line and see if they have the same amount of commas, and throw an exception if any differences occur. So far I have this, which does work but there are some issues I'll describe soon:
int? CommaCount = null;
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
String Str = null;
//This loops through all the headerrow cells and writes them to the stringbuilder
for (int k = 0; k <= (grd.Columns.Count - 1); k++)
{
sw.Write(grd.HeaderRow.Cells[k].Text + ",");
}
sw.WriteLine(",");
//This loops through all the main rows and writes them to the stringbuilder
for (int i = 0; i <= grd.Rows.Count - 1; i++)
{
StringBuilder RowString = new StringBuilder();
for (int j = 0; j <= grd.Columns.Count - 1; j++)
{
//We'll need to strip meaningless junk such as <br /> and
Str = grd.Rows[i].Cells[j].Text.ToString().Replace("<br />", "");
if (Str == " ")
{
Str = "";
}
Str = """ + Str + """ + ",";
RowString.Append(Str);
sw.Write(Str);
}
sw.WriteLine();
//The below code block ensures that each row contains the same number of commas, which is crucial
int RowCommaCount = CheckChar(RowString.ToString(), ',');
if (CommaCount == null)
{
CommaCount = RowCommaCount;
}
else
{
if (CommaCount!= RowCommaCount)
{
throw new Exception("CSV generated is corrupt - line " + i + " has " + RowCommaCount + " commas when it should have " + CommaCount);
}
}
}
sw.Close();
And my CheckChar method:
protected static int CheckChar(string Input, char CharToCheck)
{
int Counter = 0;
foreach (char StringChar in Input)
{
if (StringChar == CharToCheck)
{
Counter++;
}
}
return Counter;
}
Now my problem is, if a cell in the grid contains a comma, my check char method will still count these as delimiters so will return an error. As you can see in the code, I wrap all the values in " characters to 'escape' them. How simple would it be to ignore commas in values in my method? I assume I'll need to rewrite the method quite a lot.
View 4 Replies
Jan 8, 2010
I'm using a facebox to display a form inside a lightbox, nothing too exciting (just a couple of datepickers, some textboxes and a checkbox). However, I'm having issues with the postbacks, whenever I post back from the facebox it adds a ',' to the start of the input (so "rabbit" becomes ",rabbit") Now, I saw that there was the same issue with the modalpopup extender from the ajaxcontroltoolkit, so I assume it's a common issue.
Can anyone either explain why this is happening, or tell me how to fix it? provide a decent way of fixing this?
See attached answer for a correct solution (I fixed this eventually but didn't want to ruin the bounty question so left the answer until afterwards).
View 3 Replies
Jul 21, 2012
I have a .net aspx project done with VS 2008 using the .Net 2.xxxx framework. This ASPX application is deployed on and 4 different 2003 Server boxes. 3 are running in total beautifully. In the 4th box is my issue. I do a FILE.EXISTS conditional test looking for case file pdf's. These case numbers are structured as such 2012-C-0421,001,0008.PDF
Please note the comma's used in the path. 3 of the 4 servers in court houses recognize the path to the pdf WITH the commas in them perfectly and the FILE.EXISTS works 100%. On the fourth box (same config we THINK) the exact same FILE.EXISTS does not return a hit even though we see the document sitting in the folder via explorer. IF we remove the commas and make it 2012-C-0421001008.pdf all is fine and document is indeed discovered with the EXISTS.
WHY on this one server does the original ducument path not function. We can not ask the court houses to change the way they store their documents so I need to make this work like the other 3. Again... same version..same .net framework... same OS (2003 server)
View 4 Replies
Sep 16, 2010
I want to add controls (or simply texts) to a ListView inside the ItemTemplate at run time.
The reason is that in my application I don't know in advance how many controls (or texts) I should insert.
For example I have to read the fields from a database table and insert in the ItemTemplate controls according to those fields:
<ItemTemplate>
<%# Eval("fieldname1")%> - <%# Eval("fieldname2")%> - <%# Eval("fieldname3")%> - .....
Afterwards I have to bind the ListView to the table content, so I need to preserve the <%# ... %> structure for the binding
View 3 Replies
Jun 8, 2010
I use following code to export data to csv file:
Response.AddHeader("content-disposition", "attachment;filename=UnicodeChar.csv");
Response.ContentType = "application/octet-stream";
StreamWriter sw = new StreamWriter(Response.OutputStream, Encoding.UTF8);[code]...
It works fine. Then I download the csv file to local and open it. At last, I save it. I open the csv file with notepad, I found it misses all commas.
View 15 Replies
Apr 9, 2010
I have a number that is generated from a SQL query that is populated into a tablecell as follows:
[Code]....
I get the correct value in my tablecell, except the value is 15345432. I would like to format this to show 15,345,432How can I go about doing this?
View 3 Replies
Sep 20, 2010
I have a textbox inside modal popup. when i write some data into the textbox and hit ok it is appending unnecessary commas. How to remove them.
View 5 Replies
Sep 27, 2010
Im using Entity framework with POCO entity generator template + SQL Server. I have mapping to stored procedure that takes two floats as input.
After executing function from code with two doubles as parameters: 1.23 and 4.56, SQL Profiler shows:
exec storedProcedureName @arg1 = 1,23, @arg2= 4,56
This is causing an error because it looks like that stored procedure takes 4 arguments, but it should take only two and there should be dots insted of commas in these floats.
[code]....
View 3 Replies
Feb 8, 2011
I have a sql data souce that returns several columns of data, and they are displayed in a DetailsView on a pretty simple vb.net page. I'm stuggling with one field though for the details view.
It's a template field, and if ClientType=1 (this value is determined else where on the page), then the label in the template field should have Text='<%# Bind("ClientName") %>', but if the ClientType = 0, then the label in the template field should have Text='<%# Bind("ClientTemporaryName") %>'
How do I tell the details view to set the text for ClientName to one or the other?
[Code]....
View 3 Replies
Feb 25, 2011
I have a relatively complex dataset (numerous tables, some with multiple records) generated from reading in an XML file. I need to connect said dataset fields to an ASP form. At the moment I'm assigning them manually, like so in the pageload:
txt_first_init.Text = formData.ds.Tables["phrmHdrKey"].Rows[0]["first_init"].ToString();
txt_last_name.Text = formData.ds.Tables["phrmHdrKey"].Rows[0]["last_name"].ToString();
ddl_pregnancy_flag.SelectedValue = formData.ds.Tables["pPhrm"].Rows[0]["pregnancy_flag"].ToString();
And conversely when it's time to submit.
formData.ds.Tables["phrmHdrKey"].Rows[0]["first_init"] = txt_first_init.Text;
formData.ds.Tables["phrmHdrKey"].Rows[0]["last_name"] = txt_last_name.Text;
formData.ds.Tables["pPhrm"].Rows[0]["pregnancy_flag"] = ddl_pregnancy_flag.SelectedValue.ToString();
I did some looking into binding the textboxes (and dropdownlists, and checkboxes, and and and...) directly, but it seemed to be too many formats to use.
So this works fine, but as the number of fields increases, those load and unload lists are going to get unwieldy.
View 1 Replies
Aug 18, 2010
I am using TempleteFields for all columns in my GridView. In that columns I am using only some fields for customization but not all.
Is there any performance issue with Databound Fields vs Templete Fields in a GridView...?
Do I need to replace the remaining columns with Databound Columns instead of TempletField columns...?
View 4 Replies
Jan 3, 2013
I am working on Crystal Reports 8.5 and SQL Server 2000 as backend. I have a stored procedure which has been added to the Crystal Report. So that fields are visible in the Fields object section from where i can drag and drop the fields on the report and display it. But now as they want more fields i have written two select statements for displaying required fields. But these newly added fields are not visible in the Fields object section in the Crystal Reports. I have done verify database, removed and again attached the SP but the problem is not solved.
View 1 Replies
Jan 9, 2011
Q1: I have an Asp.net page , one textarea there the user can enter all his details like name age gender; how do get the get name, age, gender in seperate fields(text fields). how can i split?
Q:
dawn barric 25 male
answer:
text1: dawn barric
text2: 25
text3: male
View 3 Replies
Sep 26, 2010
I have a GridView, and I want Column1 to be equal to datatable data (filled by a SqlDataAdapter). Then I have two other fields by the SqlDataAdapter (first name, last name), and I want to have those two fields combined to form Column2. I have a TemplateField for my GridView that combines the first name and last name with Eval()'s, but the GridView places this combined field TemplateField and puts it as the first column.
How can I do this so that TemplateField can go in between fields that are databound?
View 6 Replies
Jul 21, 2010
Read Receipt And Read Outlook Inbox for the same
View 2 Replies
Jan 4, 2011
From here:http://heanet.dl.sourceforge.net/project/teamlab/TeamLabinstall_EN.pdf
For a mid-size portal it will be sufficient to deploy it in its default configuration:
DB : SQLite3
Web Server : ASC embedded web server.
Suppose you'll need to deploy the portal on a computer named srv003 to the following folder:
c:eamlab.(these are just example names,so when performing the operation please use
View 1 Replies
Jan 4, 2010
It is possible to embed an XBAP application into an IFrame, this is rather easy !!The problem however is that it renders on top of anything within the web application. For example!I have a menu in my web application which can collapse when I hover above it, but it will collapse UNDER the IFrame when it needs to collapse ON TOP of the IFrame with the XBAP Application in it. I tried messing with the z-index but this does not fix anything
View 1 Replies
Feb 23, 2010
I know Silverlight controls can be embedded in an ASP.NET page but is it possible to do the same for a WPF control? The reason I am asking is because we have Infragistics which has a datagrid that can be flipped to have the columns on the left with the rows of data going down vertically. This is only in their WPF package though and I am trying to figure out a way to plug this in to an ASP.NET page.
View 2 Replies
May 13, 2010
Every few days when my webpage is accessed strange characters are embedded in the URL like this:[URL] I did some searches on the internet and found that if the characters begin with the letter 'S', it is the session id used when cookieless is set to true. In my case the beginning letter is 'A', and i couldn't find anything about that. This is bad because once these strange characters appear, all the submenus in my page will disappear (I had another post about his menu problem in here:[URL]
Once I restart the webpage in IIS the URL will become normal again, but it will appear again in a few days.
Does anyone know what these strange characters (that begin with 'A') are? How to avoid them?
[Code]....
View 9 Replies