Function to Command line executable getting errors.. PLeasse help ASAP.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anju458
    New Member
    • Nov 2008
    • 5

    #1

    Function to Command line executable getting errors.. PLeasse help ASAP.

    Hi,

    I had a function to compare two XML files within a project . Now I need to change that into a commandline exe in such a way that it whouls accept two params from the Command line. I have changed it .. but I am getting some errorr

    ValidatorUpg.Va lidatorUpg.Comp areXMLFiles(str ing, string, System.Xml.XmlD ocument, System.Xml.XmlD ocument)' cannot be accessed with an instance reference; qualify it with a type name instead

    Error 10 Cannot create an instance of the static ValidatorUpg.cs
    Error 9 Cannot declare variable of static type ValidatorUpg.cs


    Code:
    namespace ValidatorUpg
    {
        static class ValidatorUpg
    
        {        
            static void Main(string[] args)
            {
                if (args.Length == 0)
                {
    
                    return;               
                }
                else
                {
                    ValidatorUpg upgrade = new ValidatorUpg();
                     Console.WriteLine("Hai");
                       string oFileName = args[0];
                    string fFileName = args[1];
                    //XmlDocument Source;
                    //   XmlDocument Target;
                    XmlDocument Source = new XmlDocument();
                    XmlDocument Target = new XmlDocument();
                    Source.Load(oFileName);
                    Target.Load(fFileName);
                    string rootSource = Source.FirstChild.Name.ToString();
                    upgrade.CompareXMLFiles(args[0],args[1],Source,Target);
    
                }
            }
    
                public static void CompareXMLFiles(string oFileName,string fFileName,XmlDocument Source,XmlDocument Target)
                {
                    foreach (XmlNode ChNode1 in Source.FirstChild.ChildNodes)
                    {
                        //use below if codition if u need to check the sub nodes 
                        if (ChNode1.HasChildNodes == true)
                        {
                            foreach (XmlNode ChNode in ChNode1.ChildNodes)
                            {
                                //CreatePath(ChNode);
                                CompareLower(ChNode, oFileName, fFileName, Target);
                            }
                        }
                        CompareLower(ChNode1, oFileName, fFileName, Target);
                    }
                }
            
            public static void CompareLower(XmlNode NodeName, string oFileName, string fFileName, XmlDocument Target)
            {
                Boolean flag = false;  // node is there 
                string Path = CreatePath(NodeName);
                XmlNodeList selectnodeslist = Target.SelectNodes(Path);
                if (selectnodeslist.Count == 0)
                {
                    insertNode(NodeName, fFileName, Target);
                }
                else
                {
                    foreach (XmlNode selectnode in selectnodeslist)
                    {
    
    ----------------
    -------------
                                                                if (flag == false)
                    {
                        insertNode(NodeName, fFileName, Target);
    
    
    -------------------
    ---------------------
                    }
                }
            }
            public static void insertNode(XmlNode Node, string fFile,XmlDocument Target)
            {
    -------------            
            }
            public static string CreatePath(XmlNode Node)
            {
    -----------
             }
        }
    }
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Well these two are easy.
    Error 10 Cannot create an instance of the static ValidatorUpg.cs
    Error 9 Cannot declare variable of static type ValidatorUpg.cs
    You have static classes and you are trying to instanciate them. Static classes to not get instanciated, which means no constructor references (that would be the myclass a = new myclass() stuff)

    The same thing applies to the first error, you are trying to use a static class with an instance when you need to use it as a type

    Comment

    • anju458
      New Member
      • Nov 2008
      • 5

      #3
      I am still getting an error ... in the command line ....


      I am giving the cmd line as

      ValidatorUpg.ex e "Validator_EN_O LD.xml","Valida tor_EN.xml"

      I am getting an IndexoutofRange exception .

      Please help ASAP.





      class ValidatorUpg

      {
      static void Main(String[] args)
      {

      Console.WriteLi ne("{0}:{1}", args[0], args[1]);
      Console.ReadLin e();
      XmlDocument Source = new XmlDocument();
      XmlDocument Target = new XmlDocument();
      ConfigManager cm = new ConfigManager() ;
      string fPath = (cm.DataFileLoc s.BinDirectory. EndsWith("\\")) ? cm.DataFileLocs .BinDirectory : cm.DataFileLocs .BinDirectory + "\\";
      string fFileName = Path.Combine(cm .DataFileLocs.B inDirectory, args[1].ToString());
      if (File.Exists(fF ileName))
      {
      string nFileName = (cm.DataFileLoc s.EditDirectory .EndsWith("\\") ) ? cm.DataFileLocs .EditDirectory : cm.DataFileLocs .EditDirectory + "\\";
      string oFileName = Path.Combine(cm .DataFileLocs.E ditDirectory, args[0].ToString());
      // File.Move(fFile Name, oFileName);
      MessageBox.Show (args[0].ToString(), args[1].ToString());

      Source.Load(oFi leName);
      // This is the point where the new file can be installed on to the Bin Folder
      Target.Load(fFi leName);
      ValidatorUpg Upgrade = new ValidatorUpg();
      ValidatorUpg.Co mpareXMLFiles(o FileName, fFileName, Source, Target);
      }
      else
      {
      //CONTINUE WITH INSTALLATI N
      }
      }


      public static void CompareXMLFiles (string oFileName,strin g fFileName,XmlDo cument Source,XmlDocum ent Target)
      {
      foreach (XmlNode ChNode1 in Source.FirstChi ld.ChildNodes)
      {
      //use below if codition if u need to check the sub nodes
      if (ChNode1.HasChi ldNodes == true)
      {
      foreach (XmlNode ChNode in ChNode1.ChildNo des)
      {
      //CreatePath(ChNo de);
      CompareLower(Ch Node, oFileName, fFileName, Target);
      }
      }
      CompareLower(Ch Node1, oFileName, fFileName, Target);
      }
      }

      public static void CompareLower(Xm lNode NodeName, string oFileName, string fFileName, XmlDocument Target)
      {

      }

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Well where is the error occuring?
        Have you debugged your application?

        Comment

        • balabaster
          Recognized Expert Contributor
          • Mar 2007
          • 798

          #5
          remove the "," from your param list...

          Comment

          • anju458
            New Member
            • Nov 2008
            • 5

            #6
            I am getting an error right at the first line
            Console.WriteLI ne

            Comment

            • balabaster
              Recognized Expert Contributor
              • Mar 2007
              • 798

              #7
              And that's caused because of the "," in your command line... as I stated previously. Remove the "," from your command line so that it reads

              ValidatorUpg.ex e "Validator_EN_O LD.xml" "Validator_EN.x ml"

              Your application is reading the command line args all in as one string... so it's failing because Args[1] doesn't exist.

              Args[0] = "Validator_EN_O LD.xml,Validato r_EN.xml"

              Args has a length of 1...

              and that's what's causing your problem...

              Comment

              • jairam singh
                New Member
                • Nov 2008
                • 1

                #8

                I have a problem In ASP code. While I am using a variable as a table name in ASP with MS Access Database. I did try, but I didn’t get success.

                Dim cust_name
                cust_name=(any table name)

                1. sql2="Insert Into '"&cust_name&"' (credit_balance ,credit_date)VA LUES('"&amount& "','"&date1&"') "
                2. sql2="Insert Into '"+cust_name+"' (credit_balance ,credit_date)VA LUES('"&amount& "','"&date1&"') "


                ( Where cust_name is a variable. It is being used as a Table name. But these quiries are not working. Please any body give me help…… or correct Ans……..
                Error: Error Type:
                Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
                [Microsoft][ODBC Microsoft Access Driver] Syntax error in query. Incomplete query clause.
                /anoop_tyre/cash_insert.asp , line 19

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by jairam singh

                  I have a problem In ASP code. While I am using a variable as a table name in ASP with MS Access Database. I did try, but I didn’t get success.

                  Dim cust_name
                  cust_name=(any table name)

                  1. sql2="Insert Into '"&cust_name&"' (credit_balance ,credit_date)VA LUES('"&amount& "','"&date1&"') "
                  2. sql2="Insert Into '"+cust_name+"' (credit_balance ,credit_date)VA LUES('"&amount& "','"&date1&"') "


                  ( Where cust_name is a variable. It is being used as a Table name. But these quiries are not working. Please any body give me help…… or correct Ans……..
                  Error: Error Type:
                  Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
                  [Microsoft][ODBC Microsoft Access Driver] Syntax error in query. Incomplete query clause.
                  /anoop_tyre/cash_insert.asp , line 19
                  Start your own thread. Hijacking someone's thread is considered rude.

                  Comment

                  • anju458
                    New Member
                    • Nov 2008
                    • 5

                    #10
                    HOw to pass commad line args ... Please help asap

                    Hi ,
                    I have an exe to which 2 arguments are to be passeed.. where both the arguments are two file paths to xml files which are to be compared.

                    It works fine when i put the two xml files in teh C:\ and execute but when its changes to any other dir like documents and settinsg etcetce it doesnt work.



                    ValidatorUpg.ex e C:\Validator_EN _OLD.xml C:\Validator_EN .xml ---- Works fine


                    But when i change to the path to anything else like
                    ValidatorUpg.ex e C:\Documents and settings\All users\Validator _EN_OLD.xml C:\Documents and settings\All Users\Validator _EN.xml


                    its is not working .. and to my surprise its not even entering the loop which runs when the args.Length ==2...

                    Any suggestions ???

                    Comment

                    • Curtis Rutland
                      Recognized Expert Specialist
                      • Apr 2008
                      • 3264

                      #11
                      Try putting quotes around your paths...spaces can screw up the command line.

                      Code:
                      ValidatorUpg.exe "C:\Documents and settings\All users\Validator_EN_OLD.xml" "C:\Documents and settings\All Users\Validator_EN.xml"
                      Something like that.

                      Comment

                      • anju458
                        New Member
                        • Nov 2008
                        • 5

                        #12
                        Thanks a lot it works.. but itss really surprising that for the C: it works and for any other it doesnt ....

                        Thanks

                        Comment

                        • Curtis Rutland
                          Recognized Expert Specialist
                          • Apr 2008
                          • 3264

                          #13
                          Notice that in the c:\ you don't have any spaces in the path name.

                          Comment

                          • balabaster
                            Recognized Expert Contributor
                            • Mar 2007
                            • 798

                            #14
                            This is a double post... and has already been answered...

                            http://bytes.com/forum/thread854813.ht ml

                            Comment

                            • Curtis Rutland
                              Recognized Expert Specialist
                              • Apr 2008
                              • 3264

                              #15
                              I've joined the threads.

                              Comment

                              Working...