Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
using System;
using System.IO;
using System.Xml;

namespace XML

    public static void Main(String[] args)
{

        public class PathReading
{
    string datei = "Just a test.xml";
    string quellPfad = @"C:\Users\LK\source\repos\Internship\XML\XML";
    string zielPfad = @"C:\Users\LK\source\repos\Internship\XML\XML\Just a test.xml";

    string quellDatei = System.IO.Path.Combine(quellPfad, datei);
    string zielDatei = System.IO.Path.Combine(zielPfad, datei);
}

            // To copy a folder's contents to a new location:
            // Create a new target folder, if necessary.
            if (!System.IO.Directory.Exists(zielPfad))
            {
                System.IO.Directory.CreateDirectory(zielPfad);
            }
}

// To copy a file to another location and 
// overwrite the destination file if it already exists.
System.IO.File.Copy(quellDatei, zielDatei, true);
}

            if (System.IO.Directory.Exists(quellPfad))
{


    string[] files = System.IO.Directory.GetFiles(quellPfad);

    // Copy the files and overwrite destination files if they already exist.
    foreach (String s in files)
    {
        // Use static Path methods to extract only the file name from the path.
        datei = System.IO.Path.GetFileName(s);
        zielDatei = System.IO.Path.Combine(zielPfad, datei);
        System.IO.File.Copy(s, zielDatei, true);
    }
}
else
{
    Console.WriteLine("Quellpfad existiert nicht!");
}

// Keep console window open in debug mode
Console.WriteLine("Press any key to exit.");
Console.ReadKey();

public class ReadingFile
{
    public void XML(String strFirst, String strLast)
    {
        // Do something with strFirst and strLast.    
        // ...    
        Console.WriteLine("{0}, {1}", strLast, strFirst);
    }
    public void ProcessXML(String xmlText)
    {
        XmlDocument _doc = new XmlDocument();
        _doc.LoadXml(xmlText);
        // alternately, _doc.Load( _strFilename); to read from a file.    
        XmlNodeList _fnames = _doc.GetElementsByTagName("FirstName");
        XmlNodeList _lnames = _doc.GetElementsByTagName("LastName");

        for (int _i = 0; _i < _fnames.Count; ++_i)
        {
            YourMethod(_fnames[_i].InnerText,
            _lnames[_i].InnerText);
        }
        public static void Main(String[] args)
        {
            XMLApp _app = new XMLApp();
            // Passing XML text as a String, you can also use the    
            // XMLDocument::Load( ) method to read the XML from a file.    
            //    
            _app.ProcessXML(@" <Authors>    
            <Author>    
            <FirstName>John</FirstName>    
            <LastName>Doe</LastName>    
            </Author>    
            <Author>    
            <FirstName>Jane</FirstName>    
            <LastName>Eod</LastName>    
            </Author>    
            </Authors> ");
        }
    }// end XMLApp

    public static class XMLLoad
    {
        Dim books =
        XDocument.Load(My.Application.Info.DirectoryPath &
                       @"C:\Users\LK\source\repos\Internship\XML\XML\Just a test.xml")
      Console.WriteLine(books)
    }
    public static void Main()
    {
        string filePath = "Text.txt";
        string fileContent = string.Empty;
        try
        {
            //checking if file exists in the current directory
            if (File.Exists(@"C:\Users\LK\source\repos\Internship\XML\XML\Just a test.xml"))
            {
                //opening text file and reading the whole content
                using (TextReader tr = File.OpenText(@"C:\Users\LK\source\repos\Internship\XML\XML\Just a test.xml")
                {
                    fileContent = tr.ReadToEnd();
                    Console.WriteLine(fileContent);
                }
            }
            else
            {
                Console.WriteLine(filePath + " file does not exist in the current " +
                "directory.");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        Console.ReadLine();
    }
    public class XmlReader
    {
        static void Main(string[] args)
        {
            // Create an isntance of XmlTextReader and call Read method to read the file  
            XmlTextReader textReader = new XmlTextReader("C:\\books.xml");
            textReader.Read();
            // If the node has value  
            while (textReader.Read())
            {
                // Move to fist element  
                textReader.MoveToElement();
                Console.WriteLine("XmlTextReader Properties Test");
                Console.WriteLine("===================");
                // Read this element's properties and display them on console  
                Console.WriteLine("Name:" + textReader.Name);
                Console.WriteLine("Base URI:" + textReader.BaseURI);
                Console.WriteLine("Local Name:" + textReader.LocalName);
                Console.WriteLine("Attribute Count:" + textReader.AttributeCount.ToString());
                Console.WriteLine("Depth:" + textReader.Depth.ToString());
                Console.WriteLine("Line Number:" + textReader.LineNumber.ToString());
                Console.WriteLine("Node Type:" + textReader.NodeType.ToString());
                Console.WriteLine("Attribute Count:" + textReader.Value.ToString());
            }
        }
    }


What I have tried:

I tried changing the code but that didn't work also if there is anything else wrong with my code don't hastate to fix it
Posted
Updated 13-Oct-21 7:28am
v2
Comments
Chris Copeland 13-Oct-21 6:27am    
You haven't told us what's wrong with the code. What error(s) are you encountering, what part of the code isn't working as intended?

Also your code seems to have two Main() methods which is odd, have you just copied and pasted multiple files into one big block?
Govancekaran 13-Oct-21 6:36am    
i just have the error cs5001
Patrice T 13-Oct-21 7:11am    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Patrice T 13-Oct-21 6:30am    
What is it supposed to do ?
describe how it don't work.

1 solution

If you don't understand a compiler error, google it: Compiler Error CS5001 | Microsoft Docs[^]
It says:
Quote:
Program does not contain a static 'Main' method suitable for an entry point


Why does it throw it on your code?
Simpel: how many static Main methods do you have? If it's more than one it has no idea which one it should be calling.
And the one and only Main method needs to be inside a class as C# has no concept of "global" methods, variables, or properties.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900