Solved

How to use GetTempFileName in VB.NET

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

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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

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…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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