Skip to content

Error with some File stream code

Jonathan Piccirilli

Asked Jun 13, 2008, 1:36 PM EDT2 answers
Share
LinkedInX

I am having trouble using the filestream object to save a file. I added the trimstar and end to try and fix it incase there were spaces though it dident help. I get an Illegal character in path filename error. The line Console.WriteLine(str); prints it out how it really should look so I am lost!

Thanks for any help.

Jon

C#
string str = SERCOM.ReadTo("%");
str = str.Substring(3);
str.TrimStart(' ');
Console.WriteLine(str);
string vMin = SERCOM.ReadExisting();

TextWriter tw = new StreamWriter(File.Open((@"\\MPI.COM\Production\EP\CNC\" + str.TrimEnd(' ')), FileMode.Create, FileAccess.ReadWrite,FileShare.ReadWrite));
tw.Write("$" + str + "%");
tw.Write(vMin);
tw.Write("%");

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    SERCOM is an instance of the serial port. The code falls under my On recevied method of my serial port.

    C#
    private static SerialPort SERCOM = new SerialPort(); //serial class
    public static void OnReceived(object sender, SerialDataReceivedEventArgs args)//Handle incoming data received method
    {
    string str = SERCOM.ReadTo("%");

    ...

    ...

    0
  • 1 short reply
    • Bechir Bejaoui
      0
      Tell me what is SERCOM before
      0