Load and Read XML file in asp.net MVC - c#

I am facing a problem while working with xml file in asp.net mvc 5. I need to load a xml file. and read the xml data in different views. which have individual controller too. I have loaded the xml file successfully. But I can not catch the idea how can I pass the xml file data to other controller.
Like I have a Controller for loading the xml file. And I have another controller to read the xml data. Can you guys give me the idea how to do the rest work?

Sorry for my late answer. The problem was that I did not get full directory path to read the file. Then I created a cache memory to save the file and read it. And to read data in several controller I used like, Session["abc"] = "asas";
And to get this information in other controller, Viewbag.abc = Session["abc"];

Related

Saving data into files and reload them later

I am working on a WPF project with C#.
There is a MainWindow and some other windows showing some data. I have also three XML files, where data from lists can be saved. The code is all written and works perfect.
Now my question is, how to save the whole file. I want to have the capability to, for example, save all the data into files, and user can open these files later and load the data into lists, and commence working, where they left the application before.
Can anybody help me?
If I understand your question correctly, you need to do it with following steps:
Save your XML files with a specific extension name.
you can achieve this by many ways: e.g. you can save your actual XML files into a location, and then just create a link file that contents links to these files. Or you can ZIP all the XML files into one single file.
link the default extension name to your application (so it will be opened by your application by default)
Open/read the file with XML content from your application.
Check this
Deserialize XML into items and display them in your list.

View xml file in Internet Explorer from an asp.net page

I am new to Asp.net. I have a grid view which contains text fields as well as three buttons. My system is generating the xml file and I want to view that xml file in a separate window. Say for example, my grid view contains 3 rows and there will be 3 xml files where one file will be associated with each row. So what I want is to view the file whenever I click the button in the corresponding row.
Can someone help? I know that I need to use some java script.
There are several ways to solve this. For an easy solution you could write the XML in the Response.
If you want a new window you could create a temporary XML File and redirect to its URL.
//create the XML and put it in the filesystem -- just use google
ClientScript.RegisterStartupScript(GetType(), "SomeNameForThisScript", "window.open('http://UrlToYourXML.xml');", true);
You have several options here:
You can stream XML, most morden browsers can render XML. Just need to supply style.
Use jQuery plugin like JQgrid, to render XML
Process XML on server side to convert it to HTML/Datagrid

Saving HTML Table as xml or json

I'm looking for a way to save a table from an html page as xml or json. The current method i'm using save the entire page as and xls sheet and then reads the sheet using Office.InterLop.Excel. I want to skip saving the file and just read directly from the page using HttpRequest. Any ideas?
I assume you mean that you'd like to scrape the contents of a web page without File-> Save As?
Code project has a writeup explaining using HttpWebRequest to do just that. Or, you could use the newer HttpClient. Once you retrieve the HTML, you'll have to parse it yourself.
In the MSDN artticle, they're actually requesting JSON directly, so they don't have to deal with parsing, but you could very easily write up a RegularExpression to capture the table body.

Using C# to display an XML file transformed by XSLT

I don't know if this is possible or if I am thinking about this in the wrong way, but this is what I want to do:
I have an XML file linked to an XSLT file and I want to use C# to get the output of the transformed XML file and Response.Write() that wherever I want on the page.
I have found questions on stackoverflow about saving the transformed output to a new file etc, but I don't want to save it to a file, I just want to display it with Response.Write() anywhere on my aspx page.
Is there any way to do this in C#?
Any help is appreciated.
Yes, save the transformed file to a MemoryStream (so in memory not the hard disk). You can then output that to a string using a filestrem reader.
Another way of doing it is by using the XML control, it has XML and XSLT properties.
You could save yourself the effort and simply serve up the XML to the browser. As long as the XML document references the URL of the corresponding XSLT document, the browser will render the page for you.
Use HttpResponse.OutputStream as output stream to save transformed file.

How can I save objects as XML files

I'm working on my high-school matriculation asp.net project, and I wish to make a website of a bookstore.
I want to create two classes,Book and BookStore, and save the data created in XML files and not in a database.
How can I save objects as XML files, and how can I load them afterwards?
Thank you very much.
You need to use XML serialisation. There are tons of examples of how to do this, but here's one link for you to get started:
http://devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=236

Categories