Save Acting Like Save As
Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan
Save Acting Like Save As
I've got the latest release of the ActiveX Viewer and I'm seeing a behavior I didn't notice before.
For example, if I open a PDF document in the AX Viewer, rotate a page, and go to File>>Save, the SaveAs dialog box pops up. I would expect the program to just save the update to the original file without displaying the SaveAs dialog. And I thought it behaved that way with older releases.
Is there a setting I'm missing, or did you intend Save to function as SaveAs in this case?
For example, if I open a PDF document in the AX Viewer, rotate a page, and go to File>>Save, the SaveAs dialog box pops up. I would expect the program to just save the update to the original file without displaying the SaveAs dialog. And I thought it behaved that way with older releases.
Is there a setting I'm missing, or did you intend Save to function as SaveAs in this case?
- Paul - Tracker Supp
- Site Admin
- Posts: 6897
- Joined: Wed Mar 25, 2009 10:37 pm
- Location: Chemainus, Canada
- Contact:
Re: Save Acting Like Save As
Hi jeffp,
Can you tell us how you are opening the file? An IStream or memory block will be different from a file name for example. Better yet would be to attach the relevant block of code for us to look at.
cheers
Can you tell us how you are opening the file? An IStream or memory block will be different from a file name for example. Better yet would be to attach the relevant block of code for us to look at.
cheers
Best regards
Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
Re: Save Acting Like Save As
I'm using a Stream (see code below). Is there something else I need to set so that Save works correctly with a Stream.
I'm using a Stream because I do not want to put a lock on the PDF file that I open. But I do need your Save menu in the Stream Open context to behave like Save if I were to open from your Open menu.
I'm using a Stream because I do not want to put a lock on the PDF file that I open. But I do need your Save menu in the Stream Open context to behave like Save if I were to open from your Open menu.
Code: Select all
function TPDFViewerAX.OpenDocument(AFileName: String;
APassword: String = ''; ADispFileName: String = ''): Integer;
var
AStream: IStream;
ADataIn, ADataOut: OLEVariant;
vArr: array of OLEVariant;
AFlags: Integer;
AWideStr: WideString;
begin
Result := 0;
if FileExists(AFileName) then
begin
SetDevInfo;
AFlags := 0; //AFlags := PXCVA_NoUI;
try
//Set UseStreamsDirectly
FControl.SetProperty('Documents.UseStreamsDirectly', 'False', 0);
//OpenDocument
AWideStr := AFileName;
SHCreateStreamOnFileW(PWideChar(AWideStr), 0, AStream); //STGM_READ
SetLength(vArr, 2);
vArr[0] := AStream;
vArr[1] := APassword;
ADataIn := vArr;
FControl.DoVerb('', 'OpenDocument', ADataIn, ADataOut, AFlags);
Result := ADataOut;
//Set DispFileName
if (ADispFileName = '') then ADispFileName := AFileName;
ADataIn := ADispFileName;
FControl.SetDocumentProperty(Result, 'DispFileName', ADataIn, 0);
//Set Modified
if not SameText(AFileName, ADispFileName) then
begin
ADataIn := ord(True);
FControl.SetDocumentProperty(Result, 'Modified', ADataIn, 0);
end;
InitializeDoc;
except end;
end;
end;
- Vasyl-Tracker Dev Team
- Site Admin
- Posts: 2353
- Joined: Thu Jun 30, 2005 4:11 pm
- Location: Canada
Re: Save Acting Like Save As
Hi, jeffp.
For your case, you should enable UseStreamsDirectly mode by:
FControl.SetProperty('Documents.UseStreamsDirectly', 'True', 0);
After this your input-stream object will be captured by our control for possible save operations in the future,
otherwise our control unlocks your input-stream after opening, "forgets" about it,
and the simple save operation will be impossible because destination will be unknown.
Best
Regards.
For your case, you should enable UseStreamsDirectly mode by:
FControl.SetProperty('Documents.UseStreamsDirectly', 'True', 0);
After this your input-stream object will be captured by our control for possible save operations in the future,
otherwise our control unlocks your input-stream after opening, "forgets" about it,
and the simple save operation will be impossible because destination will be unknown.
Best
Regards.
Vasyl Yaremyn
Tracker Software Products
Project Developer
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Tracker Software Products
Project Developer
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Re: Save Acting Like Save As
If I set it to True, will the file system put a lock on the file so that no other program can access it while it's open. I'm hoping to avoid this, and still have the save operation work.
...
Ok. I just made the change and set UseStreamsDirectly to True. However, when I open the document, rotate a page, then click on your save message, I get the following error:
Error saving document to external storage. Error [Application]: Destination Storage is wrong.
Maybe this is why I set it to False before.
..
On further seach, I looks like I reported a variant of this error before.
http://www.docu-track.com/forum3/viewto ... tly#p35656
...
Ok. Did confirm that you fixed that error when using SaveAs, but it is now there when you use just Save.
...
Ok. I just made the change and set UseStreamsDirectly to True. However, when I open the document, rotate a page, then click on your save message, I get the following error:
Error saving document to external storage. Error [Application]: Destination Storage is wrong.
Maybe this is why I set it to False before.
..
On further seach, I looks like I reported a variant of this error before.
http://www.docu-track.com/forum3/viewto ... tly#p35656
...
Ok. Did confirm that you fixed that error when using SaveAs, but it is now there when you use just Save.
- Vasyl-Tracker Dev Team
- Site Admin
- Posts: 2353
- Joined: Thu Jun 30, 2005 4:11 pm
- Location: Canada
Re: Save Acting Like Save As
Hi, jeffp.
Investigated.
The your sample code creates the read-only stream by:
SHCreateStreamOnFileW(PWideChar(AWideStr), 0, AStream);
- so, we cannot save into this stream in the future (our com-server is out-process).
Change it to:
SHCreateStreamOnFileW(PWideChar(AWideStr), STGM_READWRITE | STGM_SHARE_DENY_NONE, AStream);
Best
regards.
Investigated.
The your sample code creates the read-only stream by:
SHCreateStreamOnFileW(PWideChar(AWideStr), 0, AStream);
- so, we cannot save into this stream in the future (our com-server is out-process).
Change it to:
SHCreateStreamOnFileW(PWideChar(AWideStr), STGM_READWRITE | STGM_SHARE_DENY_NONE, AStream);
Best
regards.
Vasyl Yaremyn
Tracker Software Products
Project Developer
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Tracker Software Products
Project Developer
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Re: Save Acting Like Save As
Good catch. I missed this. Thanks.
Also, remind me the pros and cons of opening a file from a Stream versus just using your OpenDocument procedure. Originally, I had thought that opening via OpenDocument would lock the file so that other programs like Adobe couldn't open it while it was loaded in your viewer. But that doesn't appear to be the case.
Is one faster than the other?
When do you recommend using the Stream approach? And when the OpenDocument approach?
Also, remind me the pros and cons of opening a file from a Stream versus just using your OpenDocument procedure. Originally, I had thought that opening via OpenDocument would lock the file so that other programs like Adobe couldn't open it while it was loaded in your viewer. But that doesn't appear to be the case.
Is one faster than the other?
When do you recommend using the Stream approach? And when the OpenDocument approach?
- Vasyl-Tracker Dev Team
- Site Admin
- Posts: 2353
- Joined: Thu Jun 30, 2005 4:11 pm
- Location: Canada
Re: Save Acting Like Save As
If you use the:
OpenDocument(<FullFileName>...)
or equivalent:
DoVerb(NULL, "OpenDocument", dataIn(<FullFileName>), ...)
- it is fastest open-method but it locks(makes read-only) the source file for other programs.
Otherwise your method:
SetProperty("Documents.UseStreamsDirectly", "true", 0);
DoVerb(NULL, "OpenDocument", dataIn(<ReadWriteStream>), ...);
- does not lock the source file but it can be some slow because we сopy the entire data from your input-stream into a temporary file and work only with this file during viewing/editing of document.
The copy-time is small but it exists. If you specify the UseStreamsDirectly - we remember your input-stream for possible save operation from our temp file to your stream.
I think - it is best method for your case.
OpenDocument(<FullFileName>...)
or equivalent:
DoVerb(NULL, "OpenDocument", dataIn(<FullFileName>), ...)
- it is fastest open-method but it locks(makes read-only) the source file for other programs.
Otherwise your method:
SetProperty("Documents.UseStreamsDirectly", "true", 0);
DoVerb(NULL, "OpenDocument", dataIn(<ReadWriteStream>), ...);
- does not lock the source file but it can be some slow because we сopy the entire data from your input-stream into a temporary file and work only with this file during viewing/editing of document.
The copy-time is small but it exists. If you specify the UseStreamsDirectly - we remember your input-stream for possible save operation from our temp file to your stream.
I think - it is best method for your case.
Vasyl Yaremyn
Tracker Software Products
Project Developer
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Tracker Software Products
Project Developer
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Re: Save Acting Like Save As
Perfect. Thanks.
One more question: The Open menu item in the ViewerAX control uses which method? OpenDocument or Open from Stream.
One more question: The Open menu item in the ViewerAX control uses which method? OpenDocument or Open from Stream.
- Ivan - Tracker Software
- Site Admin
- Posts: 3549
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
- Contact:
Re: Save Acting Like Save As
It opens document from a file, not a stream.
Tracker Software (Project Director)
When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Re: Save Acting Like Save As
Here's the latest.
When I set UseStreamsDirectly to true and open as a stream using STGM_READWRITE | STGM_SHARE_DENY_NONE, there appears to be a lock on the source file. If I load a pdf as indicated above, then try to open the same file with Adobe, I get a message saying the file is locked.
I thought the source file was not to be locked in this case.
When I set UseStreamsDirectly to true and open as a stream using STGM_READWRITE | STGM_SHARE_DENY_NONE, there appears to be a lock on the source file. If I load a pdf as indicated above, then try to open the same file with Adobe, I get a message saying the file is locked.
I thought the source file was not to be locked in this case.
- Vasyl-Tracker Dev Team
- Site Admin
- Posts: 2353
- Joined: Thu Jun 30, 2005 4:11 pm
- Location: Canada
Re: Save Acting Like Save As
Hi, jeffp.
This problem occurs because you opened source file for write by:
SHCreateStreamOnFileW(PWideChar(AWideStr), STGM_READWRITE | STGM_SHARE_DENY_NONE, AStream);
- we can read from this stream without any problem, but Acrobat/Reader and the majority of other programs (and our standalone viewer) always open a source file in a special mode: allows reading but prohibits writing to this file by other programs. For more information, see http://msdn.microsoft.com/en-us/library ... 85%29.aspx, the dwDesiredAccess and dwShareMode group of flags.
So, if you want to keep the source file unlocked for other programs, you may:
1. create copy from source file to temp file and remember the LastWriteTime of the temp file (can be obtained by FindFirstFile api-function).
2. pass this copy to our control by OpenDocument, and setup DispFileName property of the opened document.
3. when document is closed (catch event about changing of "Documents.Count" property, and check existence of the document) - compare previous LastWriteTime with new.
4. if last-write-time stamps are different then try to replace source file by your temp file (it can be locked by Acrobat, for example )
5. delete the temp file.
Best
Regards.
This problem occurs because you opened source file for write by:
SHCreateStreamOnFileW(PWideChar(AWideStr), STGM_READWRITE | STGM_SHARE_DENY_NONE, AStream);
- we can read from this stream without any problem, but Acrobat/Reader and the majority of other programs (and our standalone viewer) always open a source file in a special mode: allows reading but prohibits writing to this file by other programs. For more information, see http://msdn.microsoft.com/en-us/library ... 85%29.aspx, the dwDesiredAccess and dwShareMode group of flags.
So, if you want to keep the source file unlocked for other programs, you may:
1. create copy from source file to temp file and remember the LastWriteTime of the temp file (can be obtained by FindFirstFile api-function).
2. pass this copy to our control by OpenDocument, and setup DispFileName property of the opened document.
3. when document is closed (catch event about changing of "Documents.Count" property, and check existence of the document) - compare previous LastWriteTime with new.
4. if last-write-time stamps are different then try to replace source file by your temp file (it can be locked by Acrobat, for example )
5. delete the temp file.
Best
Regards.
Vasyl Yaremyn
Tracker Software Products
Project Developer
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Tracker Software Products
Project Developer
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.