private void WriteXml()
        {
            int intSubCatId = 0;
            if (Request.QueryString["SId"] != null)
            {
                intSubCatId = Convert.ToInt32(Request.QueryString["SId"]);
                var result = from subcat in db.tblSubCategories
                             join alb in db.tblAlbums on subcat.SubCategoryId equals alb.SubCatId
                             where subcat.SubCategoryId == intSubCatId
                             select new { FlashImage = alb.PicUrl };
                if (result.Count() > 0)
                {
                    string strxmlDocpath = Server.MapPath("~/flash/banner/xml/banner.xml");
                    XmlTextWriter writer = null;
                    try
                    {
                        writer = new XmlTextWriter(strxmlDocpath, Encoding.UTF8);
                        writer.Formatting = Formatting.Indented; writer.WriteStartDocument(true);
                        writer.WriteComment("This file was generated from an ASPX file");
                        writer.WriteStartElement("banner");
                        writer.WriteAttributeString("width", "597");
                        writer.WriteAttributeString("height", "354");
                        writer.WriteAttributeString("startWith", "1");
                      
                        foreach (var query in result)
                        {
                            string strImage = query.FlashImage;
                            string strSlideImg = strImage.Replace("~/flash/banner/", "");
                            writer.WriteStartElement("item");
                            writer.WriteElementString("path", null, strSlideImg);
                            writer.WriteElementString("title", null, "");
                            writer.WriteElementString("target", null, "_blank");
                            writer.WriteElementString("link", null, "");
                            writer.WriteElementString("bar_color", null, "0xffffff");
                            writer.WriteElementString("bar_transparency", null, "40");
                            writer.WriteElementString("caption_color", null, "0xffffff");
                            writer.WriteElementString("caption_transparency", null, "60");
                            writer.WriteElementString("stroke_color", null, "0xffffff");
                            writer.WriteElementString("stroke_transparency", null, "60");
                            writer.WriteElementString("slideshowTime", null, "8");
                            writer.WriteEndElement();
                        }
                        writer.WriteEndElement();
                        writer.Flush();
                        writer.Close();
                        XmlDocument doc = new XmlDocument();
                        doc.Load(strxmlDocpath);
                        doc.Save(strxmlDocpath);
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                    }
                    Flash.Visible = true;
                }
                else
                {
                    Flash.Visible = false;
                }
            }
        }
 
 
No comments:
Post a Comment