You did not tell me which version of InfoPath you're using. If you're using
2003, do you have SP1 installed?
While the docs say that you should be able to use the two together
(Save/SaveAs and OnSaveRequest), I have never seen it work. The
XDocument.Save() will work if you have previously saved the form. If you
haven't previously saved the form, you must catch the error that it raises
and try using the XDocument.SaveAs() method. So you must do something like
the following in your button:
try
{
XDocument.Save();
}
catch (e)
{
XDocument.SaveAs("<path_to_file>");
}
Where code is concerned, you can do a search in this newsgroup or take a
look at this article:
http://msdn2.microsoft.com/en-us/lib...ffice.11).aspx
---
S.Y.M. Wong-A-Ton
"ISUComSciGuy" wrote:
> Thank you for your reply, line 44 had the call to XDocument.Save(). I've
> alter the code slightly since the last post, but am still receiving an error.
> Below is the code causing the error (I've simplified the code as much as
> possible)
>
> ----------------------------------------------------
> function XDocument::OnSaveRequest(eventObj)
> {
> var filePath = "file:///C:/";
> var fileName = XDocument.View.Name + ".xml";
> var fileURL = filePath + fileName;
>
> XDocument.UI.SetSaveAsDialogLocation(filePath);
> XDocument.UI.SetSaveAsDialogFileName(fileName);
>
> eventObj.IsCancelled = eventObj.PerformSaveOperation();
>
> if (eventObj.IsCancelled)
> {
> XDocument.UI.Alert("Save Cancelled");
> }
> else
> {
> XDocument.UI.Alert("Form saved");
> }
>
> eventObj.ReturnStatus = true;
> }
>
> function CTRL86_5::OnClick(eventObj)
> {
> XDocument.Save();
> }
>
> The following error occurred:
>
> InfoPath cannot save the form.
> The OnSaveRequest function returned a value indicating that the save failed.
> The following error occurred:
>
> The form does not have a file name.
> File:script.js
> Line:26
> ----------------------------------------------------
>
> I'm trying to prevent the user from having to manually enter the file name
> and file location and save the form with a single click. If the user click
> on the save command on the tool bar (instead of the button), the SaveAs
> dialog appears with the correct file name and file location. The error only
> appears when the user clicks the custom save button.
>
> I've tried to code the button with the code to produce the fileURL and to
> use the XDocument.SaveAs(fileURL) instead, but the same error pops up.
>
> However, if I use the SaveAs call in the button code (coding the file name
> in the button method and passing it the the SaveAs method), but do not use
> the custom save code in the OnSaveRequest() method (i.e. I deselect the Save
> using custom code on the File Option -> Save and Open tab) it works fine.
>
> Bottom line, can you use the Save or SaveAs method call from a button method
> and also use custom save code? And if you can, how (please include code
> sample)?
>
> ---
>
> Walter
>