コード例 #1
0
ファイル: Emoticon.cs プロジェクト: huwred/SnitzDotNet
        public static List<Emoticon> GetEmoticons()
        {
            if (HttpContext.Current != null)
            {
                if (HttpContext.Current.Request.PhysicalApplicationPath != null)
                {
                    string appdatafolder = AppDomain.CurrentDomain.GetData("DataDirectory").ToString(); //Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "App_Data");
                    XDocument loaded = XDocument.Load(appdatafolder + @"\emoticons.xml");
                    //IEnumerable<XElement> q = from c in loaded.Descendants("emoticon")
                    //        select c;
                    var q = from e in loaded.Descendants("emoticon")
                            group e by e.Attribute("image").Value into g
                            select g.First();

                    var list = new List<Emoticon>();
                    foreach (XElement element in q)
                    {
                        var smile = new Emoticon
                                             {
                                                 Image = (string) element.Attribute("image"),
                                                 Code = (string) element.Attribute("code"),
                                                 Description =
                                                     ReadResourceValue("emoticons", (string) element.Attribute("name"))
                                             };
                        string imageurl = VirtualPathUtility.ToAbsolute(Config.ImageDirectory + "emoticons/");
                        smile.ImageUrl = string.Format("{0}{1}", imageurl, smile.Image);

                        list.Add(smile);
                    }
                    return list;
                }
            }
            return null;
        }