Missing commas - InfoPath Dev
in

InfoPath Dev

Missing commas

Last post 04-20-2010 06:55 PM by Lawson. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 03-02-2010 01:55 PM

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

    Missing commas

    I have an InfoPath form with three textboxes, one attachment, and one button. When an attachment is added and the button is pressed, a csv file is created with the contents of the textboxes and saved to a specified folder. My problem is with the csv file. I need a file that separates the contents of the text boxes by commas, but I get a csv file with no commas. I am using the following code.

    IXMLDOMNode fileNameNode= thisXDocument.DOM.selectSingleNode("/my:myFields/my:field6"); 

    String fileName = fileNameNode.text; if (fileName.Length > 0)

    {

    IXMLDOMNode A =thisXDocument.DOM.selectSingleNode("/my:myFields/my:field1");String A1 = A.text;

     

    IXMLDOMNode B =thisXDocument.DOM.selectSingleNode("/my:myFields/my:field4");String B1 = B.text;

     

    IXMLDOMNode C =thisXDocument.DOM.selectSingleNode("/my:myFields/my:field5");String C1 = C.text;

    string[] lines = { A1, B1, C1,};System.IO.File.WriteAllLines(@"C:\Users\Lawson\Documents\output.csv", lines);

    }

     

    I have also added an example of the form to this post.

    Does anybody have any suggestions for how to fix this?

     

    Thanks

    -Lawson

     

     

     

  • 03-02-2010 03:22 PM In reply to

    Hi:

    Here is a link to MSDN documentation on joining strings in a string array with specified separator (String.Join method). Then, instead of using WriteAllLines, you could use the File.WriteAllText method?

    So maybe something like:

    string [] lines = { A1, B1, C1};
    string allLines = String.Join(",", lines, 0, 3);
    System.IO.File.WriteAllText(@"C:\Users\Lawson\Documents\output.csv", allLines);

    So you know, I haven't tried to compile or run that, just typed it in, so it could have an error or two, but just wanted to give you the gist...

    Hilary Stoupa

  • 03-02-2010 03:35 PM In reply to

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

    Hilary,

    Your code was exactly right. I replaced it, and it worked great.

    Thanks, 

    You're Awesome!

    My bulldog says the same.

    -Lawson

  • 04-19-2010 01:54 PM In reply to

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

    Hi Hilary,

    I am trying to add to the output in this post.

    I have another variable that needs to be added to the next line of the csv file.

     Do you know how to do this?

    -Thanks

  • 04-20-2010 06:15 PM In reply to

    Hey, Lawson:

    Does this new variable need to be on a new line in the csv file? Or simply added to what you are already writing?

    Hilary Stoupa

  • 04-20-2010 06:55 PM In reply to

    • Lawson
    • Top 100 Contributor
    • Joined on 12-24-2009
    • Virginia
    • Posts 91

     

     I figured it out with the following code:

    DOMNodeList A1aaa = thisXDocument.DOM.selectNodes("/dfs:myFields/my:AcquisitionPlan/my:A1");

    foreach (IXMLDOMNode node in A1aaa)

    if (node.text.Length > 0)

    {

    string attachedFile = node.text;

     

    Encoding _encoding = Encoding.Unicode;using (MemoryStream _memoryStream = new MemoryStream(Convert.FromBase64String(attachedFile)))

    {

    BinaryReader _theReader = new BinaryReader(_memoryStream);

    byte[] _headerData = _theReader.ReadBytes(16);

    int _fileSize = (int)_theReader.ReadUInt32(); int _attachmentNameLength = (int)_theReader.ReadUInt32() * 2;

    byte[] _fileNameBytes = _theReader.ReadBytes(_attachmentNameLength);string fileNameA1a = _encoding.GetString(_fileNameBytes, 0, _attachmentNameLength - 2);

     

    string appendText = fileNameA1a + Environment.NewLine;

     

    File.AppendAllText(@newPathA1Output, appendText);

    }

    }

     

    I am having a lot of trouble with this http://www.infopathdev.com/forums/t/15219.aspx right now.

     Do you have any suggestions?

    thanks

    -Lawson

Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.