0

I am trying to display the contents of a specific folder on SharePoint within an InfoPath form. Here's what my current form is setup to do:

  1. The user selects a customer from a drop-down which is populated from List data on SharePoint. One of the columns in the list is the URL to a specific folder on Sharepoint that contains documents related to that customer.

  2. I would like a second drop-down to be populated with the names of the files in that specific folder based on the URL specified when a customer is chosen.

I can't seem to figure out a way to use a data connection to do this. Any ideas?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Adam
  • 255
  • 6
  • 17

1 Answers1

1

You can do this in the code behind of the form. Grab the url of the folder from the drop down and pass it to the code. Something like:

using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
    SPWeb web = site.RootWeb;
    SPFolder folder = web.GetFolder(urloffolder);
    foreach (SPFile in folder.Files)
    {
       //populate drop down with each file
    }
}
Meyer Denney
  • 796
  • 1
  • 11
  • 34
  • Thank you! I'm new to code for InfoPath so I'm not 100% on how to implement this. Could you give me some more details on where to actually put the code? I can figure out how to populate the values into the drop-down with some google searches. – Adam Apr 16 '12 at 17:14
  • 1
    One way is to add a button to your form and rig up a Button Click event to that button. If you right click and go to properties you should see something about creating a button click event. Put the code in there. You can assign a field to the drop downlist and use the xpath of the field to determine which item was selected in the drop down list. Hope this helps. – Meyer Denney Apr 16 '12 at 17:54
  • OK. So I added an event to check when the value in a certain field is changed. I'm in the code and I put the code you supplied in there. I think I need to import "Microsoft.SharePoint", but I must not have it installed? Do I need to download something? – Adam Apr 16 '12 at 18:13
  • 1
    Yes you need to add Microsoft.SharePoint. If you right click References in your Solution Explorer and select Add Reference, it should be in the .Net list. If not, search your computer for it and it by using the browse feature. – Meyer Denney Apr 16 '12 at 18:35
  • Looks like I don't have the SharePoint SDK installed. I'll get moving on that. I think I also had the language set wrong on the project, I just switched it to C#. – Adam Apr 16 '12 at 18:53
  • Yeah you will have to download that if you don't have. If you found my comments or answers helpful, could you please mark them so :) Thanks. – Meyer Denney Apr 16 '12 at 21:35
  • I think I may have figured out why I don't have Microsoft.Sharepoint.dll. I'm not developing this form on the SharePoint server. Is there a way to do this without it? Another method perhaps? – Adam Apr 17 '12 at 19:16
  • I thought you were trying to access data in a SharePoint list? To do that either you need to use the SharePoint client Object Model or you need to be on the same network as the SharePoint site collection. – Meyer Denney Apr 17 '12 at 19:24