How do I open a file that is opened in another application

前端 未结 4 1209
广开言路
广开言路 2020-12-09 09:15

I have an winforms application that loads in excel files for analysis. Currently, in order to open the excel file the file must not be already open in excel otherwise a File

4条回答
  •  庸人自扰
    2020-12-09 09:35

    You could try passing FileShare.ReadWrite when opening the file:

    using (var stream = new FileStream(
           @"d:\myfile.xls", 
           FileMode.Open, 
           FileAccess.Read, 
           FileShare.ReadWrite))
    {
    
    }
    

提交回复
热议问题