Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-09-24
10
Medium Priority
?
1,362 Views
Last Modified: 2012-05-10
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
Comment
Question by:Rajkumar Gs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 14

Expert Comment

by:existenz2
ID: 33751792
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
 
LVL 23

Author Comment

by:Rajkumar Gs
ID: 33751804
Thanks for you immediate comment.

Could you please post the C# code ?

Raj

0
 
LVL 14

Assisted Solution

by:existenz2
existenz2 earned 2000 total points
ID: 33751900
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 14

Expert Comment

by:existenz2
ID: 33751915
0
 
LVL 23

Author Comment

by:Rajkumar Gs
ID: 33752079
Yes Guys! I acheived it!!

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

Raj
0
 
LVL 23

Author Comment

by:Rajkumar Gs
ID: 33752093
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
 
LVL 14

Expert Comment

by:existenz2
ID: 33752105
You indeed probably don't need it in all situations.
0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 0 total points
ID: 33752153
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
 
LVL 23

Author Comment

by:Rajkumar Gs
ID: 33752206
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
 
LVL 23

Author Comment

by:Rajkumar Gs
ID: 33752515
Response.Write("<xmp>" + XML + "</xmp>");
correct this line to
Response.Write(XML);
in my comment - http:#33752153

Raj
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question