Ver Mensaje Individual
  #2 (permalink)  
Antiguo 09/10/2011, 13:42
Avatar de bieres
bieres
 
Fecha de Ingreso: marzo-2011
Mensajes: 63
Antigüedad: 13 años, 1 mes
Puntos: 5
Respuesta: Actualizar linea de un archivo

Hola Codymarc:
Código:
        [DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
        public static extern int GetPrivateProfileString(
            string lpAppName,        // points to section name
            string lpKeyName,        // points to key name
            string lpDefault,        // points to default string
            string lpReturnedString, // points to destination buffer
            int nSize,            // size of destination buffer
            string lpFileName        // points to initialization filename
        );

       [DllImport("kernel32", EntryPoint = "WritePrivateProfileStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        private static extern int WritePrivateProfileString(string lpApplicationName, string lpKeyName, string lpString, string lpFileName);

        /// <summary>
        /// Propiedad archivo.
        /// </summary>
        /// <value>Entrada ruta y nombre archivo a Leer/grabar datos.</value>
        /// <returns>Ruta/nombre del archivo.</returns>
        /// <remarks></remarks>
        static internal string Archivo
        {
            get
            {
                return m_Ini;
            }
            set
            {
                m_Ini = value;
            }
        }


        /// <summary>
        /// Leer una llave de un archivo .ini
        /// </summary>
        /// <param name="Seccion">Sección del archivo ini.</param>
        /// <param name="Llave">Llave.</param>
        /// <returns>Dato/Nothing.</returns>
        /// <remarks></remarks>
        static internal string LeeIni(string Seccion, string Llave)
        {
            try
            {

                int ret;
                string sRetVal;
                //
                sRetVal = new string(' ', 255);
                //
                ret = GetPrivateProfileString(Seccion, Llave, "", sRetVal, sRetVal.Length, m_Ini);
                if (ret == 0)
                {
                    return "";
                }
                else
                {
                    return sRetVal.Substring(0, ret);
                }
            }
            catch (System.Exception ex)
            {
                return null;
            }          
        }

        /// <summary>
        /// Grabar una llave a un archivo ini
        /// </summary>
        /// <param name="Seccion">Sección del archivo ini.</param>
        /// <param name="Llave">Llave de la seccion del archivo ini.</param>
        /// <param name="Valor">Valor de la llave.</param>
        /// <remarks></remarks>
        static internal bool GrabaIni(string Seccion, string Llave, string Valor)
        {
            try
            {
                WritePrivateProfileString(Seccion, Llave, Valor, m_Ini);
                return true;
            }
            catch
            {
                return false;
            }
        }
Tambien puedes usar Xml, te adjunto enlace.

http://www.devjoker.com/contenidos/A...XML-con-C.aspx

http://www.subgurim.net/Articulos/xm...heros-xml.aspx
__________________
http://medprest.com

Última edición por bieres; 09/10/2011 a las 14:19