?
Solved

How to use GetTempFileName in VB.NET

Posted on 2004-04-15
4
Medium Priority
?
1,613 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 400 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
 

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 1600 total points
ID: 10836007
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month17 days, 11 hours left to enroll

829 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