Пример #1
0
        static void Main(string[] args)
        {
            System.Console.Write("Please enter the input file name: ");
            string inputFile = System.Console.ReadLine();

            //string inputFile = "aa1.txt";

            System.Console.Write("Please enter the output file name: ");
            string outputFile = System.Console.ReadLine();
            //string outputFile = "out.txt";

            FileStream inputStream = new FileStream(
                inputFile, FileMode.Open);  //non-writable

            FileStream      outputStream = new FileStream(outputFile, FileMode.Create);
            ConvertDocument convert      = new ConvertDocument();
            string          error        = convert.DoConvertDocument(inputStream, outputStream);

            if (error == "")  //success
            {
                System.Console.WriteLine("Conversion successful.");
            }
            else
            {
                System.Console.WriteLine(error);
            }
        }
        //returns the contents of the document or error
        public string Convert(string content)
        {
            //assuming it comes in UTF8
            MemoryStream inputStream = new MemoryStream(
                Encoding.UTF8.GetBytes(content), false);    //non-writable

            bool b = inputStream.CanSeek;

            MemoryStream    outputStream = new MemoryStream();
            ConvertDocument convert      = new ConvertDocument();
            string          error        = convert.DoConvertDocument(inputStream, outputStream);

            if (error == "")  //success
            {
                return(Encoding.UTF8.GetString(outputStream.ToArray()));
            }
            return(error);
        }