Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to use GetTempFileName in VB.NET

Posted on 2004-04-15
4
Medium Priority
?
1,595 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 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