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


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

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 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

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

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

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

Render Output To String - Response.Flush Breaking Page Caching

Feb 3, 2010

I have some code that is used to replace certain page output with other text. The way I accomplish this is by setting the Response.Filter to a Stream, Flushing the Response, and then reading that Stream back into a string. From there I can manipulate the string and output the resulting code. You can see the basic code for this over at [URL] However, I noticed that Page Caching no longer works after the first Response.Flush call.

I put together a simple ASP.NET WebApp as an example. I have a Default.aspx with an @OutputCache set for 30 seconds. All this does is output DateTime.Now.ToLongTimeString(). I override Render. If I do a Response.Flush (even after the base.Render) the page does not get cached. This is regardless of any programmatic cacheability that I set. So it seems that Response.Flush completely undermines any page caching in use. Why is this?

extra credit: is there a way to accomplish what I want (render output to a string) that will not result in Page Cache getting bypassed?

ASPX Page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestCacheVsFlush._Default" %>
<%@ OutputCache Duration="30" VaryByParam="none" %>
<%= DateTime.Now.ToLongTimeString() %>

Code-behind (Page is Cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
Code-behind (Page is not cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
Response.Flush();
}
Code-behind (Page still is not cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
Response.Cache.SetCacheability(HttpCacheability.Server);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(30));
Response.Flush();
}

View 1 Replies

How To Render An Array Of Objects With JQuery

Apr 15, 2010

Assume the JSON returned is

{"2010143545":{"info":[1,"soccer"]},
"2010143547":{"info":[0,"Basketball"]}
}

How do I use JQuery to render the array on ASP.NET page? More precisely, what kind of HTML template do I need to set to stuff the JSON with JQuey?

View 1 Replies

Jquery - Render Html From Database Using Javascript?

Feb 14, 2011

I have a dynamic page which has repeating input text fields and is build using Jquery. I use C#.net to get the data to be displayed on the input fields. My question is on how do I handle single Quotes and double quotes while rendering the input field. I create jquery string on page render and uses that to render the input fields on the page. But if any of the input fields contains a html tag with double quotes then it screws up the whole page. Let me know I this make sense or need more explanation.

View 1 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 :: Render Table With Controls Using JQuery AJAX

Nov 25, 2011

I want to render ASP.Net Table control which has other controls using WebMethod and jQuery AJAX

View 1 Replies

JQuery :: How To Validate A Group Then Render A Single Error Message

Feb 18, 2011

How to validate a group then render a single error message?

Below returns error message on each field.

[code]....

View 4 Replies

JQuery :: Animate Effect Work But The Render Items Are Messed Up?

Aug 20, 2010

I have a very unique problem, humm i think. I am using a jquery effect that animate bounce effect, i have a line in my javascript pageLoad function $("#UserBrowserInfoDIV").show('bounce');

- the effects run smoothly but what it does is mess up the bolded text in the div. I have try the items inside the div without bolding and it works fine and no render problem but when bolded the text that are bolded is quite messed up, and barely readable. is there anything else i can do i really would like use this effect.

P.S all the effect have the same render problem, and i am using ie8 under compatibility mode.

View 2 Replies

JQuery :: Firefox Doesn't Render Correctly Inside Modal Dialog

Jan 19, 2011

I have tried searching for the answer but have failed to get any insight into this problem. Look at the following two examples. [URL] (JQuery modal dialog without <input> element) Above pages have very simple JQuery modal dialog, whihc displays correctly in IE, Chrome, Safari and Opera. Unfortunately, Firefox does not display the modal dialog with <input> correctly. It displays the other one correctly. I have tried the following without resolution to this peculiar problem:

- Changed doctype
- Used <table> to enclose <input>
- Used <div> to enclose <input>
- Used all possible CSS display attributes for <input>

View 2 Replies

Web Form Render Engine Outputs A Control Tree / Looking For Info On Render Logic.

Feb 12, 2011

I've been watching a video on Scott Hanselmnn teaching MVC 2 tricks/tips. He mentions how MVC 2 by default uses ASP.NET Web Forms view engine to render the output of the views; he mentions that the web forms view engine is a little slower than it could be for MVC 2 since it generates a control tree and then outputs the HTML to the page (I hope I said that right).

I was wondering what he meant by web forms generating a code tree before outputting the HTML to the page. Does anyone have insight on the view engine of Web forms and the steps of the rendering process works for ASP.NET and MVC2?

View 2 Replies

Response.Write JSONP Using JQuery And WCF?

Nov 18, 2010

UPDATE:

The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as 'Allowed' or 'Required'.

when i try to access wcf service i get this error: the reason is HttpContext.Current is null, what should i do in this case?

Object reference not set to an instance of an object.

System.Web.Script.Serialization.JavaScriptSerializer s = new System.Web.Script.Serialization.JavaScriptSerializer();
Person p = new Person() { FirstName = "First name", LastName= "last name" };
string json = s.Serialize(p);
System.Web.HttpContext.Current.Response.Write("jsoncallback" + json);} //error

View 2 Replies







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