C# : File
Top 36 C# Example Pages...

[["(C*CSTUUUUTTUUUUYF6666F(C)CXSTTUUUUTTUUUU","trwes.","Microsoft Word"," can be used with C# code. You have a Microsoft Word document (.doc) and want to read it in your C# program. With the Microsoft.Office.Interop.Word assembly, we get the contents and formatting from the document. ","Tip: ","Add the Microsoft.Office.Interop.Word assembly to your project. Go to Project -> Add Reference.","Example."," First, we show the file we will read. It contains three paragraphs containing one word each. The program first instantiates an Application instance and then we call Documents.Open on that variable. ","Next: ","We loop through the Words collection and read the Text property on each element. We then display and call Quit.","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto","br","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto","Word document: word.doc","\n\nOne\n\nTwo\n\nthree\n\n","C# program that uses Microsoft Word interop","\n\nusing System;\nusing Microsoft.Office.Interop.Word;\n\nclass Program\n{\n static void Main()\n {","\n // Open a doc file.\n ","Application application = new Application();\n Document document = application.Documents.Open(\"C:\\\\word.doc\");","\n\n // Loop through all words in the document.\n ","int count = document.Words.Count;\n for (int i = 1; i <= count; i++)\n {","\n // Write the word.\n ","string text = document.Words[i].Text;\n Console.WriteLine(\"Word {0} = {1}\", i, text);\n }","\n // Close word.\n ","application.Quit();\n }\n}\n\n","Output","\n\nWord 1 = One\nWord 2 =\nWord 3 = Two\nWord 4 =\nWord 5 = three\nWord 6 =","Empty paragraphs."," We see that Word 2, Word 4, and Word 6 are empty. The empty paragraphs in the input file are considered words. If you have multiple words in a paragraph, they will each be separate in the Words collection. ","So: ","In Interop.Word, a paragraph is made up of a collection of one or more words.","Quit."," Why is the application.Quit statement important? If you don't include this, the WINWORD.EXE application will remain in the process list. Then, when this program is run again, a new one will be started. This wastes memory. ","Note: ","It is important to iterate on Words from 1 to Count inclusive. Correction suggested by Robert Ford.","Summary."," We looked at the Microsoft.Office Interop.Word assembly and learned how to read in data from a Word document. This can be useful when you have DOC or DOCX files and want to programmatically read in data from your C# program. ","br","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","3679700504","data-ad-format","link","br","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto"],"url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG4AAACCAgMAAADasxWRAAAADFBMVEXv2f////+VlZX29vYeLcrOAAAASElEQVR4AWPACZj/f0DmjkqOSjKtQgcLyJccZiEE9SOmP8mXHEaBMBoIo4EwGggryJccvvVKKAogTnJUclRyVHLklgmjkqOSAALWyrsxEHLDAAAAAElFTkSuQmCC)","url(data:image/jpeg;base64,/9j/2wBDAAcHBwkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQn/wQARCABSAJgDACIAAREAAhEA/8QAUwAAAQUBAQEAAAAAAAAAAAAAAAECAwUGBAcIEAACAgECAgUKBAUFAAAAAAAAAgEDEQQSBRMGISIxQjIzQVFSYWJxcpIUI7LSc4GCorORocHh4v/aAAwDAAABAAIAAD8A+kAAQUUjstSpZex0rWPEzYj/AHKW3pDpYdaqc2s04z5CeVj09r+wy/SHiv4m3lVN+VXuhZjxz4n/AGFJouu+v61/UXum4Us1cy7dmV3bO77i/wBNwhZq5t27Mru2d33HsQDWnrCCiKDA8BBRBAAAAAABAAUBAADl1utq0lTW2/0rHe8+qDzvW8b1upZtrvXX7CM0R/P2jd8T4emtqhJna6ddbejr8qJIZp0XDtI6stcLsaGllWXunb/cWektorWJ5TXXs23b7MfCWuiuopWJ5TXXs+3b7MfCZfo9xS+NUlL2O9dk7drM07Z8M/cehHnvRrTLbq2tloiKu1C7utpnqXC/CeghxWE5+EjHYXft9YcXhPxGEjE7F37fWKAgFYVQkmT6S62+pEorjalsZZ473+A1cnNqNLVqOXzU38t9y+puz3SdOmtSu1Xdd0L4f0nVpbUrtWx13Qva2+/wnkt2mtqhHtSViy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N64Ot0IGQlhokmhokj3SQ33rUjWPOFWM/9E8qZDj2rmbIoWezX5X1/+Tq01POshfR5TfI69NRzrISO7ym+RBEXcT1OfDH+iJBoq9XpaJr01U7myq4j1y2MyxQ6TitWlohKa99rdbu3dn1bY8KkPDtPffq67YreVixWaYVsLG7JY3U7obf+VTUv5S7sbp9pizup3Q2/8qmpfyl3Y3T7THoCITqg5UJdpnWYzTOMhB+0dgXAzJFLDRwCjRuRAFAQQAAAAAAAAQbMDxBRckMqRsh04E2joYfDHHKGTu6P3anU22NMV1tY/X3y0bvQsG32jdp006p6ZmUnEyu3cdVGrspmZScTK7dxQ6XgOkpxlOa3x932F4lcLEQqwqx3RC4gkhR2CO297Jy7M31ENuossnLszfUIOAUgIMiCgAggAAAAAAAAAAAAAAAAAAAAgCgAo0BwCgIAoAAAACCAAAAAAAAAAAAH/9k=)","url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG4AAACCAgMAAADasxWRAAAADFBMVEX/6Nn///+VlZX29va5ksB5AAAASElEQVR4AWPACZj/f0DmjkqOSjKtQgcLyJccZiEE9SOmP8mXHEaBMBoIo4EwGggryJccvvVKKAogTnJUclRyVHLklgmjkqOSAALWyrsxEHLDAAAAAElFTkSuQmCC)"]

["url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGoAAACZCAMAAADw+V8SAAAADFBMVEX////09PTk5OTU1NQ/cPF/AAABzUlEQVR4Xu3bQarDMBRD0Xel/e/5w59m0FiNRQnWBg6vBidynVkOAJIAYLYEJF9j6VHxqly9Zxzfiig4T2jycpQPVMCQ4yiA4hCs0ebB8BMhWKRtlvxYFIy0w8J2x5JdsmR3LLwl1CSbmmQHy5RGNcmmJlk1yaYm2aGUj4ULUSblY9lvG2t6Fj1LU7M065b+k+/vrBcNpGxzIik0KKGGqDkRVQayiqaAGrJekVBDVCqIXjGI6ktEDTv7xHyyZrZQV0uzjxpWpZwaLtI2aliTcE4NK9LoG2pYkPiy1BFIITXclCboCGGClpUF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