Solved

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

Posted on 2010-09-24
10
1,222 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
  • 6
  • 4
10 Comments
 
LVL 14

Expert Comment

by:existenz2
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 14

Expert Comment

by:existenz2
Comment Utility
0
 
LVL 23

Author Comment

by:Rajkumar Gs
Comment Utility
Yes Guys! I acheived it!!

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

Raj
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 23

Author Comment

by:Rajkumar Gs
Comment Utility
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
Comment Utility
You indeed probably don't need it in all situations.
0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 0 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Response.Write("<xmp>" + XML + "</xmp>");
correct this line to
Response.Write(XML);
in my comment - http:#33752153

Raj
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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 video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now