Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
           //     };

           // }

              
            }
Posted
Updated 18-Mar-18 5:51am
Comments
Richard MacCutchan 16-Mar-18 4:14am    
The second error message suggests that the content of the file is not valid.
Richard Deeming 16-Mar-18 12:30pm    
You've tagged this as ASP.NET (actually "ASP" and ".NET", which would be a contadiction); you're trying to use HttpContext, which only exists in ASP.NET; but your question says you're writing a VSTO application, which is nothing to do with ASP.NET (nor ASP).

So which is it? If you're writing a VSTO add-in, you can't use ASP.NET idioms in your code.

1 solution

You can't access App_Data folder this way!

As MSDN documentation[^] states:
Quote:
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[^].


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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900