|
-
May 12th, 2010, 02:55 AM
#1
Thread Starter
Lively Member
Help with CopyFile
I am trying toi run the below code but it is giving error.
Code:
Dim BG_Logon As String
OpenFileDialog1.ShowDialog()
BG_Logon = OpenFileDialog1.FileName
My.Computer.FileSystem.CopyFile(BG_Logon, "e:\sss\sss.jpg")
Error: The file 'e:\sss\sss.jpg' already exists.
I have checked and there is no such file in E:\sss, no matter wherever I copy this file error remains the same. Any ideas?
< advertising link removed by moderator >
-
May 12th, 2010, 03:01 AM
#2
Re: Help with CopyFile
The file must exist or you wouldn't get that error message, unless something is seriously wrong with your system. Do you by any chance have code before that that might open a file at that location?
-
May 12th, 2010, 03:17 AM
#3
Thread Starter
Lively Member
Re: Help with CopyFile
I added a overwrite command but still no success in the system32 drive.
Code:
Imports Microsoft.Win32
Public Class Form1
Dim regkey As RegistryKey
Dim BG_Logon As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
BG_Logon = OpenFileDialog1.FileName
My.Computer.FileSystem.CopyFile(BG_Logon, Environ("%systemdrive%") & "\system32\oobe\info\backgrounds\defaultbackground.jpg", overwrite:=1)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
regkey = Registry.LocalMachine.OpenSubKey("Software", True)
regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", True)
regkey.SetValue("OEMBackground", 1)
regkey.Close()
My.Computer.FileSystem.WriteAllBytes(Environ("%systemdrive%") & "\md.cmd", My.Resources.md, 0)
Process.Start(Environ("%systemdrive%") & "\md.cmd")
End Sub
End Class
< advertising link removed by moderator >
-
May 12th, 2010, 04:12 AM
#4
Re: Help with CopyFile
Shall we assume that the file really did exist then?
You can not overwrite a file that is already open/locked in another application.
'No success' does not mean anything, explain the error.
-
May 12th, 2010, 06:06 AM
#5
Re: Help with CopyFile
 Originally Posted by jmcilhinney
Do you by any chance have code before that that might open a file at that location?
You never did answer this question.
-
May 12th, 2010, 11:32 PM
#6
Thread Starter
Lively Member
Re: Help with CopyFile
No, I haven't done that Check out my code, I written copy command after the file is opened.
< advertising link removed by moderator >
-
May 13th, 2010, 08:56 AM
#7
Frenzied Member
Re: Help with CopyFile
Why do you open it before you copy it?
-
May 13th, 2010, 10:33 AM
#8
Thread Starter
Lively Member
Re: Help with CopyFile
 Originally Posted by BrianS
Why do you open it before you copy it?
OOPs my bad
But it still it won't work can some1 do the coding for me
< advertising link removed by moderator >
-
May 13th, 2010, 11:23 AM
#9
Re: Help with CopyFile
Asking someone to 'do' the coding for you is like asking someone to make you a cake without telling you what type of cake to make. Your code looks OK, what you need to do is explain where the problem is.
Your 1st code example is different from your 2nd code example.
I will attempt to explain how you solve your own problem for yourself.
Try making a simple copy of a file you know exists to a place where you know the file does not to ensure you know how to use the command. With this, I mean using names you know can not fail, hardcoded filenames. Do not allow other code to run/get involved in this, it will confuse and maybe give you false results. For example:
Code:
My.Computer.FileSystem.CopyFile("c:\testfile.jpg", "c:\outputfile.jpg",True)
Run this a few times, if this works for you then you know your command use is correct. From there you can replace the parameters with variables:
Code:
My.Computer.FileSystem.CopyFile(BG_Logon, "c:\outputfile.jpg",True)
Now, if the file copy has worked you should be able to see it. If you have an error, then your source file is invalid as your first test worked over and over again. If you are running other code at the same time then your test results may not be accurate
Now you replace the other variable:
Code:
My.Computer.FileSystem.CopyFile(BG_Logon, Environ("%systemdrive%") & "\system32\oobe\info\backgrounds\defaultbackground.jpg,True)
If this works on its own, then something else in your program is causing the issue. If this does not work, then your filename you are trying to save to is invalid. You should look at your values before using them to ensure you have decent parameters.
Code:
Msgbox Environ("%systemdrive%") & "\system32\oobe\info\backgrounds\defaultbackground.jpg"
What does it look like, do you have 2 backslashes? \\
Once you have done all that you should know where the problem lies, the source params, the destination params, or something else in your code. If its something else, your gonna have to show us what else you do in your app.
If its your filenames, maybe you should look into using the IO.Path.Combine method instead like so:
Code:
IO.Path.Combine( Environ("%systemdrive%") , "system32\oobe\info\backgrounds\defaultbackground.jpg")
If I use this Environ("%systemdrive%") I get back a nothing, so thats a consideration to me. However Environ("systemdrive") returns "C:" combined with your hard coded path will still not give me the correct location of my system32 directory.
Hopefully you can look into why you have a failure and if you still have problems can explain more clearly what/where you are having issues.
Last edited by Grimfort; May 13th, 2010 at 11:30 AM.
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
|