Reputation: 396
I'm trying to read word file path but it returns me the wrong path in vb.net and I'm using Path.getfullpath
For Each a In p
If Not pName.Equals("") And I <= p.Count Then
Console.WriteLine(a)
Console.WriteLine(p.Count)
pName = p(I).MainWindowTitle.ToString
File.WriteLine("Word Process Name : {0} is started on time {1}", pName, p(I).StartTime)
fullPath = Path.GetFullPath(pName)
File.WriteLine("Path Of the file is : {0}", fullPath(0))
End If
Next
Upvotes: 1
Views: 594
Reputation: 96
You can also you Microsoft.Office.Interop.Word
Library
Dim wordApp As Microsoft.Office.Interop.Word.Application
wordApp = Marshal.GetActiveObject("Word.Application")
FileTxt = My.Computer.FileSystem.OpenTextFileWriter("E:\txt.txt", True)
For Each f In wordApp.Documents
pName = Path.GetFileName(f.FullName).ToString()
pPath = f.Path.ToString()
FileTxt.WriteLine("Word Process Name : {0} ", pName)
FileTxt.WriteLine("Path of File : {0} " , pPath)
Next
Upvotes: 1
Reputation: 468
when you use a for each loop avoid doing p(I) instead of "a". This will return all word process open
Dim p() As Process = System.Diagnostics.Process.GetProcessesByName("winword")
Dim List As New List(Of String)
Dim cList As New List(Of Int32)
Dim I As Int32 = 0
If p.Count > 0 Then
For Each a In p
Dim fullpath As String = ""
Console.WriteLine(a)
Console.WriteLine(p.Count)
Console.WriteLine("Word Process Name : {0} is started on time {1}", a.MainWindowTitle, a.StartTime.ToString)
fullpath = Path.GetDirectoryName(a.MainModule.FileName)
Console.WriteLine("Path Of the file is : {0}", fullpath)
cList.Add(I)
I += 1
List.Add(a.MainWindowTitle)
Next
Else
'Word not open
End If
you can use something like that to find the file in your system but this might take a while.
For Each foundFile As String In My.Computer.FileSystem.GetFiles(
My.Computer.FileSystem.SpecialDirectories.MyDocuments,
Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, a.MainWindowTitle)
msgbox(foundFile)
Next
Upvotes: 0