示例#1
0
        /// <summary>
        /// Reads all text out of a .docx file.
        /// </summary>
        /// <param name="file">The file to read all text out of.</param>
        /// <returns>A string that contains all the text from the specified file</returns>
        public static string ReadFile(string file)
        {
            if (string.IsNullOrEmpty(file)) throw new ArgumentNullException("file", "file cannot be null or empty");
            FileInfo info = new FileInfo(file);
            if (!info.Exists) throw new FileNotFoundException("file must exist");
            if (!info.Extension.Equals(".docx", StringComparison.OrdinalIgnoreCase)) throw new ArgumentException("File must have a .doc extension");

            DocxToText extractor = new DocxToText(file);
            return extractor.ExtractText();
        }
示例#2
0
        /// <summary>
        /// Reads all text out of a .docx file.
        /// </summary>
        /// <param name="file">The file to read all text out of.</param>
        /// <returns>A string that contains all the text from the specified file</returns>
        public static string ReadFile(string file)
        {
            if (string.IsNullOrEmpty(file))
            {
                throw new ArgumentNullException("file", "file cannot be null or empty");
            }
            FileInfo info = new FileInfo(file);

            if (!info.Exists)
            {
                throw new FileNotFoundException("file must exist");
            }
            if (!info.Extension.Equals(".docx", StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException("File must have a .doc extension");
            }

            DocxToText extractor = new DocxToText(file);

            return(extractor.ExtractText());
        }