Get name of form library from form - InfoPath Dev
in

InfoPath Dev

Get name of form library from form

Last post 07-27-2011 10:19 AM by enthdegree_. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 07-27-2011 09:06 AM

    Get name of form library from form

    Hello all,

     

    I have an InfoPath 2007 form up on a SharePoint 2007 form library. Is it possible for the form to get the name of it's library?

     This has left me stumped for quite a while. Initially I thought it was floating somewhere in the data connections wizard but I couldn't find it there. I've been doing it in part of my form code with uri parsing but it seems like that solution has the potential to break very easily.

    Thank you!

    Klaus Fiedler
  • 07-27-2011 10:19 AM In reply to

    Re: Get name of form library from form

     At any rate, Here's what I'm doing right now. I get the browser form's URI and then pull the library name out of that.

     For the sake of organization, paste this snippet right underneath the comment block that talks about member variables:

      private object _strUri
      {
        get { return FormState["_strUri"]; }
        set { FormState["_strUri"] = value; }
      }

    In my form load event code ( Tools > Programming > Loading Event... ):

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

    In my submit code:

      // Get URI
      string sUri = _strUri.ToString();

      // Extract library name
      int nUriLastSlashIndex = sUri.LastIndexOf('/');
      int nUriSecondToLastSlashIndex = sUri.LastIndexOf('/', nUriLastSlashIndex - 1);
      int nLibraryStringStartPosition = nUriSecondToLastSlashIndex + 1;
      int nLibraryStringLength = nUriLastSlashIndex - nUriSecondToLastSlashIndex - 1;
      string sLibrary = sUri.Substring(nLibraryStringStartPosition, nLibraryStringLength);

      // Write the value to somewhere in the form
      XPathNavigator xpnThis = this.MainDataSource.CreateNavigator();
      xpnThis.SelectSingleNode("/my:myFields/my:FormSuppliments/my:FormLibraryName", this.NamespaceManager).SetValue(sLibrary);

    EDIT: Ok, I've looked it up and this little code snippet isn't technically 'supposed' to work unless you close the form and reopen it exactly as I said I /didn't/ want to do. I have no idea how I had it working. Anyway it did jus break for me but fortunately I found a fix so I've edited it in.

    Klaus Fiedler
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.