|
-
Feb 28th, 2009, 12:21 PM
#1
Thread Starter
Lively Member
[RESOLVED] Allow User To Copy File To Folder or Drive
Hi,
I need to be able to allow a user to save a file to their choice of desktop, folder, flash drive etc etc.
They do not need to choose the file to copy, I can hard code this info into the code itself. They just need the abilty to choose where to save it.
Can anyone point me in the right direction please.
Thanks in advance.
Daz.....
-
Feb 28th, 2009, 12:29 PM
#2
Re: Allow User To Copy File To Folder or Drive
Yes use a commondialog to choose a file and then use the common dialog to save the file as well...
Edit
Here is an Example
Create a form, Add a label, Common Dialog, and two buttons to it. The First button is for file select and the second button is to save the file...
Code:
Private Sub Command1_Click()
On Error GoTo errhandler
CommonDialog1.CancelError = True
'~~> Set flags
CommonDialog1.flags = cdlOFNHideReadOnly + cdlOFNPathMustExist + cdlOFNFileMustExist
'~~> Set filters
CommonDialog1.Filter = "All Files (*.*)|*.*"
'~~> Display the Open dialog box
CommonDialog1.FileName = ""
CommonDialog1.ShowOpen
'~~> Store the path in label
Label1.Caption = CommonDialog1.FileName
Command2.Enabled = True
Exit Sub
errhandler:
Select Case Err
Case 32755 '~~> Dialog Cancelled
MsgBox "you cancelled the dialog box"
Case Else
MsgBox "Unexpected error. Err " & Err & " : " & Error
End Select
End Sub
Private Sub Command2_Click()
On Error GoTo errhandler
CommonDialog1.CancelError = True
'~~> Set filters based on the extention of the file chosen
Extn = Right(Label1.Caption, 3)
CommonDialog1.Filter = "*." & Extn & "|*." & Extn
'~~> Display the Save dialog box
CommonDialog1.FileName = Label1.Caption
CommonDialog1.ShowSave
'~~ Save the file
FileCopy Label1.Caption, CommonDialog1.FileName
Exit Sub
errhandler:
Select Case Err
Case 32755 '~~> Dialog Cancelled
MsgBox "you cancelled the dialog box"
Case Else
MsgBox "Unexpected error. Err " & Err & " : " & Error
End Select
End Sub
Last edited by Siddharth Rout; Feb 28th, 2009 at 12:46 PM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|