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

Move() private méthode

private Move ( String sourceFileName, String destFileName ) : void
sourceFileName String
destFileName String
Résultat void
        public static void Move(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();

            String fullSourceFileName = Path.GetFullPath(sourceFileName);
            String fullDestFileName = Path.GetFullPath(destFileName);

            if (!InternalExists(fullSourceFileName))
            {
                throw new FileNotFoundException(SR.Format(SR.IO_FileNotFound_FileName, fullSourceFileName), fullSourceFileName);
            }

            FileSystem.Current.MoveFile(fullSourceFileName, fullDestFileName);
        }

Same methods

File::Move ( string sourceFileName, string destFileName ) : void

Usage Example

        public async Task <IActionResult> Edit(Guid id, Audio audio)
        {
            try
            {
                if (id != audio.ID)
                {
                    return(BadRequest());
                }
                var list = await AddOns.ReadFromJson();

                var solo = list.FirstOrDefault(x => x.ID == id);
                if (Data.Exists(AddOns.Path(directory: "Files", filename: solo.Name)))
                {
                    Data.Move(AddOns.Path(directory: "Files", filename: solo.Name), AddOns.Path(directory: "Files", filename: audio.Name));
                }
                solo.Name = audio.Name;
                solo.Size = audio.Size;
                await list.WriteToJson();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                await ex.LogAsync();

                return(View());
            }
        }
All Usage Examples Of System.IO.File::Move