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
Printable View
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
I would use FileInfo.CopyTo(string). Here is the MSDN link: http://msdn.microsoft.com/en-us/library/f0e105zt.aspx
Basically
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).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)
Hope that helps.
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
}