-1

enter image description here
I am trying to implement FILEHELPER 2.0 in my project , but some csv file with "" quoted facing problem . and it is showing error ( the error log showing this )

**" LineNumber | LineString |ErrorDescription 2|"Symbol","Date","Expiry","Strike Price","Open","High","Low","Close","LTP","Settle Price","No. of contracts","Turnover in Lacs","Open Int","Change in OI","Underlying Value "|Length cannot be less than zero. -> Parameter name:Length cannot be less than zero. -> Parameter name: length 3|" **

and my code goes like this :

   var engine = new FileHelperEngine<script>();
   engine.Options.IgnoreFirstLines = 1; // skipping the header line

   script[] res = engine.ReadFile("agile.csv");  <<<<< at this line error occred 

and my class file :

     [DelimitedRecord(",")]
      public class script
    {
         [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
        public string Symbol;
         [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
        public string Date;
         [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
        public string Expiry;
         [FieldQuoted('"', QuoteMode.AlwaysQuoted)]

       ...
    }

and csv file is .

"Symbol","Date","Expiry","Strike Price","Open","High","Low","Close","LTP","Settle Price","No. of contracts","Turnover in Lacs","Open Int","Change in OI","Underlying Value "

"NIFTY","31-Aug-2012","27-Sep-2012"," 5400.00"," 56.00"," 56.90"," 38.05"," 44.45"," 43.55"," 44.45"," 281087"," 765592.77"," 4845150"," 1334150"," 5258.50"

Vishwa
  • 110
  • 1
  • 9
  • So what line do you get the error and what is the error call stack – Cole Tobin Sep 02 '12 at 18:33
  • @ColeJohnson script[] res = engine.ReadFile("agile.csv"); at this line i am getting error – Vishwa Sep 02 '12 at 18:41
  • @Vishwa you need to look inside `engine.ReadFile` method, it's not clear where excactly exception is thrown from the code you posted. Do you have access to that method? – oleksii Sep 02 '12 at 18:46
  • @oleksii, this error what stored in error file " – Vishwa Sep 02 '12 at 19:00
  • @oleksii plz help, i posted the error in the post – Vishwa Sep 02 '12 at 19:07
  • @Vishwa you did post csv file and the error, but you did not post the internals of the `engine.ReadFile("agile.csv");` method. We need to see the **code** of that method. – oleksii Sep 02 '12 at 19:19
  • @oleksii , engine.ReadFile is method from the Filehelper.dll from the other developer . – Vishwa Sep 02 '12 at 19:48
  • @Vishwa, it is not standard library. You would need to look inside it it. You can use free ILSpy, dotPeek or paid/trial Reflector for this. There is nothing we can help you here... – oleksii Sep 02 '12 at 20:03
  • Can you post the stack trace ? or send the record class and the test file to me ? marcos (in) filehelpers.com Thanks – Marcos Meli Sep 02 '12 at 21:24
  • The problem could be that your `script` class doesn't include the same number of fields as your .csv; please post your complete `script` class. The other less likely problem could be that agile.csv file is not being found. One way to diagnose your error is to reduce your CSV file to one record with only one field and to comment all properties in your `script` class to one property and see if it works. Then, you can add more fields and finally more rows until it breaks and you'll know where. – Brad Rem Sep 02 '12 at 23:45

1 Answers1

1

I can't see any reason for your error: the following code works fine:

[DelimitedRecord(",")]
public class Script
{
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string Symbol;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string Date;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string Expiry;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string StrikePrice;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string Open;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string High;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string Low;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string Close;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string LTP;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string SettlePrice;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string NoOfContracts;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string TurnOverInLacs;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string OpenInt;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string ChangeInOI;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string UnderlyingValue;
}

class Program
{
    static void Main(string[] args)
    {
        string input = @"""Symbol"",""Date"",""Expiry"",""Strike Price"",""Open"",""High"",""Low"",""Close"",""LTP"",""Settle Price"",""No. of contracts"",""Turnover in Lacs"",""Open Int"",""Change in OI"",""Underlying Value """ + Environment.NewLine +
            @"""NIFTY"",""31-Aug-2012"",""27-Sep-2012"","" 5400.00"","" 56.00"","" 56.90"","" 38.05"","" 44.45"","" 43.55"","" 44.45"","" 281087"","" 765592.77"","" 4845150"","" 1334150"","" 5258.50""";

        var engine = new FileHelperEngine<Script>();
        engine.Options.IgnoreFirstLines = 1; // skipping the header line

        Script[] validRecords = engine.ReadString(input);

        // Check the third record
        Assert.AreEqual("NIFTY", validRecords[0].Symbol);
        Assert.AreEqual("31-Aug-2012", validRecords[0].Date);
        Assert.AreEqual("27-Sep-2012", validRecords[1].Date);
        // etc...            

        Console.WriteLine("All assertions passed");
        Console.Read();
    }
}
shamp00
  • 11,106
  • 4
  • 38
  • 81