GetTempFileName + File.Create

OSVBNET 1,386 Reputation points
2022-07-01T11:02:25.487+00:00

Hello,
GetTempFileName states that: This method creates a temporary file.
Since it has not something like FileOptions.DeleteOnClose, may I use this afterward?

Dim MyFile As FileStream = File.Create(blah, 8, FileOptions.DeleteOnClose)

and if so, how to read it? I mean how to ReadAllBytes from resource?

MyFile.Write(File.ReadAllBytes(My.Resources.blah.blah)) :: Value of type '1-dimensional array of Byte' cannot be converted to 'String'

*** for some reason I can't find, this does not work for me:

Dim MyFS As FileStream = New FileStream(Path.GetTempFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.RandomAccess Or FileOptions.DeleteOnClose)
MyFS.Write(My.Resources.blah.blah, 0, 4096)

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,580 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,831 Reputation points
    2022-07-01T12:00:46.157+00:00

    This test works for me :

            Dim sTempPath = Path.GetTempFileName()  
            Dim byteFileResources As Byte() = My.Resources.TestResource  
            My.Computer.FileSystem.WriteAllBytes(sTempPath, byteFileResources, False)  
    

    For example, if My.Resources.TestResource is an exe file, it creates a .tmp with the right exe content (if I rename it to .exe, the executable works)

    0 comments No comments

0 additional answers

Sort by: Most helpful