InfoPath - Populating a combo box with AD users from a web service - infopath

I have the need to populate a combobox in InfoPath with all the users from our Active Directory system. I'd also like this combo box to have auto-complete Can someone please point me in the right direction to accomplish this? Everything I find on the web seems to only load the currently logged-in user.
Thanks in advance!

If you have sharepoint server on your domain you can take advantage of contact selector control described here.
Otherwise you will be to forced to create some code in C#. Basiclly you have two options
Create custom control in C# and use it in infopath. Tutorial
Create standard infopath combobox and bind it to dynamically created collection in custom C# code.
This will be needed for both options: Extensive tutroial how to use class from DirectoryServices namespace.
Based on the comment I think you should take a look at this post about adding multiple contact selector controls into one infopath form and also this thread.

You'll have a bit of learning to do here I am afraid. You'll need to write an LDAP query to get this information. LDAP is a bit of a chore to learn. Using .NET, you can get some help from System.DirectoryServices namespace for help. e.g.:
var searcher = new DirectorySearcher("(objectCategory=user)");
var results = searcher.FindAll();
for (int i=0; i<results.Count; i++)
{
Console.WriteLine(results[i].GetDirectoryEntry().Name);
}
You'll probably need to refine the filter to limit searches to a particular OU to avoid returning service accounts and the like. You'll also want to look at pulling back properties for the user's Fullname etc.
Another route that might be MUCH easier is if your domain has Exchange, you could use the Exchange web service to query the global address list?

Related

asp.net datasource detailsview and CRUD permissions

Thanks for any thoughts. This question refers to an ASP.NET 4.0 web application.
A DetailsView then uses an ObjectDataSource (although any solution should apply to any of the ASP.NET DataSource controls) for CRUD operations.
A user has permission to view details for all records, but can only create or modify a single record related to their own department.
obviously I can easily modify the listview to show/remove the appropriate buttons
if (!_canModifySelectedWard)
{
dptDetailView.AutoGenerateEditButton = false;
dptDetailView.AutoGenerateInsertButton = false;
dptDetailView.AutoGenerateDeleteButton = false;
}
but this is only removing the buttons. Is there a neat way to disable the ability to edit/insert/delete functionality? I think a malicious request is highly unlikely once the user has access to this page, but it seems better practice to remove functionality, not just UI elements.
I can set the associated objectdatasource's InsertMethod etc. to null, but this almost seems like a hack.
Your object data source is tied to an class which is responsible for providing the data requested by the object data source. This is where additional checks should be performed to ensure unauthorized access to data doesn't happen.
Hiding the buttons is a good idea from a user experience perspective, but you should always make sure your business rules are being enforced.
Sorry I cannot provide any more detailed help. Perhaps if you could describe what you have going on in more detail, or post some code that would help.
Cheers.

The best solution to customize page controls based on some roles and settings

I have several pages in asp.net each with lots of controls. I Also have some roles in my application that each has some setting options. Now I want to prepare my page based on these settings. Maybe it’s not too clear, so please take a look at my example.
Example: There are some buttons, some textboxes, some datetime picker, and a chart in a page, now what I want is when a user sees this page, the controls appear and disappear based on the users role. An important thing is that I don’t want to have only visible and invisible controls, in some scenarios I need to show controls with some customizations. For example change chart data source, limit selecting date time and so on.
The first solution that I can think of, is saving the settings in database and after visiting the page by user, the settings fetch from database and based on those, I can customize the controls with conditional phrases (if and else). But I suppose it is not a good approach and my page will get very messy.
Please help me with any better solutions and if you know good references about it, please let me know.
Please see this link...use of ControlAdapters may help you...
Role-based enabling/disabling of controls in asp.net
You must use Thread.CurrentPrincipal.
A. When user login to your application, you attach his identity to thread, for example
string[] rolesArray = .....; //Get roles from dataBase by identity.
Thread.CurrentPrincipal = new YourCustomPrincipal(new YourCustomIdentity("YouName", "..."), rolesArray);
B. And when you navige about your application you test Thread.CurrentPrincipal
IPrincipal threadPrincipal = Thread.CurrentPrincipal;
if(threadPrincipal.Roles.Contains("roleTest"))
{
//Adjust your control
}

asp.net webform pattern re-use same page (view and edit)

i'm working on a project which aim is to create a sort of social portal.
The matter is that i've an entity page detail where user can edit it or just view it.
I'm considering to create just one page and using that as view only and edit mode at the same time.
I had two ideas:
1) create an enumeration ControlBehaviour { EditMode, ViewMode } in Session and using that to understand if I have to set readonly every controls in my page;
2) use jquery to set readonly every controls in the page if i have to open it in viewmode (or not readonly if i have to open it in edit mode).
Does it exist any pattern to reach my aim?
best regards
Separating your concerns into read and edit forms is most suitable, in terms of maintaining your code afterwards, by yourself or for someone else.
The DetailsView control is exactely what you are looking for

Kentico - Using the calendar to filter booking system events

Having a lot of problems getting to grips with the Kentico CMS, but I'm finally getting somewhere close. I'm using a normal portal engine and running Kentico 5.5 RC2 on a local installation.
I currently have an events page which uses a repeater to display all of the events that are available on the system currently. I want to use a calendar to be able to filter the events in that repeater. How would I go about this?
There are several ways.
Custom user control
Custom web part
Query string parameters
The easiest would be the last one. Or a combination of the first two with the last one. Add your calendar control via your preferred method (an AJAX Calendar, jQuery calendar, <asp:Calendar>, or whatever you like) and have it populate in a text field. Then have that run some JavaScript to change the URL query string which will reload the page.
Go to your Kentico repeater's web part properties. In the Content filter->WHERE condition field, you can write a standard SQL WHERE clause and inject query string parameters via the special macro: {?QUERYSTRINGPARAMETERNAME?}. For example http://url/page?myfilter=2 would be {?myfilter?}. That would make the WHERE clause something like: {?myfilter?} = '' OR {?myfilter?} = SqlFieldToCompare.
Kentico claims they escape that macro for security, though I haven't personally confirmed that. Works for us though.
If you went with a customer user control or web part, you could use safer postback methods with a Control macro (instead of the above QueryString macro).
For more info on macros, see the Developer's Guide Appendix A Macros.

How can I call a web service to insert a record into a database with jquery?

I am actually not sure if a webservice would be the correct way to go or if there is a better alternative, but here is my question. I have a dropdown with some products and I want to give the user the ability to add a new product, so when they select add new, it will pop up a dialog and when they are done it will insert the new product into a table in the database. My UI is basically a dropdown that is just html tags and I want to use JQuery to hopefully handle the backend processing. My webservice or alternative is asp.net. Can JQuery do this? and does anyone have an example?
You can use JQuery to issue web service call. Here is a good example here. Then in your web service method, you will insert the record into the DB.
So, your web service is your bridge. JQuery itself is client-side technology.

Resources