views:

98

answers:

1

Hi, all. I have a problem with uploading of the file in Silverlight application. Here is a code sample. In case when this file is opened in other application (excel or word for example) it fails to open it, otherwise it's working fine. I'm using OpenFileDialog to choose the file and pass it to this function.

    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;
    }

Is there any way i can access this file or should i just notify the user that the file is locked?

A: 

You should notify the user that the file is currently in use by another program. If another program has the file open with a lock that does allow a shared read there is no way to bypass this lock.

AnthonyWJones