Tag: 锁定文件

使用C#可以测试文件上是否存在锁定

背景:我使用偏移到文件和文件流锁定/解锁menthods来控制读/写访问。 我正在使用以下代码来测试当前是否在文件上保留了锁 try { fs.Lock( RESERVED_BYTE, 1 ); fs.Unlock( RESERVED_BYTE, 1 ); rc = 1; } catch { rc = 0; } 题: 我的目标是消除try / catch块。 有没有更好的方法来查看锁是否存在? 编辑: 注意:此问题与文件是否存在无关。 我已经知道了。 它是关于同步写访问。

将文件作为附件发送后锁定文件

我发送文件作为附件: // Create the file attachment for this e-mail message. Attachment data = new Attachment(filePath, MediaTypeNames.Application.Octet); // Add time stamp information for the file. ContentDisposition disposition = data.ContentDisposition; disposition.CreationDate = System.IO.File.GetCreationTime(filePath); disposition.ModificationDate = System.IO.File.GetLastWriteTime(filePath); disposition.ReadDate = System.IO.File.GetLastAccessTime(filePath); // Add the file attachment to this e-mail message. message.Attachments.Add(data); 然后我想将文件移动到另一个文件夹,但是当我尝试这样做时 try { //File.Open(oldFullPath, FileMode.Open, FileAccess.ReadWrite,FileShare.ReadWrite); File.Move(oldFullPath, newFullPath); […]