Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6
This is the forum to discuss the Wrox book Beginning Visual Basic 2005 by Thearon Willis, Bryan Newsome; ISBN: 9780764574016
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 14th, 2006, 06:22 AM
Authorized User
 
Join Date: Feb 2006
Location: Dubai, UAE, United Arab Emirates.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Copy a File using VB 2005?

Dear All,

I’m trying to copy a file using VB 2005pro, for example: From CD to C:\vb\ Using System.IO.File.Copy(source, des, True) but everytime I get a message “Could not find a part of the path C:\VB\”

I’m getting the source using Open File Dialog, while I’m getting the destination from an ini file, using IO.StreamReader (readline)

Am I missing any step?

Appreciate your help…

Best regards,

PHENOM


>>>PHENOM<<<
__________________
>>>PHENOM<<&amp ;lt;
  #2 (permalink)  
Old March 14th, 2006, 07:26 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

It would be helpful to see the copy that does the file copy.

Thearon
  #3 (permalink)  
Old March 15th, 2006, 02:05 AM
Authorized User
 
Join Date: Feb 2006
Location: Dubai, UAE, United Arab Emirates.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Thearon
 It would be helpful to see the copy that does the file copy.
Thearon
Dear Thearon,

sorry but i didn't get what you mean? you want to see the code?

thanks & regards,

PHENOM

>>>PHENOM<<<
  #4 (permalink)  
Old March 16th, 2006, 07:36 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Does the source destination exist? What does your code that performs the actual copy look like?

Thearon
  #5 (permalink)  
Old March 18th, 2006, 12:28 PM
Authorized User
 
Join Date: Feb 2006
Location: Dubai, UAE, United Arab Emirates.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Thearon
 Does the source destination exist? What does your code that performs the actual copy look like?
Thearon
Dear Thearon,

thanks for the reply, my code look like the one below:

Dim dat As Date
        Dim Mm As String = 0
        dat = m_DataDB.Rows(1)("sdat")
        Select Case dat.Month
            Case 1
                Mm = "Jan" & Microsoft.VisualBasic.Right(dat.Year, 2)
            Case 2
                Mm = "Feb" & Microsoft.VisualBasic.Right(dat.Year, 2)
            Case 3
                Mm = "Mar" & Microsoft.VisualBasic.Right(dat.Year, 2)
         End Select
        Dim source As String = lblImgPath.Text & m_DataDB.Rows(1)("country") & "\" & Mm & "\" & m_DataDB.Rows(1)("filename")
        Dim des As String = lblDesPath.Text

        'Check the Destination & Source
        MessageBox.Show(des)
        MessageBox.Show(source)

        Try
            System.IO.File.Copy(source, des, True)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

both Dest and Soure exist...

thanks & regards

PHENOM


>>>PHENOM<<<
  #6 (permalink)  
Old March 19th, 2006, 09:25 PM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

I'm curious what the variables source and des contain? Can you post those? Also are you getting the date from a database?

Thearon
  #7 (permalink)  
Old March 20th, 2006, 01:19 AM
Authorized User
 
Join Date: Feb 2006
Location: Dubai, UAE, United Arab Emirates.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Thearon
 I'm curious what the variables source and des contain? Can you post those? Also are you getting the date from a database?
Thearon
Dear Thearon,

Des for Destination will be like this (C:\DFB\Story\) i'm getting this from an INI file...

Source will be like this (E:\Images2005\Lebanon\Dec05\Television\0304023599 01-L14014.MPG)

i'll explain to you how i'm getting this source:

lblImgPath.Text = in this case E:\Images2005\ "From CD-Rom"
m_DataDB.Rows(1)("country") in this case = Lebanon "From DataBase"
Mm = Dec05 from the select case...
m_DataDB.Rows(1)("filename") = Television\030402359901-L14014.MPG "From DataBase"

that's how i'm getting the source
so the final shape will as shown below:
Dim source As String = lblImgPath.Text & m_DataDB.Rows(1)("country") & "\" & Mm & "\" & m_DataDB.Rows(1)("filename")

Appreciate your help…

Best Regards,

PHENOM

>>>PHENOM<<<
  #8 (permalink)  
Old March 20th, 2006, 07:31 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

You are going to have to specify the filename as part of the destination. I ran a little sample which worked fine. Without the filename as part of the destination path, I encountered the same error as you did. Here's my code.

Thearon

Imports System.IO

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strSource As String = "C:\WINDOWS\Greenstone.bmp"
        Dim strDestination As String = "C:\Temp1\" & strSource.Substring(strSource.LastIndexOf("\") + 1)
        File.Copy(strSource, strDestination, True)
    End Sub
End Class
  #9 (permalink)  
Old March 20th, 2006, 09:56 AM
Authorized User
 
Join Date: Feb 2006
Location: Dubai, UAE, United Arab Emirates.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Thearon
 You are going to have to specify the filename as part of the destination. I ran a little sample which worked fine. Without the filename as part of the destination path, I encountered the same error as you did. Here's my code.
Thearon
Imports System.IO
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strSource As String = "C:\WINDOWS\Greenstone.bmp"
        Dim strDestination As String = "C:\Temp1\" & strSource.Substring(strSource.LastIndexOf("\") + 1)
        File.Copy(strSource, strDestination, True)
    End Sub
End Class
Dear Thearon,

Thank you very very much, it’s working now, I forgot to add the file name to the des, I really appreciate your help…

I have one more question, if you don’t mind…

How can I remove the ReadOnly form a file and a folder?

Thanks again

PHENOM


>>>PHENOM<<<
  #10 (permalink)  
Old March 21st, 2006, 09:59 PM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

To remove the ReadOnly attribute from a file, use the code below. When you start dealing with folder level security things get more complex and you need to have the appropriate permissions to modify the access control rights on a folder. My suggestion would be to start small and work your way up.

Thearon

Imports System.IO

Public Class Form1

    Private Sub btnFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFile.Click
        Dim strFile As String = "C:\Documents and Settings\Thearon\My Documents\kagi\arrow.gif"
        File.SetAttributes(strFile, FileAttributes.Normal)
    End Sub
End Class
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a VB 2005 exe file on a system without VB dilionyi Pro Visual Basic 2005 3 September 21st, 2009 07:37 PM
connecting Excel file in VB.NET 2005 vish_vj ADO.NET 1 March 1st, 2008 10:37 AM
VB 2005 question, binary to text file conversion pitcher General .NET 0 September 24th, 2007 07:45 PM
Running my VB 2005 exe file dilionyi Visual Basic 2005 Basics 4 August 10th, 2006 10:00 AM
Copy File - but need Envirement Variable - VS 2005 oceaniana General .NET 3 April 2nd, 2006 03:49 AM



All times are GMT -4. The time now is 10:01 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.