【问题标题】:Silverlight file upload - file is in use by another process (Excel, Word)Silverlight 文件上传 - 文件正在被另一个进程(Excel、Word)使用
【发布时间】:2011-02-24 01:27:30
【问题描述】:

全部。我在 Silverlight 应用程序中上传文件时遇到问题。这是一个代码示例。如果在其他应用程序(例如 excel 或 word)中打开此文件时,它无法打开它,否则它工作正常。我正在使用OpenFileDialog 选择文件并将其传递给此函数。

    private byte[] GetFileContent(FileInfo file)
    {
        var result = new byte[] {};

        try
        {
            using (var fs = file.OpenRead())
            {
                result = new byte[file.Length];
                fs.Read(result, 0, (int)file.Length);
            }
        }
        catch (Exception e)
        {
            // File is in use
        }

        return result;
    }

有什么方法可以访问这个文件,还是应该通知用户文件被锁定?

【问题讨论】:

    标签: silverlight excel upload openfiledialog


    【解决方案1】:

    您应该通知用户该文件当前正被另一个程序使用。如果另一个程序使用允许共享读取的锁打开文件,则无法绕过此锁。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-13
      • 1970-01-01
      • 2016-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多