相关疑难解决方法(0)

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

我发送文件作为附件:

            // 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);
Run Code Online (Sandbox Code Playgroud)

然后我想将文件移动到另一个文件夹,但是当我尝试这样做时

                    try
                    {
                        //File.Open(oldFullPath, FileMode.Open, FileAccess.ReadWrite,FileShare.ReadWrite);
                        File.Move(oldFullPath, newFullPath);

                    }
                    catch (Exception ex)
                    {
                    }
Run Code Online (Sandbox Code Playgroud)

它抛出了一个异常,即该文件已在另一个进程中使用.如何解锁此文件以便将其移动到此位置?

c# attachment locked-files

13
推荐指数
4
解决办法
1万
查看次数

标签 统计

attachment ×1

c# ×1

locked-files ×1