none
Problem to code RRS feed

  • Question

  • Hi,
    How to correct 
    Error	1	Invalid token '(' in class, struct, or interface member declaration	C:\App3\Program.cs	90	32	Validate_File1
    Error	2	Invalid token ',' in class, struct, or interface member declaration	C:\App3\Program.cs	90	35	Validate_File1
    Error	3	Invalid token ',' in class, struct, or interface member declaration	C:\App3\Program.cs	90	42	Validate_File1



    to code below?


    using System; using System.IO; using System.IO.Compression; using System.Linq;

    ... string s_ext = Path.GetExtension(@File0); f1 = File0.Replace(s_ext, ""); f1 = f1 + s_rand + s_ext; while ((line = sr.ReadLine()) != null && Cont0) { using (StreamWriter sw = new StreamWriter(@f1, true, Encoding.Default)) { sw.WriteLine(line.Trim()); //if (line.Trim() == "") //wrt_empt = true; //sw.WriteLine((Att0.ToString().Trim() == "Directory" ? "Directory - " : "File - ") + Name.ToString().Trim() + " Access time - " + AccessTime.ToString().Trim() + " Write time - " + WriteTime.ToString().Trim()); } } } } System.IO.File.Copy(f1, File0, true); File.Delete(f1); } } }




    Many Thanks & Best Regards, Hua Min


    Monday, December 23, 2019 10:27 AM

Answers

  •                 while ((line = sr.ReadLine()) != null && Cont0)
                    {
                        using (StreamWriter sw = new StreamWriter(@f1, true, Encoding.Default))
                        {
                                sw.WriteLine(line.Trim());
                                //if (line.Trim() == "")
                                //wrt_empt = true;
                                //sw.WriteLine((Att0.ToString().Trim() == "Directory" ? "Directory - " : "File - ") + Name.ToString().Trim() + " Access time - " + AccessTime.ToString().Trim() + " Write time - " + WriteTime.ToString().Trim());
                            }
                        }
                    }
    

    Should that right/closing brace be there?

    - Wayne

    • Marked as answer by Jackson_1990 Tuesday, December 24, 2019 3:59 AM
    Monday, December 23, 2019 2:12 PM

All replies

  • Which line of code are the errors reported?

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, December 23, 2019 10:32 AM
    Moderator
  • Line 90

    Many Thanks & Best Regards, Hua Min

    Monday, December 23, 2019 1:11 PM
  • Line 90

    Many Thanks & Best Regards, Hua Min


    What I would like for you to do is copy and paste the line of code into a reply as I'm not going copy your code and find line 90.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, December 23, 2019 1:34 PM
    Moderator
  • Here is line 90

                System.IO.File.Copy(f1, File0, true);
    


    Many Thanks & Best Regards, Hua Min

    Monday, December 23, 2019 1:39 PM
  •                 while ((line = sr.ReadLine()) != null && Cont0)
                    {
                        using (StreamWriter sw = new StreamWriter(@f1, true, Encoding.Default))
                        {
                                sw.WriteLine(line.Trim());
                                //if (line.Trim() == "")
                                //wrt_empt = true;
                                //sw.WriteLine((Att0.ToString().Trim() == "Directory" ? "Directory - " : "File - ") + Name.ToString().Trim() + " Access time - " + AccessTime.ToString().Trim() + " Write time - " + WriteTime.ToString().Trim());
                            }
                        }
                    }
    

    Should that right/closing brace be there?

    - Wayne

    • Marked as answer by Jackson_1990 Tuesday, December 24, 2019 3:59 AM
    Monday, December 23, 2019 2:12 PM
  • Try this

    using System;
    using System.IO;
    using System.Text;
    
    
    namespace Validate_File1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string File0,
                    File1,
                    File2,
                    File3,
                    Call_Sign,
                    Line0,
                    Line1 = "",
                    Line2 = "",
                    Line3 = "",
                    Line_Hold = "",
                    ftx_Line1 = "",
                    eqd_Line1 = "",
                    cta_Line1 = "",
                    Ver0 = "",
                    line = "",
                    Str0,
                    Str1 = "",
                    Str2 = "";
                int Pos0,
                    Pos1,
                    Pos2,
                    Pos3,
                    Pos4,
                    Pos5,
                    Pos6,
                    Pos7,
                    Pos8,
                    Pos9,
                    Pos10 = 0,
                    Pos11 = 0,
                    Pos12,
                    Pos13,
                    Pos14,
                    Pos15,
                    Pos_Hold0,
                    Pos_Hold1,
                    Sep_Count,
                    Len0,
                    UNT_pos,
                    Tot_line,
                    Total_Line1 = 0,
                    eqd2_line_cnt = 0,
                    TDT_cnt = 0;
                bool UNB_Exist,
                    UNZ_Exist,
                    UNT_Exist,
                    NAD_Exist = false,
                    Voy_Ref0,
                    Voy_Ref1,
                    dtm_Line = false,
                    nad_Line = false,
                    doc_Line = false,
                    eqd2_line = false,
                    eqd3_line = false,
                    cta_Line,
                    cta_OK,
                    codeco = false,
                    Found0,
                    BGM_line = false,
                    TDT_line = false,
                    LOC_line = false;
                bool allowappend = true;
    
    
                File0 = args[0];
                if (File0.Trim() == "")
                {
                    Console.WriteLine("Please have a proper input with one file name!");
                    return;
                }
                //System.IO.File.WriteAllText(File0, Str20);
    
    
                string f0 = "", f1 = "", s0 = "", s1 = "", d0 = "", d1 = "";
                int pos0 = 0, pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0, pos5 = 0, pos6 = 0, pos7 = 0, pos8 = 0, pos9 = 0;
                bool wrt_empt = false;
                string OutFile = "";
                string Name1 = "", Name_H = "";
                string AccessTime1 = "";
                string WriteTime1 = "";
    
    
                bool Cont0 = true;
                bool Cont1 = true;
                wrt_empt = false;
                using (StreamReader sr = new StreamReader(@File0, Encoding.Default))
                {
                    Random random = new Random();
                    string s_rand = random.Next(1000).ToString().Trim();
                    //f1 = File0.Replace("y:/BizIn/error/", "");
                    string s_ext = Path.GetExtension(@File0);
                    f1 = File0.Replace(s_ext, "");
                    f1 = f1 + s_rand + s_ext;
                    while ((line = sr.ReadLine()) != null && Cont0)
                    {
                        using (StreamWriter sw = new StreamWriter(@f1, true, Encoding.Default))
                        {
                            sw.WriteLine(line.Trim());
                        }
                    }
                }
    
    
                File.Copy(f1, File0, true);
                File.Delete(f1);
            }
        }
    }
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, December 23, 2019 2:20 PM
    Moderator
  • Hi Ai Guo,

    Thank you for posting here.

    There is no error in the code, and the cause of the error is mismatched brace.

    Just delete a brace above the codes.

    System.IO.File.Copy(f1, File0, true);
    File.Delete(f1);

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 24, 2019 2:18 AM