C# - Return XML To The Response Stream?

Nov 10, 2010

I'm trying to return an xml string from a IHttpHandler to a like this: context.Response.Write(xml); When I receive the response in my .aspx.cs I try to load the document as follows: var xml = XDocument.Load(xmlString); but I get an Illegal Characters in Path error message. I've also tried

context.Response.Write(context.Server.HtmlEncode(xml));

and

var xml = XDocument.Load(Server.HtmlDecode(xmlString));

but I get the same message. Is there any way I can return XML from my IHttpHandler?

View 3 Replies


Similar Messages:

Save A File / Stream To Local Folder From Response Output Stream?

Feb 22, 2011

I have an excel file in my Response Output stream. I can Open the stream as a file after a prompt, but it doesn't seem I can save it directly to a specified folder on my client.

View 1 Replies

C# - Convert Response Stream To An Image?

Aug 29, 2010

in previously asked question answeres said they dont get what i want to do exactly so heres is the full code also i simply want that instead of a TABLESe i rendered an image( of the content ) on the page

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Text;
using System.Data;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Web.UI.WebControls.Panel panelmain = new System.Web.UI.WebControls.Panel();
System.Web.UI.WebControls.Literal abc = new System.Web.UI.WebControls.Literal();
abc.Text = "as<br/>dasdas<br/>dasdad";
DataSet ds = new DataSet();
DataTable dt;
DataRow dr;
DataColumn idCoulumn;
DataColumn nameCoulumn;
dt = new DataTable();
idCoulumn = new DataColumn("ID", Type.GetType("System.Int32"));
nameCoulumn = new DataColumn("Name", Type.GetType("System.String"));
dt.Columns.Add(idCoulumn);
dt.Columns.Add(nameCoulumn);
dr = dt.NewRow();
dr["ID"] = 1;
dr["Name"] = "Name1";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["ID"] = 2;.............

View 1 Replies

C# - Render Response Stream With Jquery?

Jan 9, 2010

MemoryStream export = new MemoryStream();
iCalendarSerializer serializer = new iCalendarSerializer(iCal);
serializer.Serialize(export,System.Text.Encoding.UTF8);
return export;

so I am using the C# DDay.iCal library for exporting my calendars. Serialize takes in a "stream" so I passed it a memory stream. I now have a generic handler that calls the method that contains the above code.

public class CalendarHandler : IHttpHandler
{
private Calendar service;
private Membership membershipS;
public void ProcessRequest(HttpContext context)
{
service = new Calendar ();
membershipS = new Membership (null);
string userName = context.User.Identity.Name;
Guid userId = membershipS.GetUsersId(userName);
context.Response.ContentType = "text/calendar";
// calls the export calendar(the code that showed above that uses dDay ical.
var t = service.ExportCalendar(userId);
t.WriteTo(context.Response.OutputStream);
}
public bool IsReusable
{
get
{
return false;
}
}
}

So now I wrote the icalendar to the Outputstream. Now I have a jquery post that goes to this method and now I am not sure how to take the OutputStream result that the jquery post will get and make it popup with a save dialog box.

$('#ExportCalendar').click(function(e)
{
$.post('../Models/CalendarHandler.ashx', null, function(r)
{
});
return false;
});

View 2 Replies

Insert Anywhere A String Into The Response Stream?

May 7, 2010

I created a simple Http Module that starts a timer on the PreRequestHandler and stops the timer on the PostRequestHandler to calculate the time it took the page to load. I then create some simple html and write my results to Response.Write. Since I'm doing this in the PostRequestHandler it's adding my results after the </html> tag. That's fine for testing but I need in a scenario where the page needs to validate.

I can't seem to figure out how I could manipulate the Response object to insert my results before the </body> tag. Response.Write and Response.Output.Write don't have that flexibility and I couldn't see a way to work with the Response as a string. Am I missing something easy?

View 1 Replies

C# - Create A BitmapDecoder Off .Net Response Stream?

Dec 6, 2010

We're getting this weird exception when trying to create a BitmapDecoder off an ASP.Net response stream. This is the line of code that throws the exception:

BitmapDecoder dec = BitmapDecoder.Create(
Request.Files[0].InputStream,
BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.OnLoad);

Here's some info on the file being uploaded: Filename: bank statement.jpg, Content length: 266041, Mime type: image/jpeg

This is the exception stack trace:

System.IO.IOException: Cannot read from the stream. --->
System.Runtime.InteropServices.COMException (0x88982F72):
Exception from HRESULT: 0x88982F72 [code]...

how we can prevent this from happening?

View 1 Replies

Update Image Based On Response Stream?

Sep 20, 2010

Is is possible to update an image on an HTML page using the response stream of an ASP.NET Generic Handler? For example, if I have the following code on a handler: [URL]

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "image/png";
context.Response.WriteFile("~/images/test.png");
}

How can I call the handler in jQuery, using .ajax, and set an image on the page equal to the image that is returned by the Handler? I am ignoring the query string variable at the moment as I just want to get this working. Secondly, if I can do above, how can I loop through all of DIVs on the page that are of class "content", select a guid out of a hidden field to use as my query string parameter, and update the associated image within the same content DIV tag? A content div tag would look as follows:

<div class="content">
<asp:TextBox runat="server" Id="HiddenField_1" Value="C142E68F-B118-4565-9A9E-B2347F0B6D5B"/>
<img src="#"/>
</div>
<div class="content">
<asp:TextBox runat="server" Id="HiddenField_2" Value="GJ38AD23-B118-4565-9A9E-B2347F0B6D5B"/>
<img src="#"/>
</div>

I would like to have all the images updated on a periodic interval, so essentially, as a quick recap, I would need to have: A loop through all of my DIVs of class "content", occuring every n. seconds. Extractation the GUID from the hidden field. A call to my ASHX handler to get the updated image. Set the returned image to the corrisponding image on the page. Is this something that would be difficult to achieve? If not, what would I need to do to make this function in the above manner?

View 1 Replies

C# - Response.WriteFile - Write Out A Byte Stream

Sep 21, 2010

Is is possible to write to the http response stream from a dynamically created bitmap using the Response.Write/WriteFile without saving the image to the hard drive?

View 4 Replies

Architecture :: How To Handle An Excel Stream And The Http Response

Jan 27, 2011

I'm using .net 3.5 and am currently creating a web application used to generate a report through Aspose.CellsActually, the page is composed in a form where I get the configuration of the report I have to generate. The "generation" button is in an update panel. When I click on it, the "generation" button is hidden and a progress bar appears. When the excel file is generated, I save it in a memory stream and I send it back to the aspx page where I change the headers to allow the file's download.

View 3 Replies

Examine WebResponse Without Affecting The Underlying Response Stream In .NET?

Oct 27, 2010

After a call to initial HttpWebResponse.GetResponseStream() and reading through the stream, that stream is done for and cannot be reused.

I have a situation where I need to examine the content of the response and if it is of a certain data, get another page and then pass the new response down the line. Otherwise, pass down the original response as is. The only problem is that after examining the response to check for this "special data", that response is no good to the downstream code.

The only way, I can think of, to make this transparent to the downstream code, is to create a derived class of HttpWebResponse, and somehow cache the data streamed, and pass that cached stream down the line instead of the initial stream. I'm not sure if that's even feasible since I haven't looked into it further.

View 3 Replies

MVC :: Unable To Remove The Cookie From The Response Stream After Reading It?

Sep 29, 2010

I am trying to use a custom ITempDataProvider provider to store TempData in a browser's cookie instead of session state. However, everything works fine except that I am unable to remove the cookie from the Response stream after reading it. The code exexutes fine but the cookie won't go away.

[Code]....

And in my controller:

[Code]....

View 6 Replies

MVC :: Return Text Stream Of HTML From Controller Action?

Nov 6, 2010

How does a controller action return an HTML stream as the View? ( in place of the name of the View file )

I want to return a simple "error detected" or "action completed" page to the browser. And I dont want to clutter up my project with yet another view. The return string being "<html><body><h1>Error. Customer xxxx is not found</h1></body></html>"

( thinking about it, better to have a general purpose view in a folder named "Common". Then pass the message text in ViewData. Still curious to know how to return an html stream. )

View 1 Replies

Web Forms :: Send A Large File To The Response Stream - OutofMemory?

May 20, 2010

I'm using Filestream for read big file (> 500 MB) and I get the OutOfMemoryException. Any solutions about it?? I want this in my app asp.net: Read DATA from Oracle Uncompress file using FileStream and BZip2 Read file uncompressed and send it to asp.net page for download. When I read file from disk, Fails !!! and get OutOfMemory. My Code is:

using (var fs3 = new FileStream(filePath2, FileMode.Open, FileAccess.Read))
{
byte[] b2 = ReadFully(fs3, 1024);
}
// [URL]
public static byte[] ReadFully(Stream stream, int initialLength)
{
// If we've been passed an unhelpful initial length, just
// use 32K.
if (initialLength < 1)
{
initialLength = 32768;
}
byte[] buffer = new byte[initialLength];
int read = 0;
int chunk;
while ((chunk = stream.Read(buffer, read, buffer.Length - read)) > 0)
{
read += chunk;
// If we've reached the end of our buffer, check to see if there's
// any more information
if (read == buffer.Length)
{
int nextByte = stream.ReadByte();
// End of stream? If so, we're done
if (nextByte == -1)............................

View 8 Replies

HttpHandlers / Modules :: Write The Response Stream Content To A File On Disk

Jan 20, 2011

I have an httpmodule and it has a handler for OnEndRequest. I am trying to write the HttpContext.Response.OutputStream to a file. I am trying to use the Read method of it. But when it is called the exception message i get is "Specified method is not supported". So i am not able to do what i want that is, write the response to a file on the disk. I am able to write the HttpContext.Request.InputStream to a file using its Read method which i do in a handler for OnBeginRequest.

View 2 Replies

Javascript - Response Object Not Returning Excel Stream In Update Panel?

Oct 11, 2010

I am generating an Excel file upon a click of a button in an update panel. It is throwing a parsing error.

If I keep the button outside the update panel it is working fine. Why isn't it working in the update Panel?

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition",
String.Format("attachment;filename={0}", filename))
Response.Clear()
Response.BinaryWrite(WriteToStream.GetBuffer)
HttpContext.Current.ApplicationInstance.CompleteRequest()
Private Function WriteToStream() As MemoryStream
'Write the stream data of workbook to the root directory
Dim file As MemoryStream = New MemoryStream
hssfworkbook.Write(file)
Return file
End Function

View 1 Replies

Jquery - How To Write A File To The Response Stream And Have A 'Working' Modal Window Show/hide

Feb 15, 2011

I need to to export a file to the user. It takes 1-2 min to generate the file so I'd like to have the page go into a kind-of modal mode with a layover on the page and a 'Working' spinner showing. The problem is I can't make the modal stuff go away after Save File dialog is closed.

How can I remove the layover after the dialog is done?

View 1 Replies

C# - Return CSV Response Without Headers?

Sep 23, 2010

I am writing an ASP.NET application that generates CSV string and returns it using response.write. However, along with the CSV string, the output comes with other information I would like to get rid of (e.g. ASP.NET version, time-stamp) etc. How can I just get the CSV string and nothing else?

View 1 Replies

VS 2008 - Return XML Response From HTTP Request

Apr 16, 2012

I am trying to the following to return xml response from an http request

Code:
Try
Dim id As String = Request.QueryString("id")
Dim xmlOut As String = ""
cn.ConnectionString = "Data Source=192.168.1.2;Initial Catalog=db;Persist Security Info=True;User ID=sa;Password=pass"
dad = New SqlDataAdapter("select * from tbl where id = '" & id & "'", cn)
ds.Clear()

[Code] ...

Is there some other way to do this without having to resort to writing the xml to a temp file on C drive and reading it again to display the output ?

View 2 Replies

.NET, Asynchronous Call To Another Page, Return Response Immediately?

Feb 13, 2010

An external server sends incoming SMS messages converted to HTTP requests into my sometimes very time-consuming .aspx page. If no response is returned to the external server in 20 seconds, this is considered as an timeout and the same message is sent to my aspx page again (and maybe again....The optimal solution for me would be that the aspx page reads the incoming message (as an HTTP request to the aspx page), starts the processing of the message in another thread, and immediately renders response back to the external server. The external server has no interest in other stuff than the HTTP status (normally 200). When the processing of the message is completed this results in an entry into the log file of the application.

View 2 Replies

Configuration :: ReadResponse() Failed - The Server Did Not Return A Response For This Request.

Sep 21, 2010

i am experiencing this error when i try to browse one of the application.The same app is working fine in the morning but when i tried to debug the app i am facing the error .Now i removed the debugger but still am facing this error.

View 1 Replies

MVC :: Want To Return A Response With Type Text/plain And Status Code 404?

Jul 26, 2010

I want to return a response with type text/plain and status code 404. How do I do that? I've found that ContentResponse allows for setting response type but how do I set response status code?

View 2 Replies

How To Read XML File Using System.IO.Stream With LINQ / Cannot Convert From 'System.IO.Stream' To 'string'

Jul 19, 2010

i will be passing the xml file like this:

[code]....

error:

Error 1 The best overloaded method match for 'System.Xml.Linq.XDocument.Load(string)' has some invalid arguments

cannot convert from 'System.IO.Stream' to 'string'

View 2 Replies

Web Forms :: Difference Between Response.Expire And Response.ExpiresAbsolute?

Mar 3, 2010

I am not able tto understand the differnce between REspose.Expire and Response.ExpiresAbsolute?

Is it mandatory to use both toghter?

View 4 Replies

Response Object / Response.AddHeader Is Used To Add A New HTML Header?

Jul 16, 2010

[Code]....

I am using this code to download and its working well for me.But i cant understand the code.Can someone explain me this code to me please?

Response.AddHeader is used to add a new HTML header,but what is an HTML header all about?and the parameters i am passing within it as the name and value;what are they?

View 3 Replies

Web Forms :: Response.Flush() | Response.Buffer = False: Neither Do Anything?

Sep 20, 2010

So,I have this code:

[Code]...

Even though I have buffer set to false,no text is displayed.I have tried adding a response.flush,with and without changing the buffer value.What exactly is wrong?I've also tried it with and without the label(i.e. with or without just Response.Write)

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved