Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / September 2005

Tip: Looking for answers? Try searching our database.

Calling OnSaveRequest Event using a custom button (c#)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Benjamin Wegner - 10 Aug 2005 16:15 GMT
Hi!

I created a form with a button. In the buttons code I tried to save the
current document using
thisXDocument.Save();
This will trigger the OnSaveRequest event but when
e.PerformSaveOperation()
is reached, an exception will be thrown.

When I click on the menuentry 'file -> save' the event gets triggered
as well and everything works fine.

It seems that when using the menu, Infopath sets some other values
prior triggering the event.

Am I able to do the same as Infopath? e.g. use some other method than
thisXDocument.Save();?

To give you an overview:
I want to create a form where users can click buttons like 'forward to
approver', 'approve request' or 'decline request'.

Regards,
Benjamin
Scott L. Heim [MSFT] - 10 Aug 2005 16:54 GMT
Hi Benjamin,

When you call the "Save" function (or a number of other functions as well)
through code it requires your form to be "fully trusted." This can be
accomplished by signing your form with a valid digital certificate or by
creating a setup package (with the RegForm tool from the InfoPath SDK)
where your users would need to install your solution.

Here are some links that should be of benefit:

Understanding Fully Trusted Forms
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/
ipsdkUnderstandingFullyTrustedForms.asp

Using the Form Registration Tool
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/
ipsdkUsingTheFormRegistrationTool.asp

Deploy a Fully Trusted Form to a SharePoint Form Library
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/
ipsdkDeployURNFormToSharePoint_HV01086376.asp

InfoPath SDK
http://www.microsoft.com/downloads/details.aspx?FamilyId=351F0616-93AA-4FE8-
9238-D702F1BFBAB4&displaylang=en

I hope this helps!

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights
Benjamin Wegner - 11 Aug 2005 10:18 GMT
Hi Scott,

thanks for your answer, but my form is alread signed and fully trusted.
I deployed this to a local folder and to a sps list, both the same
problem.

The problem occures only the first time I try to save a new document.

Regards,
Benjamin
Benjamin Wegner - 11 Aug 2005 14:34 GMT
When I call the save method within my btnApprove_OnClick eventhandler
in a new document, I get the following exception:
InfoPath cannot save the form.
The OnSaveRequest function returned a value indicating that the save
failed.
The form does not have a file name.
  at
Microsoft.Office.Interop.InfoPath.SemiTrust.SaveEvent.PerformSaveOperation()
  at
Microsoft.Office.Interop.InfoPath.SemiTrust.SaveEventWrapper.PerformSaveOperation()
  at
Microsoft.Office.Interop.InfoPath.SemiTrust.SaveEventWrapper.PerformSaveOperation()
  at mynamespace.ApplicationForm.OnSaveRequest(SaveEvent e) in
formcode.cs:line 85
  at
Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnSaveRequest(SaveEvent
pEvent)

  at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocument.Save()
  at
Microsoft.Office.Interop.InfoPath.SemiTrust.XDocumentWrapper.Save()
  at
Microsoft.Office.Interop.InfoPath.SemiTrust.XDocumentWrapper.Save()
  at mynamespace.ApplicationForm.btnSubmit_OnClick(DocActionEvent e)
in formcode.cs:line 149
  at
Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent
pEvent)
Scott L. Heim [MSFT] - 12 Aug 2005 13:19 GMT
Hi Benjamin,

Ah - now I have a better understanding. When you call the "Save" method,
this is used when the form has been previously saved - as such, the first
time you call this method it will fail.

As you are using .NET, there are a couple of options:

    - Display a .NET Save Dialog to allow the user to save the form
    - Use a "try/catch" statement and if the save fails, drop to the "SaveAs"
method and hard-code the location

Let me know if this helps!

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights
Benjamin Wegner - 05 Sep 2005 09:46 GMT
Hi Scott,
I am using the following code. It's nearly the same you suggested.

Regards,
Benjamin

if( thisXDocument.IsNew )
{
    if( thisXDocument.Solution.URI.LastIndexOf("Forms/") > 0 )
    {
        string url = thisXDocument.Solution.URI.Substring(0,
thisXDocument.Solution.URI.LastIndexOf("Forms/"));
        thisXDocument.SaveAs(url + this.GetFileName() + ".xml");
    }
    else
    {
        string url = thisXDocument.Solution.URI.Substring(0,
thisXDocument.Solution.URI.LastIndexOf("\\"));
        thisXDocument.SaveAs(url + "\\" + this.GetFileName() + ".xml");
    }
}
else
{
    thisXDocument.UI.SetSaveAsDialogFileName(this.GetFileName());
    thisXDocument.Save();
}
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.