miércoles, 11 de enero de 2012

Información del directorio activo desde InfoPath



1- Crear un proyecto de infopath



2- Opciones Avanzadas 



3- Seguridad y confianza

 

3- Programacion



4- Compatibilidad




5- Codigo fuente

Se debe asignar un directorio para almacenar el archivo xml, que contiene las propiedades que van a consultarse.

En ambientes de producción se deben dar los permisos a la carpeta.

Ej:



document.Load(@"C:\Users\Administrator\Documents\InfoPath Projects\codigoInfopath\Properties.xml");

Properties.xml

<?xml version="1.0" encoding="utf-8" ?>
<document>
      <property id="givenname" value="FirstName"/>
      <property id="sn" value="LastName"/>
      <property id="title" value="Job"/>
      <property id="l" value="City"/>
      <property id="department" value="Area"/>
      <property id="company" value="Company"/>
</document>




6- Editor de codigo

Directorio del xml

document.Load(@"C:\Users\Administrator\Documents\InfoPath Projects\codigoInfopath\Properties.xml");


Credenciales Dominio

DirectoryEntry root = new DirectoryEntry("LDAP://think.com"@"Administrator""Shar3p0int");








        public void InternalStartup()
        {
            EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
        }



//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------


        public void FormEvents_Loading(object sender, LoadingEventArgs e)
        {
            // Escriba aquí su código.
            // Get the user name of the current user.
            string userName = this.Application.User.UserName;
            //ActiveDirectoryAccess obj = new ActiveDirectoryAccess();
            Dictionary<stringstring> dictionary = new Dictionary<stringstring>();
            List<string> list = new List<string>();

            XmlDocument document = new XmlDocument();

            document.Load(@"C:\Users\Administrator\Documents\InfoPath Projects\codigoInfopath\Properties.xml");

            XmlNodeList nodes = document.SelectNodes("document/property");

            foreach (XmlNode node in nodes)
            {
                dictionary.Add(node.Attributes["id"].Value, node.Attributes["value"].Value);

            }
            foreach (KeyValuePair<stringstring> pair in dictionary)
            {
                list.Add(pair.Key);
            }

            Dictionary<stringstring> ADDictionary = GetInformation(userName, list);
            XPathNavigator xnMyForm;
            XmlNamespaceManager ns;

            try
            {
                xnMyForm = this.CreateNavigator();
                ns = this.NamespaceManager;

                foreach (KeyValuePair<stringstring> pair in dictionary)
                {
                    xnMyForm.SelectSingleNode("/my:myFields/my:" + pair.Value, ns).SetValue(ADDictionary[pair.Key]);
                }
            }
            catch (Exception ex)
            {

                throw;
            }
            finally
            {
                // Clean up. 
                xnMyForm = null;
            }

            // Clean up.

        }


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------




public Dictionary<string, string> GetInformation(string userName, List<string> list)
        {
            DirectorySearcher searcher = null;
            SearchResult result = null;
            DirectoryEntry employee = null;
            Dictionary<string, string> dictionary = new Dictionary<string, string>();

            try
            {

                // Create a DirectorySearcher object using the user name
                // as the LDAP search filter. If using a directory other
                // than Exchange, use sAMAccountName instead of mailNickname.

                DirectoryEntry root = new DirectoryEntry("LDAP://think.com", @"Administrator", "Shar3p0int");
                searcher = new DirectorySearcher(root, "(samaccountname=" + userName + ")");
                foreach (string data in list)
                {
                    searcher.PropertiesToLoad.Add(data);
                }
                // Search for the specified user.
                result = searcher.FindOne();

                // Make sure the user was found.
                if (result == null)
                {
//                    MessageBox.Show("Error finding user: " + userName);
                }
                else
                {
                    // Create a DirectoryEntry object to retrieve the collection
                    // of attributes (properties) for the user.
                    employee = result.GetDirectoryEntry();

                    foreach (string name in list)
                    {
                        if (!dictionary.ContainsKey(name))
                        {
                            if (employee.Properties[name].Value != null)
                            {
                                dictionary.Add(name, employee.Properties[name].Value.ToString());
                            }
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                //MessageBox.Show("The following error occurred: " + ex.Message.ToString());
                throw;
            }
            finally
            {
                // Clean up.
                searcher.Dispose();
                result = null;
                employee.Close();
            }

            return dictionary;
        }


7- Publicacion SharePoint Server










Manage form templates



Seleccionar la plantilla previamente creada.







8- Usar Plantilla desde SharePoint

- Crear una libreria de formularios

- Activar Tipos de Contenido


- Abrir en el browser


- Adicionar tipo de contenido de la plantilla y predeterminarlo, y borrando el que viene por defecto.




9- Adicionar Documento a la libreria





10- Resultado final