• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1489
  • Last Modified:

Open XML in Webpage using C# WITHOUT Saving and Loading in File

I am working on a Webservice Project in ASP.Net 3.5 / C#.

In this project, I am saving the Webservice request XML & response XML in SQL Server 2005 database.
In the report of Webservice transactions, there is links to OPEN these two XMLs from database in a new Webpage.
Currently I achieved this by
a. First read the XML contents from database by Stored Procedure.
b. Then save this XML string into a XML file using 'xmlDocument'.
c. Then load that XML file in IE.

Curretly working code is attached
 
..............
XML = (string)sqlCommand.ExecuteScalar();

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.InnerXml = XML;
xmlDoc.Save("C:\\XML\\" + Convert.ToInt64(Request.QueryString["ID"]) + ".xml");

System.Diagnostics.Process.Start("C:\\XML\\" + Convert.ToInt64(Request.QueryString["ID"]) + ".xml");

Open in new window


But I want to AVOID saving XML as file and reload it again. Instead need to show the XML to Webpage - It should looks like we opened the XML file in IE.

Hope it make sense!

Thanks In Advance
Raj
0
Rajkumar Gs
Asked:
Rajkumar Gs
  • 6
  • 4
2 Solutions
 
existenz2Commented:
Load the Xml in a MemoryStream then open a separate page which you over write the render method from and put the response type to "application/xml".

That should be enough.
0
 
Rajkumar GsSoftware EngineerAuthor Commented:
Thanks for you immediate comment.

Could you please post the C# code ?

Raj

0
 
existenz2Commented:
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Rajkumar GsSoftware EngineerAuthor Commented:
Yes Guys! I acheived it!!

Thanks @existenz2 for the link you provided http:#33751900

Raj
0
 
Rajkumar GsSoftware EngineerAuthor Commented:
In that link the final section 'Emitting XML Content to the Browser Window Directly' gave me the clue. But NOT used 'XmlTextWriter '  / Response.OutputStream for that.

Not done as mentioned there. I will explain.
Raj
0
 
existenz2Commented:
You indeed probably don't need it in all situations.
0
 
Rajkumar GsSoftware EngineerAuthor Commented:
Entire ASPX file code:-
<%@ Page Language="C#" ContentType="text/xml" CodeFile="OpenXML.aspx.cs" Inherits="OpenXML" %>

Only we need to specify ContentType="text/xml" for the Page directive.


Code-Behind C# Code:-
....................
 XML = (string)sqlCommand.ExecuteScalar();
Response.Write("<xmp>" + XML + "</xmp>");

That enough! It worked for me.
0
 
Rajkumar GsSoftware EngineerAuthor Commented:
I have opened a popup to view the XML when I click on 'View Request XML' / 'View Response XML' in a LinkButton code in Repeater.

Things are fine now :)

Thanks
Raj

lnkRequest.Attributes.Add("OnClick", "window.open('OpenXML.aspx','ViewXML','scrollbars=1,resizable=1')")

Open in new window

0
 
Rajkumar GsSoftware EngineerAuthor Commented:
Response.Write("<xmp>" + XML + "</xmp>");
correct this line to
Response.Write(XML);
in my comment - http:#33752153

Raj
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now