Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1401
  • 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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