CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2011
    Posts
    18

    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

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    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.

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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
  •  





Click Here to Expand Forum to Full Width

Featured