Wrox Programmer Forums
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 23rd, 2008, 04:45 AM
Authorized User
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
Default Problem with saving a file

Hi All,

I have licence.exe file i want to save that file on runtime with different name. i mean to say that i want to make copy of that file on run time.

how can i achieve that ? is anybody have some idea ?


Old October 23rd, 2008, 05:05 AM
Friend of Wrox
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts


Here is a hint

Imports System.IO

    Function MoveFile(ByVal sOldLocation As String, ByVal sNewLocation As String) As Boolean

        On Error GoTo Err_Handler

        Dim oFile As New FileInfo(sOldLocation)

        oFile.CopyTo(sNewLocation, True)

        Return True
        ' No need to Report Errors at this stage
        If Err.Number <> 0 Then
            Exit Function
        End If
    End Function



VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Old October 23rd, 2008, 02:02 PM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Heuh? On error go to???? That's very old skool style. What about Try Catch?

Secondly, what's wrong with using the static Copy file? http://msdn.microsoft.com/en-us/libr...file.copy.aspx

File.Copy (oldLocation, newLocation)

And lastly, I'd be pretty confused by a method called MoveFile that would actually copy the file. So, all in all, I would use the following instead:

Dim oldLocation As String = "C:\SomePath\OldFile.txt"
Dim newLocation As String = "C:\SomePath\NewFile.txt"

File.Copy(oldLocation, newLocation)
Catch e As Exception
' Do what you need to do here to deal with the error
End Try

Nothing personal, but I wouldn't qualify the sample code given as a best practice in .NET development.



Imar Spaanjaars
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Old October 24th, 2008, 01:09 AM
Friend of Wrox
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts

Agreeing with you Imar!

File.Copy is the better one. The snippet I have posted was a trimmed down version of my requirement, which needs some logging (I have deleted those code in the forum posy for better brevity)



VBA Tips & Tricks (http://www.vbadud.blogspot.com)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with saving results grid to a file vgeier SQL Server 2000 2 June 1st, 2007 11:42 PM
saving a file tinybunny_8 ASP.NET 2.0 Professional 0 February 1st, 2006 05:39 PM
EXCEL question saving a file saving the the first macupryk VS.NET 2002/2003 0 January 6th, 2005 05:33 PM
.Net File Saving Problem vinod_pawar1 General .NET 1 July 4th, 2004 09:30 PM
Problem with saving binary file using VBScript Mythos VBScript 1 April 14th, 2004 05:28 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.