Date
1 - 8 of 8
Open file
Pavel Mencl
I do quite a lot excel files manipulations from Magic, both write and read, mostly via EPPlus and usually it's fine but there's one thing that occasionally stings me:
my programs don't work properly when the xls file is open by a user. How can I find out that this is the case? Thanks Pavel |
|
John Knickerbocker
Maybe try to copy the file first to another file name. If it copies, delete the copy and continue, it is not open. If it doesn't, give an error message that it is open. On Thu, Jan 19, 2023 at 3:05 PM Pavel Mencl <pavel.mencl@...> wrote: I do quite a lot excel files manipulations from Magic, both write and read, mostly via EPPlus and usually it's fine but there's one thing that occasionally stings me: |
|
Hello Pavel,
Just loaded a small code (XPA 4.9) to the Files section that does the job with the help of Dot Net. https://magicu-l.groups.io/g/main/files/Program_5_IsFileOpen.xml Following a previous tip from Mike - there's a good chance you'll be able to import it to previous XPA versions, as it uses no special new feature. Hope this helps. -- Gadi Birman
I know nothing (Manuel) Don't underestimate the power of the Source (GB) |
|
Roberto Ramirez Cervantes
Pavel, A simple solution that I have implemented is to try to rename the file that I want to open to test if some other application is using it; for example: File to open is "c:\temp\File.xls" Rename file "c:\temp\File.xls" to "c:\temp\File.xls.temp" If file "c:\temp\File.xls.temp" exist, file is not open by another application, rename file "c:\temp\File.xls.temp" back to "c:\temp\File.xls" and continue with logic. If file "c:\temp\File.xls.temp" does not exist, the file is open by another application, alert the user. I generate a random string instead of using the hardcoded text ".temp". -- Roberto Ramirez marionette_66@... On Thu, Jan 19, 2023, at 5:05 AM, Pavel Mencl wrote:
|
|
Pavel Mencl
Hi Gadi,
thanks, I like it as I've recently started to delve into the C# kingdom (this old dog likes new tricks,-)), hope you don't mind further question: it imported two versions of IsFileOpen program, one of them handles event DNExceptionOcurred. What kind of exception is anticipated to happen? I haven't been able to fire it off. Pavel |
|
Hi Pavel
I've accidentaly exported the whole project, instead of exporting only program 5. It may have caused a failed import as program 4 contained a control with a new property (Show Zoom Button) that is unavailable in older XPA versions. I've now replaced the uploaded file with the correct one: https://magicu-l.groups.io/g/main/files/Program5IsFileOpen.xml I believe you'll be able to import it. It worked on my end - I opened a PDF for editing and the program recognised it as locked. -- Gadi Birman
I know nothing (Manuel) Don't underestimate the power of the Source (GB) |
|
Pavel Mencl
Gadi,
that wasn't a problem, I have a 4.8 on my home laptop and it imported fine. For production I have 3.1 though but I don't mind rewriting it as it's short and useful for practice. It works like a charm, I've made it a function in MainProgram. I've implemented it without the IOException handling though as I don't know what ti use it for, yet. Thanks a lot Pavel |
|
Hi Pavel,
Thanks for the feedback. As for your previous question regarding the DNExceptionOcurred event handling - it was only for debugging purposes when I worked on an earlier version of program 5, and therefore redundant on the final version. I'll post another message soon that will shed some light on the DNExceptionOcurred event, as it's a very usefull Best Practice when starting to work with .NET code in XPA. -- Gadi Birman
I know nothing (Manuel) Don't underestimate the power of the Source (GB) |
|