top of page

Resource File con C#

Código simple para leer la información de un documento Resource File

Dada la clase Empresa

    public class Empresa
    {
        public string EmpresaNombre { get; set; }
        public string Mision { get; set; }
        public string Vision { get; set; }
        public List<string> Valores { get; set; }

    }

El código para leer el archivo es:

//Agregar la referencia System.Windows.Forms para poder usar las propiedades del Resoureceset

using AmcWeb2.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Resources;​

    public static class UserInformation
    {

 public static Empresa Empresa()
        {
            string nombreProyectoAsp = "AmcWeb2";
            string nombreArchivoResourece = "ContactResource";
            string parametrosResourece = nombreProyectoAsp + "." + nombreArchivoResourece;

            ResourceManager resxSet = new ResourceManager(parametrosResourece,
                 Assembly.GetExecutingAssembly());
            return new Empresa()
            {
                EmpresaNombre = resxSet.GetString("Empresa"),
                Mision = resxSet.GetString("Mision"),
                Vision = resxSet.GetString("Vision"),
                Valores = ListaValores()

            };
         

        }


    }
 

bottom of page