本文整理汇总了C#中IFileInfo.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IFileInfo.Write方法的具体用法?C# IFileInfo.Write怎么用?C# IFileInfo.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileInfo
的用法示例。
在下文中一共展示了IFileInfo.Write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyTo
/// <summary>
/// Copies this file's contents to the destination file.
/// The destination file will be overwritten if it already exists.
/// </summary>
/// <param name="destinationFile">The destination file.</param>
/// <remarks>
/// If the destination file is also a local file, the simple approach of using <see cref="File.Copy(string,string)"/> is used.
/// Otherwise, the <see cref="Write"/> method is used to copy the local file's stream on the destination file.
/// </remarks>
public FtpStatusCode CopyTo(IFileInfo destinationFile)
{
FtpStatusCode status;
if (destinationFile is LocalFileInfo)
{
// take a shortcut
File.Copy(_file, ((LocalFileInfo)destinationFile)._file, true);
status = FtpStatusCode.CommandOK;
}
else
{
// go the normal way
using (FileStream fs = new FileStream(_file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
status = destinationFile.Write(destinationStream => fs.CopyTo(destinationStream), Length);
}
}
return status;
}