Solved

How to use GetTempFileName in VB.NET

Posted on 2004-04-15
4
1,502 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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