Ask a questionAsk a question
 

AnswerFile.Replace("sourse","Destination");

  • Sunday, November 08, 2009 4:13 AMJoesoft11a Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    string filepath = "path\\";
    string filename = "Text.txt";
    
    File.Replace(filepath + "temp.tmp", filepath + filename);
    
    
    
    When I try athe above sample. I keep getting an

    Error 1 No overload for method 'Replace' takes '2' arguments 
    As far as I can tell I'm using 2 arguments.

    Can some one tell me why I'm getting this error

    Thanks


    Toppers BBS http://toppersbbs.dtdns.net

Answers

  • Sunday, November 08, 2009 4:24 AMTamer OzMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Hi,

    There are 2 overloads for this method. One with 3 and one with 4 parameters.

    I think you want to use the one with 3 parameters.

    As you can see in the documentation there is a 3rd parameter named BackupOfFileToReplace

    http://msdn.microsoft.com/en-us/library/9d9h163f.aspx


    By the way if you want to copy a file you can also use

    File.Copy(source, destination, true);
    
    Here the third parameter indicates that if destination file exists it'll be overwritten

    You can also use File.Copy(source,destination) but if the destination file exists it'll not be overwritten.
    • Marked As Answer byJoesoft11a Sunday, November 08, 2009 5:20 AM
    •  

All Replies

  • Sunday, November 08, 2009 4:24 AMTamer OzMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Hi,

    There are 2 overloads for this method. One with 3 and one with 4 parameters.

    I think you want to use the one with 3 parameters.

    As you can see in the documentation there is a 3rd parameter named BackupOfFileToReplace

    http://msdn.microsoft.com/en-us/library/9d9h163f.aspx


    By the way if you want to copy a file you can also use

    File.Copy(source, destination, true);
    
    Here the third parameter indicates that if destination file exists it'll be overwritten

    You can also use File.Copy(source,destination) but if the destination file exists it'll not be overwritten.
    • Marked As Answer byJoesoft11a Sunday, November 08, 2009 5:20 AM
    •