SharePoint - What site was Infopath form opened From Issue

M

Mike C

I have posted this before. Is this possible to do. Please advise.

I have a form template saved to a site collection in Sharepoint. I then have
this form available on a site template that users will use to create sub
sites with. When the user creates a site they then need to fill out this
form. The form is supposed to read data from a list on the site and
prepopulate some fields on the form with that data.

The issue I have is the form needs to know which sub site and document
library it was opened from
in order to read from the list. I have been able to successfully do this
using this for new forms in a Loading event with code like below.

e.InputParameters["SaveLocation"].ToString();

The issue is this only work when the forms are opened in the browser. I need
to know how to accomplish this with forms opened in the Infopath client
application. Once the form
is saved I can use this to read the document library it was saved in :

e.InputParameters["XmlLocation"].ToString();

This is putting a project of mine on halt and is driving me nuts because if
you open the form and hit save it knows where to save it so you would think
you could access that information somehow.

If this is not possible please let me know.
 
M

Mike C

I figured this out finally. If anyone is interested.

You need to add this using line:

using System.Runtime.InteropServices;

Then add this inside your class:

[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetCommandLine();

Then you need to add something similar to this in your form loading event:

if (this.New)
{
IntPtr cmdLineStr = GetCommandLine();
String commandLine = Marshal.PtrToStringAuto(cmdLineStr);
string[] splitCommand = commandLine.Split('"');
string splitUrl = splitCommand[1].ToString();
}

This will give you the URL to the SharePoint Document Library that you
opened the from from.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top