Solved

Setting Default Save Location in InfoPath Form

Posted on 2008-10-30
23
3,433 Views
Last Modified: 2011-10-03
I have a form published to a SharePoint document library that has a workflow attatched to it. When someone navigates to the form and clicks "New" it launches the form, which they then would save back to the library to kick of a workflow that does all sorts of stuff.

When they go to save the form however the default save location is always their document folers, is there a way I can either set the form or the clients to default to the specified sharepoint site for save operations?

I understand you can do something like this via "Submit" features, but I am doing a straight "Save" and do not want to change that operation.

Thanks!
0
Comment
Question by:dfxdeimos
  • 11
  • 10
  • 2
23 Comments
 
LVL 7

Expert Comment

by:CloudedTurtle
ID: 22849408
I believe that in order to do this without using a submit button, would be to specify custom Save code. This of course means that you need to use managed code to create the new save event to do whatever you want.
I'm not sure what your reservations are about changing to a submit, but depending on your skill level with .NET programming, it might be simpler to go with a submit, vs. custom code.
I am still doing some digging on this, and will let you know if there are any other options that  I find.
0
 
LVL 28

Expert Comment

by:clayfox
ID: 22850277
This is pretty simple.

Save is on the toolbar. In form options you can remove this and they just use the submit button instead. Or add a button on the bottom of the form and call it save or whatever you want.

The benefit for the user is that the action is one click, rather then having to name the file, possibly save it somewhere else by mistake, etc.

Create a submit data connection using the wizard to the Sharepoint library.  Use fields in the form and maybe the date, etc to create a standard naming scheme for each document.

This is best practice since save cannot be controlled or ensured.
0
 
LVL 14

Author Comment

by:dfxdeimos
ID: 22852639
I understand what you are saying about the submit functions, but that is not an option in this situation.

I am working in an environment that is built to some exact procedural specifications as to how operations are completed. The current procedures demand that a save is used instead of a Submit (not my choice / under my control).

I know this is possible, as I have seen it in other forms I have dealt with in the past.

Thank you.
0
 
LVL 28

Expert Comment

by:clayfox
ID: 22865016
I believe then you would have to use code to set the path and filename as cloudedturtle states.
0
 
LVL 7

Expert Comment

by:CloudedTurtle
ID: 22866850
To make this change using custom code, do the following:
  • Goto Tools Menu, select Form Options
  • On the Open and Save category check the checkbox in the "Save Behavior" section that reads "Save using custom code"
  • then click the "Edit" button.
Below is a snippet of sample code in VB that we give you your desired change. This is the full sub for the save, the important part in the "SetSaveAsDialogLocation" function...
Good luck!

Public Sub FormEvents_Save(ByVal sender As Object, ByVal e As SaveEventArgs)

            ' Write your code that will run before a Save or Save As operation here.
 

            SetSaveAsDialogLocation("c:\")
 

            ' The Dirty property will be set to false if save is successful.
 

            e.PerformSaveOperation()
 

            ' Write your code that will run after saving here.
 

            e.CancelableArgs.Cancel = False

        End Sub

Open in new window

0
 
LVL 14

Author Comment

by:dfxdeimos
ID: 22869735
Thank you for your suggestion. Just to clarify, when you click the "Edit" button to insert the custom code you posted, InfoPath has some pre-populated code in there. I wanted to be sure I should add this in the place indicated (it has a placeholder, something like "\\Nothing Here"). The resulting code looked like this:
/*

 * This file contains functions for data validation and form-level events.

 * Because the functions are referenced in the form definition (.xsf) file, 

 * it is recommended that you do not modify the name of the function,

 * or the name and number of arguments.

 *

*/
 

// The following line is created by Microsoft Office InfoPath to define the prefixes

// for all the known namespaces in the main XML data file.

// Any modification to the form template files made outside of InfoPath

// will not be automatically updated.

//<namespacesDefinition>

XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:tns="http://contoso.com/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-04T16:19:23" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');

//</namespacesDefinition>
 
 

//=======

// The following function handler is created by Microsoft Office InfoPath.

// Do not modify the name of the function, or the name and number of arguments.

//=======

function XDocument::OnLoad(eventObj)

{

	try

	{

		var CreateAccountData = XDocument.DataObjects["CreateAccount"];

		var CreateAccountAdapter = CreateAccountData.QueryAdapter;

		CreateAccountAdapter.Timeout = 120;

	}

	catch(e)

	{

		Public Sub FormEvents_Save(ByVal sender As Object, ByVal e As SaveEventArgs)

            ' Write your code that will run before a Save or Save As operation here.

 

            SetSaveAsDialogLocation("C:\Location\I\Am\Saving\To")

 

            ' The Dirty property will be set to false if save is successful.

 

            e.PerformSaveOperation()

 

            ' Write your code that will run after saving here.

 

            e.CancelableArgs.Cancel = False

        End Sub

	}

}
 

//=======

// Die folgende Handlerfunktion wurde von Microsoft Office InfoPath erstellt.

// Der Funktionsname und die Anzahl und Namen der Argumente dürfen nicht geändert werden.

//=======

function XDocument::OnSaveRequest(eventObj)

{

	// Erstellen Sie hier den Code, der vor dem Speichern ausgeführt werden soll.
 

	eventObj.IsCancelled = eventObj.PerformSaveOperation();
 

	// Erstellen Sie hier den Code, der nach dem Speichern ausgeführt werden soll.
 

	eventObj.ReturnStatus = true;
 

}

Open in new window

0
 
LVL 7

Expert Comment

by:CloudedTurtle
ID: 22869842
To start, it looks like you are using C# as your code base, so the code that I included will need to be updated with the C# equivelant.
Using the code snippet about, you should add the following code on line 5 in the function XDocument::OnSaveRequest(eventObj) section:
XDocument.SetSaveAsDialogLocation("C:\\"); (replacing C:\\ with whatever your path is. Besure to replace any \ with a double "\\".
0
 
LVL 14

Author Comment

by:dfxdeimos
ID: 22870082
Thank you for your quick response.

To confirm my code now looks like the following:
/*

 * This file contains functions for data validation and form-level events.

 * Because the functions are referenced in the form definition (.xsf) file, 

 * it is recommended that you do not modify the name of the function,

 * or the name and number of arguments.

 *

*/
 

// The following line is created by Microsoft Office InfoPath to define the prefixes

// for all the known namespaces in the main XML data file.

// Any modification to the form template files made outside of InfoPath

// will not be automatically updated.

//<namespacesDefinition>

XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:tns="http://contoso.com/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-04T16:19:23" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');

//</namespacesDefinition>
 
 

//=======

// The following function handler is created by Microsoft Office InfoPath.

// Do not modify the name of the function, or the name and number of arguments.

//=======

function XDocument::OnLoad(eventObj)

{

	try

	{

		var CreateAccountData = XDocument.DataObjects["CreateAccount"];

		var CreateAccountAdapter = CreateAccountData.QueryAdapter;

		CreateAccountAdapter.Timeout = 120;

	}

	catch(e)

	{

		// Do nothing currently.

	}

}
 

//=======

// Die folgende Handlerfunktion wurde von Microsoft Office InfoPath erstellt.

// Der Funktionsname und die Anzahl und Namen der Argumente dürfen nicht geändert werden.

//=======

function XDocument::OnSaveRequest(eventObj)

{

	// Erstellen Sie hier den Code, der vor dem Speichern ausgeführt werden soll.
 

	eventObj.IsCancelled = eventObj.PerformSaveOperation();

	

	XDocument.SetSaveAsDialogLocation("http://intranet.mycompany.com/Departments/Personal/Forms/FormLibrary");
 

	// Erstellen Sie hier den Code, der nach dem Speichern ausgeführt werden soll.
 

	eventObj.ReturnStatus = true;
 

}

Open in new window

0
 
LVL 7

Expert Comment

by:CloudedTurtle
ID: 22870105
That looks correct, be sure to preview and test the form before moving to production.
:-D
0
 
LVL 14

Author Comment

by:dfxdeimos
ID: 22870110
Hmm, this didn't seem to work as I expected. After re-publishing the form and re-opening it to create a new record it still defaults to the user's Documents folder.

Do I need to use a different syntax if my save location is a SharePoint Document Library instead of a local location?
0
 
LVL 7

Expert Comment

by:CloudedTurtle
ID: 22870207
..did you debug the code in the VS editor before publishing it?
Remove the XDocument prefix for the line that you added.. Final line should look like the code below...
Sorry, I didn't debug the code myself...
Before republishing, press F5 in the VS Code editor.. this should load the form in preview mode and you should be able to select Save and verify that it is working before publishing the form..

 
 

SetSaveAsDialogLocation(http://intranet.mycompany.com/Departments/Personal/Forms/FormLibrary);

Open in new window

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 14

Author Comment

by:dfxdeimos
ID: 22870330
I do not seem to have a "Debug" option in the "Microsoft Script Editor" that InfoPath opens up to create this code...
0
 
LVL 7

Expert Comment

by:CloudedTurtle
ID: 22870367
..okay.. Well then you should still be able to preview the form and test the functionality before you re-publish this form.. just saves you the work have publishing something that may not work.. and having to republish again, and again... :-)
0
 
LVL 14

Author Comment

by:dfxdeimos
ID: 22870488
Ok, when I preview the form with the line you specified in it, it still defaults to the user's Documents. If I hit cancel an error comes up saying there is a problem in the script.js file and asking me if I want to debug it. If I select yes, Visual Studio opens up the code, highlights the code line that we put in and gives the error "Microsoft JScript runtime error: Object expected"

I took a guess and also tried it with the "eventObj." prefix added to the line and it gave me an error that said the object didn't support that method.

Thank you again for taking the time to assist me with this, I really appreciate it.
0
 
LVL 7

Expert Comment

by:CloudedTurtle
ID: 22870799
..Okay.. Last shot, I think that this will do it.. you're line of code should look like this..
I have tested this and it seems to function as expected on my system.
 

XDocument.UI.SetSaveAsDialogLocation(http://intranet.mycompany.com/Departments/Personal/Forms/FormLibrary/);

Open in new window

0
 
LVL 14

Author Comment

by:dfxdeimos
ID: 22871108
Hmm...

I have tried it with both:

XDocument.UI.SetSaveAsDialogLocation(http://intranet.mycompany.com/Departments/Personal/Forms/FormLibrary/);

and

UI.SetSaveAsDialogLocation(http://intranet.mycompany.com/Departments/Personal/Forms/FormLibrary/);

and it doesn't change the default "Save As" location. On the plus side I don't get the errors I was getting with the other lines.
0
 
LVL 7

Expert Comment

by:CloudedTurtle
ID: 22871151
..Sorry... I am terrible at proof reading.. you need to surround your path with quotes ("path")
 

XDocument.UI.SetSaveAsDialogLocation("http://intranet.mycompany.com/Departments/Personal/Forms/FormLibrary/");

Open in new window

0
 
LVL 14

Author Comment

by:dfxdeimos
ID: 22871188
No worries, I included those anways.

Still a no go. I only have to check the box "Save using custom code" in order to activate the custom code, correct?

The complete code is as follows:
/*

 * This file contains functions for data validation and form-level events.

 * Because the functions are referenced in the form definition (.xsf) file, 

 * it is recommended that you do not modify the name of the function,

 * or the name and number of arguments.

 *

*/
 

// The following line is created by Microsoft Office InfoPath to define the prefixes

// for all the known namespaces in the main XML data file.

// Any modification to the form template files made outside of InfoPath

// will not be automatically updated.

//<namespacesDefinition>

XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:tns="http://contoso.com/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-04T16:19:23" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');

//</namespacesDefinition>
 
 

//=======

// The following function handler is created by Microsoft Office InfoPath.

// Do not modify the name of the function, or the name and number of arguments.

//=======

function XDocument::OnLoad(eventObj)

{

	try

	{

		var CreateAccountData = XDocument.DataObjects["CreateAccount"];

		var CreateAccountAdapter = CreateAccountData.QueryAdapter;

		CreateAccountAdapter.Timeout = 120;

	}

	catch(e)

	{

		// Do nothing currently.

	}

}
 

//=======

// Die folgende Handlerfunktion wurde von Microsoft Office InfoPath erstellt.

// Der Funktionsname und die Anzahl und Namen der Argumente dürfen nicht geändert werden.

//=======

function XDocument::OnSaveRequest(eventObj)

{

	// Erstellen Sie hier den Code, der vor dem Speichern ausgeführt werden soll.
 

	eventObj.IsCancelled = eventObj.PerformSaveOperation();

	XDocument.UI.SetSaveAsDialogLocation("http://intranet.mycompany.com/Departments/Personal/Forms/FormLibrary/");
 

	// Erstellen Sie hier den Code, der nach dem Speichern ausgeführt werden soll.
 

	eventObj.ReturnStatus = true;
 

}

Open in new window

0
 
LVL 7

Accepted Solution

by:
CloudedTurtle earned 500 total points
ID: 22871236
Exact code should be below... you have the new line in the wrong order, you need to set the path location before you perform the save function..
 

/*

 * This file contains functions for data validation and form-level events.

 * Because the functions are referenced in the form definition (.xsf) file, 

 * it is recommended that you do not modify the name of the function,

 * or the name and number of arguments.

 *

*/

 

// The following line is created by Microsoft Office InfoPath to define the prefixes

// for all the known namespaces in the main XML data file.

// Any modification to the form template files made outside of InfoPath

// will not be automatically updated.

//<namespacesDefinition>

XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:tns="http://contoso.com/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-04T16:19:23" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');

//</namespacesDefinition>

 

 

//=======

// The following function handler is created by Microsoft Office InfoPath.

// Do not modify the name of the function, or the name and number of arguments.

//=======

function XDocument::OnLoad(eventObj)

{

	try

	{

		var CreateAccountData = XDocument.DataObjects["CreateAccount"];

		var CreateAccountAdapter = CreateAccountData.QueryAdapter;

		CreateAccountAdapter.Timeout = 120;

	}

	catch(e)

	{

		// Do nothing currently.

	}

}

 

//=======

// Die folgende Handlerfunktion wurde von Microsoft Office InfoPath erstellt.

// Der Funktionsname und die Anzahl und Namen der Argumente dürfen nicht geändert werden.

//=======

function XDocument::OnSaveRequest(eventObj)

{

	// Erstellen Sie hier den Code, der vor dem Speichern ausgeführt werden soll.

	

	//Set Save As location

	XDocument.UI.SetSaveAsDialogLocation("http://intranet.mycompany.com/Departments/Personal/Forms/FormLibrary/");
 

	//Perform SAVE function 

	eventObj.IsCancelled = eventObj.PerformSaveOperation();

	

 

	// Erstellen Sie hier den Code, der nach dem Speichern ausgeführt werden soll.

 

	eventObj.ReturnStatus = true;

 

}

Open in new window

0
 
LVL 14

Author Comment

by:dfxdeimos
ID: 22871401
I am at a loss here... I plugged in the code that you posted in the previous message and I am still having the problem. No errors / debug messages but no success.

Do you know if there is a spot in the InfoPath program itself to specify the default save location for ALL forms? This is the only form that we will be using so that is an option as well.
0
 
LVL 7

Expert Comment

by:CloudedTurtle
ID: 22873310
I am not sure what is going on either, but everything as I can tell should be working fine. I don't know of any way to set the default location for all forms.
Unfortunately, I can't think of anything short of uploading your form, or remote accessing your PC that would help is resovling this problem.
You may be better off working with the process owner in the possibilities of using a custom submit function cleverly disguised as a Save button.  One caveate in only changing the default save path, is that the users can still over-write this path and save anywhere they like, it doesn't offer the same level of security that I suspect you are looking for...
Sorry I can't be more of a help.
0
 
LVL 14

Author Comment

by:dfxdeimos
ID: 22879294
Well, thank you for your help and suggestions. I really appreciate your time! =]
0
 
LVL 14

Author Closing Comment

by:dfxdeimos
ID: 31511886
I just figured I would award you the points for all the help you gave me. I am sure that anyone else searching for a solution for a custom save script would find your posts helpful.

Thank you again.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

When installing SharePoint 2010 RTM I came across a strange error, I was getting timeouts during the installation. I searched the web and found the best solution to be found here (http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010genera…
I recently came across an issue with a MOSS 2007 deployment where access into some sub-sites were denied, even for the MOSS farm administrators. A bit of background to the setup of this MOSS farm; this was a three server setup, consisting of a fr…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now