Windows Develop Bookmark and Share   
 index > Windows Forms Designer > File copying
 

File copying

Hello all!

I'm new to .NET development, and had a question dealing with file copying....

I need to create an object which will contain a file (document).

I need this class object to pick up a file given a full file path, and copy the file from the source system to the class object.

I wasn't sure if serializing this object was the best way to go about it, or if I should just use some sort of file copy to put it into the object byte-wise.......

I haven't been able to find the right functions to use for file copying in MSDN......could any of you push me in the right direction?

Thanks!!

-TW
MigrationUser 1  Wednesday, March 12, 2003 9:14 AM
It's unclear exactly what you're needing to do. Do you need to copy a file from one location to another within the file system? Or do you need to copy the contents of a file into some sort of data structure (normally, either a string (if it's text) or a byte array (if it's not) within your object?

The answers are different for the two options. Please indicate which one you're looking for, so we can help you better.
MigrationUser 1  Thursday, March 13, 2003 2:21 PM
Sorry for the confusion.......until this morning I was being confused myself.

I didn't quite have the spec in my hand yet :(

At any rate, what I need to do is copy a file from one place to another, and rename the file in the process (create a new file in a new location with a new name, but the same content as the origin file).

I know there are more than one ways to skin this cat, using FileStream, or using just Windows File copy (standard copying)......but I am not finding example implementations.....probably looking in the wrong place on MSDN :(

So that's what I am trying to do, thank you all for your patience!
MigrationUser 1  Thursday, March 13, 2003 2:25 PM
Well, this one is simple: use the File.Copy method, supplying the source file name and destination file name. It's as simple as that! The code might look like this:

System.IO.File.Copy("C:\YourSourceFile", "D:\YourDestinationFile")

That's it! Check out the File class in the Framework help for more information.
MigrationUser 1  Thursday, March 13, 2003 4:34 PM

You can use google to search for other answers

Custom Search

More Threads

• Extending BindingSource
• DataGridViewComboBox Cell Problem
• Why DataGridView behaves like this?
• designer can't load form. Where is 'more information'?
• BehaviorService Errors / Questions
• Composite Extender
• email validation control
• How can we avoid user to select node from diffrent category in trre control.
• Inherited Control
• Datagrid View column ordering bug.