我不确定我做错了什么。
我查看了此功能的开发人员帮助页面,但它没有任何示例
Rght现在我只想将临时目录打印到msgbox以确保我做得对。然后我会用它来写一个文件
我是VB.net的新手,对C
更熟悉这是我的代码:
Imports System
Imports System.IO
Imports System.Collections
Public Class Form1
Public Shared Function GetTempPath() As String
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
...
...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim tempFolder As String
tempFolder = GetTempPath()
MsgBox(tempFolder)
End Sub
省略号只是意味着那里的代码对于问题
是不必要的答案 0 :(得分:2)
您需要删除Function
GetTempPath
声明。这导致您使用您的函数,而不是System.IO.Path
版本。由于Path.GetTempPath
是Shared Function
,因此您可以通过Path.GetTempPath()
调用它。
您的代码应如下所示:
Imports System
Imports System.IO
Imports System.Collections
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
...
...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim tempFolder As String
tempFolder = Path.GetTempPath()
MsgBox(tempFolder)
End Sub