My.Computer不是......的成员问题Visual Studio

时间:2015-08-30 20:29:10

标签: visual-studio windows-10

我正在运行Microsoft Visual Studio社区添加。在过去的几年里,我使用Windows应用程序表单学到了很多Visual Basic - 我自学了很抱歉,如果这不是他们的“官方”名称。无论如何,转向Windows 10的应用程序开发,我注意到我的代码只需要改变很多工作就会发生很多变化。我在这里错过了一些大事吗?我现在只想为桌面创建Windows应用商店应用程序并使用Visual Studio语言,我希望我的大部分代码能够按原样运行。

以下是我期望的一些代码示例:

Dim infoReader As System.IO.FileInfo
infoReader = My.Computer.FileSystem.GetFileInfo(txtDir.Text)

返回突出显示My.Computer

的错误
  

错误BC30456'计算机'不是'App3'的成员。

对不起,如果这很简单,就像我说的那样,我自学成就无法在网上找到解决方案。我希望很多人在某些时候也会遇到与我相同的问题,所以我认为为什么我觉得这个问题值得一试。

1 个答案:

答案 0 :(得分:2)

应用程序框架(它为您提供My命名空间下的所有内容与Windows应用商店应用程序不兼容,后者仅支持.Net API的子集。最接近的等价物是{{3 }}:

Dim picturesFolder As StorageFolder = KnownFolders.PicturesLibrary ' Although you probably want to get the StorageFolder for the directory specified by txtDir.Text here instead
Dim outputText As New StringBuilder

Dim fileList As IReadOnlyList(Of StorageFile) =
    Await picturesFolder.GetFilesAsync()

outputText.AppendLine("Files:")
For Each file As StorageFile In fileList

    outputText.Append(file.Name & vbLf)

Next file

Dim folderList As IReadOnlyList(Of StorageFolder) =
    Await picturesFolder.GetFoldersAsync()

outputText.AppendLine("Folders:")
For Each folder As StorageFolder In folderList

    outputText.Append(folder.DisplayName & vbLf)

Next folder