Jump to content

_Word_DocSave and network drives


Recommended Posts

I got an error when I try to save a .doc file using _Word_DocSave() function. Going deep to understand why this function fail in my case I ended up thinking it might be an unexpected behavior of that function because this function check if $oDoc.FullName if a file on disk but this is a little bit tricky. In my case I have a SharePoint farm where I can upload files (especially .doc and .docx). SharePoint save this files as blob in database but there is a feature that let you view them with explorer. So I can enter in explorer a link like http://mysharepointfarm/bla/bla/ and in this location I can see all .doc files. So far so good, Because I cannot use _Word_Open with a link but I can as a file path, I came up with the idea to map a network drive so http://mysharepointfarm/bla/bla/ became K:\mydocfiles. Now things are interesting, _Word_Open works fine as I expected and any other _Word_* functions works well also except _Word_Save whici fail with error code 2 because $oDoc.FullName doesn't return the network drive location used as parameter for _Word_Open but instead returns the address of mapped location (ex: http://mysharepointfarm/bla/bla/myfile.doc) so FileExists won't find a find at this location. I think this issue can be reproduced in other cases involving mapped drives, not just this one and in my oppinion this validation is not perfect. Maybe there should be a precheck to verify the drive type or something like that. I fixed my code with a custom function that skip this validation but what do you think, is this something that need to be reported as bug and fixed or do you consider this to be a very special case?

This is the function about are we talking about.

Func _Word_DocSave($oDoc)
    ; Error handler, automatic cleanup at end of function
    Local $oError = ObjEvent("AutoIt.Error", "__Word_COMErrFunc")
    #forceref $oError

    If Not IsObj($oDoc) Then Return SetError(1, 0, 0)
    If Not FileExists($oDoc.FullName) Then Return SetError(2, 0, 0)
    $oDoc.Save()
    If @error Then Return SetError(3, @error, 0)
    Return 1
EndFunc

 

When the words fail... music speaks.

Link to comment
Share on other sites

When rewriting the Word UDF I only had file paths in mind - so yes, this might be a bug :(

I have never worked with Sharepoint before but IIRC I have read on this forum that you should check out a document before altering the content and then chick it in again - so it might not be a bug :)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I am agree the document should be verified before any alteration of its content but FullName property doesn't provide in all cases the real path so this validation might fail even if everything is right.

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

That's why the document should be checked out of SharePoint. You then get a local copy of the file to work with while it is locked on SharePoint until you check it in again.
IIRC this has been discussed on the forum before. Search for SharePoint and checkin or something similar.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

You missed my point, it's nothing regarding a technology. SharePoint was just my way to reproduce a more generic issue that can be reproduced in other cases. I have already a way to get it right so I don't have a problem (still wonder why this thread has been moved here). I posted for a debate if this is the way it is suppose to work this function. And about getting a local copy of the file to work with, I let you as a MVP to judge if is the proper way based on the fact that can be done without and maybe your post on something very similar were you seems  to understood the flaw of this validation of file existence.

When the words fail... music speaks.

Link to comment
Share on other sites

I see.
I will check if this is something I need to add to my bullet list :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 3 months later...

Andreik, sorry for my late reply.
I just noticed that I didn't find the time to investigate the problem and post my findings.

Saving a file using _Word_DocSave only works when a newly created file  has been saved before. That's what _Word_DocSaveAs needs to be used for.
_Word_DocSave checks the file for existance so it can return a meaningful error code and not just a COM error number.
This isn't necessary when the document already existed but it was easier to code and always do the file check.

I have modified all Word and Excel functions which open a file so you can specify an HTTP address as well. Some users had problems when opening Office documents located on SharePoint.
But I never had "complaints" about saving documents (except your thread).
This means that I won't modify _Word_DocSave at the moment.

I hope this is a decision you can live with ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...