Gå til innhold

Anbefalte innlegg

hei. kan jeg få en FileListBox til å liste opp alle filene i F.EKS http://home.no.net/danfredr/minefiler ?

 

og hvordan kan jeg få til slik at når jeg tar høyre klikk på filen så kommer det

en meny: kopier, klipp ut, Lim inn, slett ?

 

og hvis jeg dubbel klikker på en .txt fil så skal teksten inni den vises

i en textbox

 

Dette er i VisualBasic6

 

Jeg takker på fårhond :D (jeg glemmer det bare bort heletiden)

Lenke til kommentar
Videoannonse
Annonse

Jeg antar du må bruke FTP for å liste opp alle filene på en server. Legg til en listbox i en form og legg inn denne koden:

 

Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long
Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hConnect As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Long, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByRef dwContext As Long) As Boolean
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean

Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type

Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
Const FTP_TRANSFER_TYPE_ASCII = &H1
Const FTP_TRANSFER_TYPE_BINARY = &H2
Const INTERNET_DEFAULT_FTP_PORT = 21
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_FLAG_PASSIVE = &H8000000
Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4
Const MAX_PATH = 260

Const PassiveConnection As Boolean = True

Dim hConnection As Long, hOpen As Long

Private Sub Form_Load()

hOpen = InternetOpen("FTP client", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
hConnection = InternetConnect(hOpen, "SKRIV INN FTP-SERVEREN HER", INTERNET_DEFAULT_FTP_PORT, "DITT BRUKERNAVN", "DITT PASSORD", INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)

' Åpner mappen "minefiler" i root
FtpSetCurrentDirectory hConnection, "minefiler"

EnumFiles hConnection, List1

End Sub

Private Sub Form_Unload(Cancel As Integer)

' Renser opp
InternetCloseHandle hConnection
InternetCloseHandle hOpen

End Sub

Public Sub EnumFiles(hConnection As Long, ListBox As ListBox)

Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long

ListBox.Clear
pData.cFileName = String(MAX_PATH, 0)

hFind = FtpFindFirstFile(hConnection, "*.*", pData, 0, 0)
If hFind = 0 Then Exit Sub
Me.Print Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)

Do
pData.cFileName = String(MAX_PATH, 0)
lRet = InternetFindNextFile(hFind, pData)
If lRet = 0 Then Exit Do

ListBox.AddItem Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
Loop

InternetCloseHandle hFind
   
End Sub

 

Når det gjelder å få opp en popup meny må du først lage en, f.eks

 

mnuHidden

'''' mnuCut

'''' mnuCopy

'''' mnuPaste

'''' mnuDelete

 

Og så trykke vekk Visible i mnuHidden.

 

For å få popup menyen til å virke i ListBoxen når du Venstre-klikker bruker du denne koden:

 

Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = 2 Then Me.PopupMenu mnuHidden

End Sub

 

For å slette en fil bruker du dette: FtpDeleteFile hConnection, "test.txt"

 

 

Hvis du skal f.eks åpne en txt fil må du først laste filen ned til en midlertidig fil:

 


Dim Buff$

' Laster ned filen
   FtpGetFile hConnection, "test.txt", App.Path & "\Buff.txt", False, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0

' Åpner filen

Open App.Path & "\Buff.txt" For Binary As #1
Buff = Space(LOF(1))
Get #1, , Buff
Close #1

Text1.Text = Buff

 

Jeg skal se nærmere på kopiering av filer slik at man kan lime dem inn med Explorer (Utforsker), men FtpGetFile er det beste jeg kan finne på nå (Du har sikkert allerede sett hvordan man bruker den).

 

For å lime inn filer kan du bruke denne koden:

 

' Overfører filen "C:\test.txt" til "test.txt" i "minefiler" mappen.
FtpPutFile hConnection, "C:\test.txt", "test.txt", FTP_TRANSFER_TYPE_UNKNOWN, 0

 

Du vil sikkert at programmet skal lime inn en fil du har kopiert/klippet ut via Explorer. Du kan hente ut disse filene fra utklippstavlen med denne class-modulen.

Endret av aadnk
Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...