We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

file in use error

Thread ID:

Created:

Updated:

Platform:

Replies:

35645 Oct 5,2005 04:27 PM Oct 10,2005 03:04 AM Windows Forms 4
loading
Tags: XlsIO
Greg
Asked On October 5, 2005 04:27 PM

This should be simple. When Excel has a file open, and I attempt to open it with: streamIn = new FileStream(strFile,FileMode.Open,FileAccess.Read,FileShare.Read); I get an exception ("...is being used by another process."). My intent is to open it in read access mode only, to avoid this conflict, but I must have something wrong. Please advise. Thanks, Greg

Administrator [Syncfusion]
Replied On October 6, 2005 12:19 AM

Hi Greg, I herewith attach a Sample for your reference. OpenFromStream_1883.zip Please see to it and let me know if you have further questions. Best Regards, Seetha >This should be simple. > >When Excel has a file open, and I attempt to open it with: > >streamIn = new FileStream(strFile,FileMode.Open,FileAccess.Read,FileShare.Read); > >I get an exception ("...is being used by another process."). My intent is to open it in read access mode only, to avoid this conflict, but I must have something wrong. > >Please advise. > >Thanks, >Greg

Greg
Replied On October 7, 2005 04:38 PM

Did you actually test to see if the sample code you threw my way actually opens a file that is currently opened by Excel? If so, please state that in your reply, because the line of code this sample has for creating the FileStream is identical to mine, which does not work when the file is already opened by Excel. So, now that you have wasted more of my time by my having to install this useless sample to compile and run it, I have proven that it also does not work - just as I suspected. I would appreciate some real help. Sorry for being harsh, but not replying is actually better than throwing out crap. -Greg

Administrator [Syncfusion]
Replied On October 10, 2005 01:49 AM

Hi Greg, Sorry for the Inconvenience. We have already logged a feature request regarding this issue, you can track the status of this issue here. http://www.syncfusion.com/support/features/xlsio/Default.aspx?ToDo=view&questId=233 Please let me know if you have further questions. Best Regards, Seetha >Did you actually test to see if the sample code you threw my way actually opens a file that is currently opened by Excel? > >If so, please state that in your reply, because the line of code this sample has for creating the FileStream is identical to mine, which does not work when the file is already opened by Excel. > >So, now that you have wasted more of my time by my having to install this useless sample to compile and run it, I have proven that it also does not work - just as I suspected. > >I would appreciate some real help. Sorry for being harsh, but not replying is actually better than throwing out crap. > >-Greg

Administrator [Syncfusion]
Replied On October 10, 2005 03:04 AM

Hi Greg, I looked into this issue and it seems that MS Excel locks the file when opening it so it is not even to possible to open the filestream in Read-Only mode. However, I came across this workaround which might help in this situation string strFile = "..\\..\\Template\\OpenFromStreamTemplate.xls"; FileStream fs; //Opening a File from a Stream try { fs = new FileStream(strFile, FileMode.Open, FileAccess.Read); } catch(IOException) { //The file is locked so create a copy. File.Copy(strFile,"Copy.xls",true); //Open the copy. fs = new FileStream("Copy.xls", FileMode.Open, FileAccess.Read,FileShare.ReadWrite); } fs.Seek(0, SeekOrigin.Begin); IWorkbook workbook = excelEngine.Excel.Workbooks.Open(fs); //Close the workbook. workbook.Close(); //No exception will be thrown if there are unsaved workbooks. excelEngine.ThrowNotSavedOnDestroy = false; excelEngine.Dispose(); //Delete the temp file fs.Close(); File.Delete("Copy.xls"); I have also requested the development team to check if there is a more elegant solution to opening a locked file in readonly mode. Sorry for the inconvenience. Thanks, Stephen.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;