|
Destaque Empreendimentos em Inform?tica
Guest
|
Hi for all,
I'm trying include in our Add-In solution a functionality to upload a Word file when user is editing it, like a save in the cloud.
The problem is that when I try to read the file, even using flags to open it at read only mode and without exclusive access, the Delphi raise an exception indicating that the file is already opened by another process.
For better comprehension, I putted bellow a part of my code (where I'm trying to open the file):
msArquivo := TFileStream.Create(pArquivo, fmOpenWrite or fmShareDenyWrite);
Search about it in the google, I found some people discusing that it is a Delphi issue, wich always ignore the flags. You can see it at the following links:
http://stackoverflow.com/questions/16027127/cant-open-file-a-second-time-even-though-marked-as-share-read-using-tfile
http://qc.embarcadero.com/wc/qcmain.aspx?d=115020
Can someone help me with ideas to how can I open the file to read its content? I'm thinking about save a copy of the file in a temporary folder, and save it again in the real path. So I can use the copy to upload, but I'm feeling that this workaround is bad.
Sergio |
|
Posted 19 Nov, 2014 08:42:15
|
|
Top
|
|
Donni Devito
Posts: 54
Joined: 2004-08-16
|
Hi,
I did it before. If you try to do it before save the document, you may only get the latest saved one. For this reason, if you want to send the final document, firt you have to save it then close it;
1. AddInInstance.WordApp.ActiveDocument.Save; //to save the document.
2.AddInInstance.WordApp.ActiveDocument.FullName; //to get the latest name. Maybe it is a new document and did not save before.
3.Close the document;
Var
SaveChanges : OleVariant;
SaveFormat : OleVariant;
Begin
SaveChanges:=wdDoNotSaveChanges;
SaveFormat:=wdOriginalDocumentFormat;
AddInInstance.WordApp.ActiveDocument.Close(SaveChanges,SaveFormat,EmptyParam);
end;
4.Now you have the document name to save it.
Regards. |
|
Posted 19 Nov, 2014 10:07:50
|
|
Top
|
|
Destaque Empreendimentos em Inform?tica
Guest
|
Hi Donni,
thank you very much by your help. But, I have a question: If I close the document, will I need reopen it to allow user continue working in it? Because I want perform the upload, but keeping the file opened.
Regards |
|
Posted 19 Nov, 2014 10:38:49
|
|
Top
|
|
Donni Devito
Posts: 54
Joined: 2004-08-16
|
Hi,
Infect, it is not possible to get file as is while opened. Word opens and locks the document. May be you have to consider the scenerio. May be you must wait till the user ends the writing.
Anyway,
I have no other idea till you explaind the requirements.
regards. |
|
Posted 20 Nov, 2014 05:56:31
|
|
Top
|
|
Destaque Empreendimentos em Inform?tica
Guest
|
Thank you Donni,
I want make a behaviour similar to the OneDrive documents. When we are editing a document which is saved in OneDrive, the MS Word performs an upload each time that we save the document.
Someone have another idea?
Thankful,
Sergio |
|
Posted 21 Nov, 2014 06:49:23
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18825
Joined: 2006-05-11
|
Hello Sergio,
Try using Document.WordOpenXML instead of uploading the document's file; the file is locked by Word. If only I remember correctly, this property was introduced in Word 2007.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 21 Nov, 2014 08:02:09
|
|
Top
|
|
Destaque Empreendimentos em Inform?tica
Guest
|
Hi Andrei,
can I read the content of file (in bytes) from Document.WordOpenXML? Can I open a read stream from Document.WordOpenXML to perform the upload?
Thankful,
Sergio |
|
Posted 21 Nov, 2014 09:13:14
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18825
Joined: 2006-05-11
|
Hello Sergio,
I suppose yes. I suggest that you verify if this is so.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 24 Nov, 2014 03:31:15
|
|
Top
|
|