Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Sharing violation opening a file with OpenFileDialog - Can we change this??
1 replies. Latest Post by Yi-Lun Luo - MSFT on July 28, 2008.
(0)
CleverCoder
Member
203 points
157 Posts
07-24-2008 11:25 AM |
Good morning! I've recently ran into an issue with a sharing violation using the OpenFileDialog. Basically, we have the ability to import CSV data in our application. When I open Excel and create a CSV file, then save to disk and subsequently open it with Silverlight, I get a sharing violation and an exception is thrown. I only see two options for opening the file: "OpenRead" and "OpenText".
I assume that our hands are tied here and we can't tell the framework to open the file in manner thats safer. For instance, I can open the file with Notepad++ and it doesn't complain. The only difference I see is the options:
SL: Options: Synchronous IO Non-Alert, Non-Directory File, Open No RecallNOtepad++: Options: Synchronous IO Non-Alert, Non-Directory FileSo... does anyone have any experience with this? It seems that since it's a read only file open under ALL circusmtances, we should be able to open this file in this situation..
Cheers!
-Sean
Yi-Lun L...
All-Star
25052 points
2,747 Posts
07-28-2008 3:59 AM |
Hello, I think Office opens a file with the FILE_SHARE_WRITE flag, which means subsequent requests to this file must also include this flag, or the request will fail. Try to open the file in WordPad, and you'll also note an error. WordPad opens a file with the FILE_SHARE_READ flag only. However, Notepad, or your Notepad++, opens a file with both FILE_SHARE_READ and FILE_SHARE_WRITE flags, so the request succeeds. There's very little you can do in Silverlight to change this behavior. I've logged this as a feature request. But I can't assure you anything since the IO APIs are completely different on Mac, and we need to support both...