如何在VB.net中使用GetTempPath

时间:2013-08-08 17:18:10

标签: vb.net api

我不确定我做错了什么。

我查看了此功能的开发人员帮助页面,但它没有任何示例

GetTempPath Help

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

省略号只是意味着那里的代码对于问题

是不必要的

1 个答案:

答案 0 :(得分:2)

您需要删除Function GetTempPath声明。这导致您使用您的函数,而不是System.IO.Path版本。由于Path.GetTempPathShared 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