读取silverlight程序形成的xap包中的文件

1. 读取xml或config文件内容

            Uri uri = new Uri("DataConfig.xml", UriKind.Relative);   //DataConfig.xml  为xap包中文件
            var sm = Application.GetResourceStream(uri);
            StreamReader reader = new StreamReader(sm.Stream);
            string xmlContent = reader.ReadToEnd();

            .......        //解析过程可参考此网址:  http://blog.csdn.net/u011480030/article/details/13037699

 

2. 往silverlight的canvas中粘贴图片

           Image myImage = new Image();
           myImage.Source = new BitmapImage(new Uri("Images/welcome.png", UriKind.Relative)); ;
           myImage.Height = 15;
           myImage.Width = 15;
           myImage.Opacity = 0.7;

           myImage.SetValue(Canvas.LeftProperty, 3d);
           myImage.SetValue(Canvas.TopProperty,3d);
           myImage.SetValue(Canvas.ZIndexProperty, 3);
           this.myCanvas.Children.Add(myImage);

 

3. 读取当前文件夹下的xml文件

          配置文件如下Web.config:

           
                   
                           
                   

            


          加载以及读取Rock_Names.xml文件中的内容

           string configData = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings.Get("rockNames"));  //读取文件名
            var appPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;   //获取物理位置,即文件夹路径
            string bodyFile = Path.Combine(appPath, configData);    //合并成完整路径
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(bodyFile);
            string xmlContent = xmlDoc.InnerXml;
            if (xmlContent.Trim().StartsWith(""))
            {
                XElement xe = XElement.Parse(xmlContent);
                IEnumerable elements = xe.Elements();
                foreach (XElement element in elements)
                {
                   
                }

            }



你可能感兴趣的:(编程语言)