Solved

VB.NET copying and renaming a file

Posted on 2008-10-29
2
1,351 Views
Last Modified: 2008-10-29
I need help in VB.NET to copy a file, rename it, and then put it in another folder.  If that file already exists, it will overwrite without prompting.  

For example file 22288Bank10292008_a3322.csv was downloaded.   The user will be able to use the OpenFileDialog1 to open this file from any where they save the file to.  From there, the program will take the file and copy, rename to input.csv, and put it in C:\Input\ folder.  There's a third party tool that we'll use to inport this into our ERP system and the tool only recognize file input.csv.

I looked online, but only found the script:  My.Computer.FileSystem.RenameFile(oldfilename, newfilename)
0
Comment
Question by:holemania
2 Comments
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 500 total points
ID: 22831972
Try this

System.IO.File.Copy("<source file path>","<destination file path>",true)

Eg: if your file name is oldfile.txt and you want to rename it to newfilename.txt

then use System.IO.File.Copy("D:\PickupFolder\oldfile.txt", "C:\Input\folder\newfilename.txt", true)

this will copy and rename the file and overwrite if file already exist
0
 

Author Comment

by:holemania
ID: 22833153
Sweet thanks.  That worked.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question