This blog is about the dotnet.all types of codes,news about dotnet including asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.ncluding asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.asp.net programming,dot net programming,dotnet programs,dotnet source code,source code.

Free Hosting

Free Hosting

Thursday, January 22, 2009

Drag & Drop - Move files from desktop to a textbox(vb.net)

Drag & Drop - Move files from desktop to a textbox(vb.net)

Version: VB 2005
Compatibility: VB.NET 2002, VB.NET 2003, VB 2005, VB 2008
Category: File Manipulation

This example moves any files from desktop to a textbox. The example needs a reference to Shell32.dll

Declarations:
Imports Shell32
Imports System.IO.Path

Code:
Public Class Form1

Private Structure FileFormat
Public TypeFormat As String
End Structure

Private ff As New FileFormat

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
With Me
.CenterToScreen()
.TextBox1.AllowDrop = True
.ff.TypeFormat = "FileNameW"
End With
End Sub

Private Function DragAndDrop_MoveLink(ByVal Filename As String) As String
Const Filetype As String = ".lnk"
If String.Compare(GetExtension(Filename), Filetype, True) <> 0 Then Return Filename
Dim shell As Shell32.Shell = New Shell32.Shell
Dim DirectoryName As Shell32.Folder = shell.NameSpace(GetDirectoryName(Filename))
Dim Item As Shell32.FolderItem = DirectoryName.Items().Item(GetFileName(Filename))
Dim LinkObject As Shell32.ShellLinkObject = CType(Item.GetLink, Shell32.ShellLinkObject)
Return LinkObject.Path
End Function

Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) _
Handles TextBox1.DragDrop
If ff.TypeFormat = Nothing Then
Throw New Exception("Error...")
Else
If e.Data.GetDataPresent(ff.TypeFormat, False) Then
Dim Filename As System.Array = CType(e.Data.GetData(ff.TypeFormat, False), System.Array)
TextBox1.Text = DragAndDrop_MoveLink(CType(Filename.GetValue(0), String))
End If
End If
End Sub

Private Sub TextBox1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) _
Handles TextBox1.DragOver
If ff.TypeFormat = Nothing Then
Throw New Exception("Error...")
Else
If e.Data.GetDataPresent(ff.TypeFormat, False) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End If
End Sub

End Class

0 comments:

dotnet(.Net) Project Source code Downloads and Tutorials

Email Subscrption



Enter your email address:

Delivered by FeedBurner

Feedburner Count

Blog Archive

Unique Visitor

Design by araba-cı | MoneyGenerator Blogger Template by GosuBlogger