ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Check character exists in Word Document using C# and VB.Net in Windows Application<p>Hey <a class="username" rel="PRA">PRA</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using Microsoft.Office.Interop.Word;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports Microsoft.Office.Interop.Word</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">public Form1() { &nbsp;&nbsp;&nbsp; InitializeComponent(); &nbsp;&nbsp;&nbsp; Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application(); &nbsp;&nbsp;&nbsp; Document doc = new Document(); &nbsp;&nbsp;&nbsp; string filePath = "Test.docx"; &nbsp;&nbsp;&nbsp; object missing = System.Type.Missing; &nbsp;&nbsp;&nbsp; object fileName = filePath; &nbsp;&nbsp;&nbsp; doc = word.Documents.Open(ref fileName, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ref missing, ref missing, ref missing, ref missing, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ref missing, ref missing, ref missing, ref missing, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ref missing, ref missing, ref missing, ref missing, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ref missing, ref missing, ref missing); &nbsp;&nbsp;&nbsp; List&lt;string&gt; data = new List&lt;string&gt;(); &nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; doc.Paragraphs.Count; i++) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string temp = doc.Paragraphs[i + 1].Range.Text.Trim(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (temp.Contains(".") || temp.Contains(":") || temp.Contains("?")) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data.Add(temp); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; ((_Application)word).Quit(); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Public Sub New() &nbsp;&nbsp;&nbsp; InitializeComponent() &nbsp;&nbsp;&nbsp; Dim word As Application = New Application() &nbsp;&nbsp;&nbsp; Dim doc As Document = New Document() &nbsp;&nbsp;&nbsp; Dim filePath As String = "Test.docx" &nbsp;&nbsp;&nbsp; Dim missing As Object = System.Type.Missing &nbsp;&nbsp;&nbsp; Dim fileName As Object = filePath &nbsp;&nbsp;&nbsp; doc = word.Documents.Open(fileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing) &nbsp;&nbsp;&nbsp; Dim data As List(Of String) = New List(Of String)() &nbsp;&nbsp;&nbsp; For i As Integer = 0 To doc.Paragraphs.Count - 1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim temp As String = doc.Paragraphs(i + 1).Range.Text.Trim() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If temp.Contains(".") OrElse temp.Contains(":") OrElse temp.Contains("?") Then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data.Add(temp) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If &nbsp;&nbsp;&nbsp; Next &nbsp;&nbsp;&nbsp; CType(word, _Application).Quit() End Sub</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/123572/Check-character-exists-in-Word-Document-using-C-and-VBNet-in-Windows-Application/https://www.aspforums.net:443/Threads/123572/Check-character-exists-in-Word-Document-using-C-and-VBNet-in-Windows-Application/Tue, 01 Jan 2019 23:40:32 GMT