Click here to Skip to main content
16,003,474 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralOne form MDI only admitted Pin
Member 87881514-Feb-04 10:37
Member 87881514-Feb-04 10:37 
Generalhide a from which is not foucsed Pin
aynka200014-Feb-04 7:26
aynka200014-Feb-04 7:26 
GeneralRe: hide a from which is not foucsed Pin
zaheer Asif14-Feb-04 9:58
zaheer Asif14-Feb-04 9:58 
GeneralRe: hide a from which is not foucsed Pin
zaheer Asif14-Feb-04 10:00
zaheer Asif14-Feb-04 10:00 
QuestionHow to create a SPARSE file in VB.NET Pin
WESHILL14-Feb-04 7:23
WESHILL14-Feb-04 7:23 
AnswerRe: How to create a SPARSE file in VB.NET Pin
Dave Kreskowiak14-Feb-04 9:25
mveDave Kreskowiak14-Feb-04 9:25 
GeneralRe: How to create a SPARSE file in VB.NET Pin
WESHILL14-Feb-04 9:41
WESHILL14-Feb-04 9:41 
GeneralRe: How to create a SPARSE file in VB.NET Pin
Dave Kreskowiak16-Feb-04 8:51
mveDave Kreskowiak16-Feb-04 8:51 
Part of the problem is you are passing in strings for your buffers, don't. This is the example your looking for:
Imports System
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
 
Module Module1
    Private Const FILE_ANY_ACCESS = 0
    Private Const FILE_READ_ACCESS = 1
    Private Const FILE_WRITE_ACCESS = 2
    Private Const FILE_DEVICE_FILE_SYSTEM = 9
 
    Private Const GENERIC_READ = &H80000000
    Private Const GENERIC_WRITE = &H40000000
    Private Const FILE_SHARE_READ = 1
    Private Const FILE_SHARE_WRITE = 2
 
    Private Const CREATE_NEW = 1
    Private Const CREATE_ALWAYS = 2
    Private Const OPEN_EXISTING = 3
    Private Const OPEN_ALWAYS = 4
    Private Const TRUNCATE_EXISTING = 5
 
    Public Const FSCTL_SET_REPARSE_POINT = &H900A4
    Public Const FSCTL_GET_REPARSE_POINT = &H900A8
    Public Const FSCTL_DELETE_REPARSE_POINT = &H900AC
 
    Public Const FSCTL_SET_SPARSE = &H900C4
    Public Const FSCTL_SET_ZERO_DATA = &H980C8
 
    Private Const INVALID_HANDLE_VALUE = -1
 
    Private Declare Function GetLastError Lib "kernel32" Alias "GetLastError" () As Integer
 
    Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" ( _
        ByVal lpFileName As String, _
        ByVal dwDesiredAccess As Integer, _
        ByVal dwShareMode As Integer, _
        ByVal lpSecurityAttributes As Integer, _
        ByVal dwCreationDisposition As Integer, _
        ByVal dwFlagsAndAttributes As Integer, _
        ByVal hTemplateFile As Integer) As Integer
 
    Private Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" ( _
        ByVal handle As Integer) As Integer
 
    Private Declare Function DeviceIoControl Lib "kernel32" ( _
        ByVal hDevice As Integer, _
        ByVal dwIoControlCode As Integer, _
        ByRef lpInBuffer() As Byte, _
        ByVal nInBufferSize As Integer, _
        ByRef lpOutBuffer() As Byte, _
        ByVal nOutBufferSize As Integer, _
        ByRef lpBytesReturned As Integer, _
        ByVal lpOverlapped As Long) As Integer
 
    Sub Main()
        Dim path As String = "D:\MyTest.dat"
        Dim hFileHandle As Integer
        Dim rc As Integer
        Dim iBytesReturned As Integer
        Dim inBuffer(512) As Byte
        Dim outBuffer(512) As Byte
 
        hFileHandle = CreateFile(path, GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0)
        If hFileHandle <> INVALID_HANDLE_VALUE Then
            Console.WriteLine("The {0} file has been created, handle is {1}.", path, hFileHandle)
            If Not ReportSparseStatus(path) Then
                ' Change the status to sparse...
                rc = DeviceIoControl(hFileHandle, FSCTL_SET_SPARSE, inBuffer, 0, outBuffer, 0, iBytesReturned, 0)
                Console.WriteLine("DeviceIOControl returned {0}.", rc)
                CloseHandle(hFileHandle)
                If rc = 0 Then
                    rc = GetLastError()
                    Console.WriteLine("DeviceIOControl failed with Win32Error {0}.", rc)
                Else
                    Console.WriteLine("DeviceIOControl call with FSCTL_SET_SPARSE returned as successful.")
                    If ReportSparseStatus(path) Then
                        Dim fs As New FileStream(path, FileMode.Open, FileAccess.ReadWrite)
                        fs.SetLength(33792000000)           ' SetLength takes a 64-bit Integer, so GB lengths are possible.
                        fs.Seek(fs.Length, SeekOrigin.Begin)
                        fs.WriteByte(42)
                        fs.Close()
                    End If
                End If
            End If
        Else
            Console.WriteLine("Unable to create file!")
            rc = GetLastError()
            Console.WriteLine("CreateFile failed with Win32Error {0}.", rc)
        End If
        Console.Write("Done...Press <Enter> to quit.")
        Console.ReadLine()
    End Sub
 
    Private Function ReportSparseStatus(ByVal path As String) As Boolean
        Dim fa As FileAttributes
 
        fa = File.GetAttributes(path)
        If (fa And FileAttributes.SparseFile) = FileAttributes.SparseFile Then
            Console.WriteLine("The {0} file is tagged as a sparse file.", path)
            Return True
        Else
            Console.WriteLine("The {0} file is NOT tagged as a sparse file.", path)
            Return False
        End If
    End Function
End Module

Hope this helps!

BTW: Why would you want to create a 33GB file with nothing in it?


RageInTheMachine9532
GeneralRe: How to create a SPARSE file in VB.NET Pin
WESHILL24-Feb-04 5:54
WESHILL24-Feb-04 5:54 
GeneralRe: How to create a SPARSE file in VB.NET Pin
WESHILL9-Mar-04 2:03
WESHILL9-Mar-04 2:03 
Questionmousehover? Pin
Nadroj14-Feb-04 6:42
Nadroj14-Feb-04 6:42 
AnswerRe: mousehover? Pin
Matthew Hazlett14-Feb-04 7:13
Matthew Hazlett14-Feb-04 7:13 
GeneralRe: mousehover? Pin
Nadroj14-Feb-04 7:21
Nadroj14-Feb-04 7:21 
GeneralRe: mousehover? Pin
Matthew Hazlett14-Feb-04 7:37
Matthew Hazlett14-Feb-04 7:37 
GeneralRe: mousehover? Pin
Nadroj14-Feb-04 7:44
Nadroj14-Feb-04 7:44 
GeneralNew to VB.Net from VB6 Pin
Gaz@UK14-Feb-04 5:33
Gaz@UK14-Feb-04 5:33 
GeneralRe: New to VB.Net from VB6 Pin
Michael P Butler14-Feb-04 6:07
Michael P Butler14-Feb-04 6:07 
GeneralRe: New to VB.Net from VB6 Pin
Gaz@UK14-Feb-04 21:12
Gaz@UK14-Feb-04 21:12 
QuestionVisual Basic 6.0 Skinning?? Pin
erikkloeze14-Feb-04 3:20
erikkloeze14-Feb-04 3:20 
AnswerRe: Visual Basic 6.0 Skinning?? Pin
r i s h a b h s16-Feb-04 19:45
r i s h a b h s16-Feb-04 19:45 
GeneralRe: Visual Basic 6.0 Skinning?? Pin
erikkloeze17-Feb-04 3:22
erikkloeze17-Feb-04 3:22 
GeneralRe: Visual Basic 6.0 Skinning?? Pin
Wilbur J. Pereira18-Feb-04 7:54
Wilbur J. Pereira18-Feb-04 7:54 
GeneralVB.NET for SQL Server problem Pin
bensoncd14-Feb-04 2:56
bensoncd14-Feb-04 2:56 
GeneralRe: VB.NET for SQL Server problem Pin
Ian Darling14-Feb-04 3:36
Ian Darling14-Feb-04 3:36 
GeneralOK: VB.NET for SQL Server Pin
bensoncd16-Feb-04 11:12
bensoncd16-Feb-04 11:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.