Solved

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

Posted on 2010-09-24
10
1,280 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 500 total points
ID: 33751900
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 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