我可以使用vsto解决方案中的xmlload读取XML或将XML从特定路径加载到我的应用程序吗 [英] Can I read XML or load XML from specifc path to my application using xmlload in vsto solution

查看:247
本文介绍了我可以使用vsto解决方案中的xmlload读取XML或将XML从特定路径加载到我的应用程序吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从VSTO解决方案的根目录App_Data文件夹中读取xml文件,这有可能在vsto解决方案中读取xml.如何获取目录路径.


I want to read xml file from root directory App_Data folder in VSTO solution is this possible to read xml in vsto solution. How can I get directory Path.


 var path = HttpContext.Current.Server.MapPath("~/TheXMLFile.xml");
            
here it is giving error ''HttpContext'' does not exist in the current ExcelAddIn1


even i have try using this 
 xml.LoadXml(@"~\App_Data\Product.xml");//Here given xml path location

this is also giving error about path 
error message is as 
Data at the root level is invalid. Line 1, position 1.

What I have tried:

<pre> private void btnGetExcl_Click(object sender, EventArgs e)
        {


            List<string> name = null;
            XmlDocument xml = new XmlDocument();
            //string path = @"~\App_Data\Product.xml.xml";
           // xml.LoadXml(@"~\App_Data\Product.xml");//Here given xml path location

            var path = HttpContext.Current.Server.MapPath("~/TheXMLFile.xml");
            var XmlData = XDocument.Load(path);


           // XmlNodeList xnList = xml.SelectNodes("/Trainings/Training");
           // foreach (XmlNode xn in xnList)
           // {
           //     new List<string>{
           //     xn["name"].InnerText
           //     };

           // }

              
            }

推荐答案

您无法通过这种方式访问​​App_Data文件夹!

作为 MSDN文档 [
You can''t access App_Data folder this way!

As MSDN documentation[^] states:
报价:

包含应用程序数据文件,包括.mdf数据库文件,XML文件和其他数据存储文件. ASP.NET使用App_Data文件夹存储应用程序的本地数据库,例如用于维护成员资格和角色信息的数据库.有关更多信息,请参见成员资格简介 [了解角色管理 [

Contains application data files including .mdf database files, XML files, and other data store files. The App_Data folder is used by ASP.NET to store an application''s local database, such as the database for maintaining membership and role information. For more information, see Introduction to Membership[^] and Understanding Role Management[^].



如果您将任何文件放在该文件夹中,则它们都无法下载/访问.请参阅:
ASP.NET入门指南应用程序文件夹 [ ^ ]

如果要授予对该文件的访问权限,则必须将Xml文件移动到其他文件夹中.或者...必须有一个公开xml数据的服务.请参阅: XML Web服务基础 [



If you place any file in that folder none of them gonna be downloadable/accessible. See: A Beginner''s Guide to ASP.NET Application Folders[^]

An Xml file have to be moved into different folder if you want to grant access to that file. Or... there must be a service which exposes xml data. See: XML Web Services Basics[^]


这篇关于我可以使用vsto解决方案中的xmlload读取XML或将XML从特定路径加载到我的应用程序吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆