Solved

How to use GetTempFileName in VB.NET

Posted on 2004-04-15
4
1,514 Views
Last Modified: 2007-12-19
I got the following code from Microsoft MSDN site. I'm trying to use it inside a VB.NET Web Application project. It's having problems with the "* 512" and "* 576" lines. Also, when I look for System.IO.Path.GetTempFileName namespace I don't see it. Can this code below work in a VB.NET code-behind page?
   
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
        (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

    Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" _
        (ByVal lpszPath As String, ByVal lpPrefixString As _
        String, ByVal wUnique As Long, ByVal _
        lpTempFileName As String) As Long

    Private Function CreateTempFile(ByVal sPrefix As String) As String
        Dim sTmpPath As String * 512
        Dim sTmpName As String * 576
        Dim nRet As Long

        nRet = GetTempPath(512, sTmpPath)
        If (nRet > 0 And nRet < 512) Then nRet = GetTempFileName(sTmpPath, sPrefix, 0, sTmpName)
        If nRet <> 0 Then
            CreateTempFile = Left$(sTmpName, InStr(sTmpName, vbNullChar) - 1)
        End If
        End If
    End Function
0
Comment
Question by:greddin
  • 2
4 Comments
 
LVL 5

Assisted Solution

by:AdrianJMartin
AdrianJMartin earned 100 total points
ID: 10835767
System.IO.Path.GetTempPath()
System.IO.Path.GetTempFileName()

These are static metods of the Path class Not Namespaces, to use Path.GetTempPath() you just have to

 imports System.IO


0
 
LVL 48

Expert Comment

by:Mikal613
ID: 10835771
0
 

Author Comment

by:greddin
ID: 10835916
Are there any actual examples of code that show how to use this as System.IO.Path.GetTempPath() and System.IO.Path.GetTempFileName() ?

Thanks you.
-Greg
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 400 total points
ID: 10836007
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now