System.IO.File.Copy C# (CSharp) Méthode

Copy() public static méthode

public static Copy ( String sourceFileName, String destFileName ) : void
sourceFileName String
destFileName String
Résultat void
        public static void Copy(String sourceFileName, String destFileName)
        {
            if (sourceFileName == null)
                throw new ArgumentNullException(nameof(sourceFileName), SR.ArgumentNull_FileName);
            if (destFileName == null)
                throw new ArgumentNullException(nameof(destFileName), SR.ArgumentNull_FileName);
            if (sourceFileName.Length == 0)
                throw new ArgumentException(SR.Argument_EmptyFileName, nameof(sourceFileName));
            if (destFileName.Length == 0)
                throw new ArgumentException(SR.Argument_EmptyFileName, nameof(destFileName));
            Contract.EndContractBlock();

            InternalCopy(sourceFileName, destFileName, false);
        }

Same methods

File::Copy ( String sourceFileName, String destFileName, bool overwrite ) : void
File::Copy ( string sourceFileName, string destFileName ) : void
File::Copy ( string sourceFileName, string destFileName, bool overwrite ) : void

Usage Example

        private async Task CopyConfigFile()
        {
            await Task.Run(() =>
            {
                try
                {
                    string sharedConfigFile = Path.Combine(SscUpdateManager.VersionFolder, GlobalResources.ConfigPath);
                    string curConfigFile    = Path.Combine(Environment.CurrentDirectory, GlobalResources.ConfigPath);

                    bool hasSharedConfig = File.Exists(sharedConfigFile);
                    bool useSharedConfig = Settings.Default.UseUserConfig;

                    Log.Logger.Debug($"has shared config?{hasSharedConfig}, useSharedConfig?{useSharedConfig}");

                    if (hasSharedConfig && useSharedConfig)
                    {
                        Log.Logger.Debug($"【copy config file】:copy {sharedConfigFile} to {curConfigFile}");

                        File.Copy(sharedConfigFile, curConfigFile, true);
                    }
                }
                catch (Exception ex)
                {
                    Log.Logger.Error($"【copy config file exception】:{ex}");
                    Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        SscDialog dialog = new SscDialog(Messages.ErrorCopyConfigFile);
                        dialog.ShowDialog();
                        Current.Shutdown();
                    }));
                }
            });
        }
All Usage Examples Of System.IO.File::Copy