-
April 10th, 2011, 10:05 PM
#1
I want help in c sharp programming language?
I dont have an idea in this program
i wanted to know that how to copy form one file to another file using c sharp
programming please help me
-
April 10th, 2011, 11:36 PM
#2
Re: I want help in c sharp programming language?
I would use FileInfo.CopyTo(string). Here is the MSDN link: http://msdn.microsoft.com/en-us/library/f0e105zt.aspx
Basically
Code:
string sourcePath = //Whatever you want to copy
string destPath = //Where you want to copy it to
FileInfo fInfo = new FileInfo(sourcePath);
fInfo.CopyTo(destPath)
I've never actually done that before though. If you want to move files around, I strongly advise you to use shell scripting (bash under linux or batch under Windows). There may be some exceptions you must handle under C# (e.g. what happens if you try to access a file in C# that Windows doesn't think you are allowed to? it throws a security exception at you that you must handle lest your program crash).
Hope that helps.
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
April 11th, 2011, 02:41 PM
#3
Re: I want help in c sharp programming language?
In general avoid using batch files in Windows. The reason is that you can't easily capture any errors inside your C# program.
Instead, use the corresponding C# class (or Win32 api) to get the job done.
For file copying, see the File.Copy class in msdn.
Code:
try
{
File.Copy( sourceFileName, destFileName );
}
catch( Exception e )
{
// report error
}
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
|