Directory.exists - VSTO [英] Directory.exists - VSTO
问题描述
代码...
      Dim foldername As String
      foldername =" C:\Files \"
      Dim activeworksheet As Microsoft.Office.Interop.Excel.Worksheet =
      Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets(1)
      Dim工作表As Microsoft.Office.Tools.Excel.Worksheet =
          Globals.Factory.GetVstoObject(activeworksheet)
      Dim path1 As String
      Dim path2 As String()
     如果Directory.Exists(foldername)则path2 = Directory.EnumerateDirectories(foldername)
      For Each path1 In path2
$
         如果File.Exists(path1)则为
              MsgBox(路径1)
         否则
             如果是Directory.Exists(path2)则为
                  MsgBox(path2)
             否则
                  Console.WriteLine("{0}不是有效的文件或目录。",path1)
             结束如果
         结束如果
     下一个路径1
Dim foldername As String
foldername = "C:\Files\"
Dim activeworksheet As Microsoft.Office.Interop.Excel.Worksheet =
Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets(1)
Dim worksheet As Microsoft.Office.Tools.Excel.Worksheet =
Globals.Factory.GetVstoObject(activeworksheet)
Dim path1 As String
Dim path2 As String()
If Directory.Exists(foldername) Then path2 = Directory.EnumerateDirectories(foldername)
For Each path1 In path2
If File.Exists(path1) Then
MsgBox(path1)
Else
If Directory.Exists(path2) Then
MsgBox(path2)
Else
Console.WriteLine("{0} is not a valid file or directory.", path1)
End If
End If
Next path1
end sub
***** ******
***********
当为文件夹添加监视时,目录始终为NULL。即使该文件夹存在。
directory is always NULL when a do a add watch for folder. even though the folder exists.
为什么directory.exists不会执行。
why directory.exists does not execute.
推荐答案
Hello Kumar,
Hello Kumar,
看起来代码根本与VSTO无关。您是否尝试过创建新的Windows窗体示例应用程序并运行上面列出的代码?你得到相同的结果吗?
Looks like the code is not related to VSTO at all. Have you tried to create a new Windows Form sample application and run the code listed above there? Do you get the same results?
请记住,系统(C :)驱动器需要管理员权限才能写入。所以,我建议尝试使用管理员权限运行主机应用程序并比较结果。
Please remember that a system (C:) drive requires admin privileges for writing. So, I'd suggest trying to run the host application with admin privileges and compare the results.
这篇关于Directory.exists - VSTO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!