Thursday, June 23, 2016

List to Comma Seperated String in C#


 var SelectedVals = loadedObject.somelist.Select(s =>  s.string).ToList();
 loadedObject.Values = string.Join(",", SelectedVals);

Tuesday, June 21, 2016

How to convert class into xml

    In Model :

    [Serializable]
    [XmlRoot(ElementName = "Process")]
    [XmlType("Exweb.Models.ExampleViewModel")]
    public class ExampleModel
    {
        [XmlElement("Organization")]
        public string Organization { get; set; }
        public string  Name { get; set; }
         
        [XmlIgnoreAttribute]
        public RangeCategory<string> Category { get; set; }
    }

In Controller

XmlDocument xmlDoc = new XmlDocument();
            XmlSerializer xmlSerializer = new XmlSerializer(model.GetType());

            using (MemoryStream xmlStream = new MemoryStream())
            {
                xmlSerializer.Serialize(xmlStream, model);
                xmlStream.Position = 0;
                xmlDoc.Load(xmlStream);

                XmlNodeList xmlnode = xmlDoc.GetElementsByTagName("ProcessControl");
                XmlNode root = xmlDoc.DocumentElement;
                

                string path = AppDomain.CurrentDomain.BaseDirectory + @"\Uploads\Process\";   --- save it into folder
                if (!System.IO.File.Exists(path))
                {
                    System.IO.FileInfo file = new System.IO.FileInfo(path);
                    file.Directory.Create();
                }
                xmlDoc.Save(path + model.ProcessName + ".xml");
            }

XmlAttributes.XmlIgnore Property


 [XmlIgnoreAttribute] 
  public RangeCategory Category { get; set; }

Monday, June 20, 2016

Devexpress mvc if control name contains dot in it


var RaceFrom = ASPxClientControl.GetControlCollection().GetByName("Race.From"); RaceFrom.SetText("SomeText")

How to Get data from input if input name contains "." in it


$("input[name='Religion.From']").val()

How to maintain state of tempdata in mvc


 TempData["Something"] = "value";
 TempData.Keep("Something");

Xml to Model in MVC


 XmlDocument doc = new XmlDocument();
 string path = AppDomain.CurrentDomain.BaseDirectory +  @"\Uploads\Process\" + filename;c var serializer = new  XmlSerializer(typeof(ModelName));
 var processData = XDocument.Load(path);
 FileStream loadStream = new FileStream(path, FileMode.Open,  FileAccess.Read);
 ProcessControlModel loadedObject =  (ModelName)serializer.Deserialize(loadStream);
 loadStream.Close();

Search

Custom Search
Protected by Copyscape Plagiarism Software