.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

XmlTextWriter using context.Response.OutputStream just stops outputting

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :ASP.Net


I'm using a ashx file and some database calls to output a list of all pages/images to a gogole sitemap - but my output seems to just stop before ending. I'm flushing on a regular basis so not sure what it coulf be - I'm no stream guru. Rather than using a memory stream or string builder I'm using the HttpCOntect directly - so may be part of it.

Brief outline of code :

context.Response.ContentType = "text/xml";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
xmlWriter = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8);
xmlWriter.Formatting = Formatting.Indented;

xmlWriter.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
xmlWriter.WriteAttributeString("xmlns:image", "http://www.google.com/schemas/sitemap-image/1.1");


//Loop through DataTAble ROws doing something along the lines of :

while (intCount < sectionTable.Rows.Count)

View Complete Post

More Related Resource Links

Writing Bitmap to Response.OutputStream - Generic Error Occured in GDI+



This is what I'm trying to do when I get the error on the server (it works on my local machine):

System.Drawing.Image image = System.Drawing.Image.FromFile(filepath);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image); 

Response.ContentType = "image/bmp";
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);

I don't think it can be a permissions problem because this works on the server:

System.Drawing.Image image = System.Drawing.Image.FromFile(filepath);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image);

Response.ContentType = "image/jpeg";
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

So how do I get this to work for a bitmap?


response.Outputstream problem

I'm trying to get create a page that grabs a file from a directory and streams the binary data to an embedded media player.   When the following code is used on a page that acts as the URL for the embedded media player the player only plays the first 11 seconds and then stops.Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim iStream As System.IO.Stream Dim strFile As String Dim strFolder As String Dim Length As Integer 'strFile = "CFD30HB1404100AD.mpeg" 'strFolder = "C:\wmdownloads" strFile = Request.QueryString("Filename") strFolder = Request.QueryString("Folder") ' Open the file. iStream = New FileStream(strFolder & "\" & strFile, FileMode.Open, FileAccess.Read, FileShare.Read) ' Total bytes to read: Length = iStream.Length Dim Buffer(CInt(Length)) As Byte iStream.Read(Buffer, 0, CInt(Length)) iStream.Close() Response.Clear() Response.ClearHeaders() Response.Charset = "UTF-8" Response.ContentEncoding = System.Text.Encoding.UTF8 Response.ContentType = "video/mpeg" Response.AddHeader("Content-Disposition", "attachment; filename=&

Using response.outputstream.write to stream large file fails in firefox



I have some code to stream files (for security of the files), the code works for all files in IE, and small files in firefox. but If the file is large (eg 750Mb) firefox hangs before it shows the open/save dialog box. 

However if i take out response.clearheaders and the response.flush in the code it does download but all the files downloaded by firefox are corrupt because the file size is too large.   Filenames are guids but I took the "-" out incase that was an issue.

If any one can shed some light on this I would be very grateful.

Function is Below. 


Private Sub StreamFile(ByRef response As HttpResponse, ByVal sFile As String)
            Dim fs As FileStream = Nothing
            Dim sFileName As String = Path.GetFileName(sFile)

            Dim oFile As New FileInfo(sFile)

                fs = New FileStream(sFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)

            Catch ex As Exception

            End Try


            'response.ClearHeaders() 'makes file size wrong in firefox
            response.AddHeader("Content-Length", oFile.Length)
            'To forcefully download, even for Excel, PDF files, reg

Response.TransmitFile stops rest of page execution



i am trying to have a download on my page. I have implemented the code below but code execution stops after the download message pops up, even if i press save or cancel, nothing happens after that.

            Response.AddHeader("Content-Disposition", "attachment; filename=" + lFile.Name);
            Response.AddHeader("Content-Length", lFile.Length.ToString());
            Response.ContentType = "application/octet-stream";

I have tried it a few times without Response.Clear() and Response.End() but it didn't make any difference to take these off. Is there anyway I can achieve this without having to using an IFrame?

Any suggestions will be very much appreciated.

Creating Sites/Lists/List Items under Current User Context in SharePoint By Using SPUserToken

Usually we do this by performing the action under RunWithElevatedPrivileges method and updating the listitem using SPListItem.SystemUpdate() method (see here). but this approach has its own flaws like (RunWithElevatedPrivileges will run under system account, we cannot use SystemUpdate for SPSite,SPWeb,SPList, since it runs under system we will "CreatedBy" by as SystemAccount).

Response.BinaryWrite help needed


Hi all

Im new to .NET and stuck now, so i hope anyone can help my with my problem.

I have a MS SQL database where i have stored some documents as Binary data. I cant figure out how to retrieve them and show/download them in my browser.

I found some guides online and have try to put something together.


private void Write()
 int id = 0;
 string strID = Request.QueryString["id"];
 int.TryParse(strID, out id);

 var db = new ModelDataContext();
 var doc = db.DocumentDatas.Where(x => x.ID == id).FirstOrDefault();

 byte[] byteArray = File.ReadAllBytes(doc);


How do i fill the byteArray with the data?

Thanks in advance :)


Response.Redirect slow


I'm in the middle of migrating servers and on the new server Response.Redirect is extremely slow. It takes around 20 seconds for the browser to get the redirect. This is something that was quick on the existing server. It's an ASP.NET 2.0 application, both servers are running IIS6.

Additionally, if I "manually" do the redirect, it's fast. For example:

Existing way:


takes around 20 seconds on the new server

New way:

Response.Status = "302 Moved Temporarily";
Response.AddHeader("Location", url);

is fast on the new server.

Any ideas why Response.Redirect would be so slow on the new server?

Keyboard shortcuts stops working in WebMatrix


I'm often experiencing that keyboard shortcuts stops working in WebMatrix. This is very annoying as CTRL-S, CTRL-C, CTRL-V, etc. stops working, all of which are heavily used when programming. It's obviously hard to explain how to reproduce this, but I was wondering if someone knows a quick-fix?

Test Run: Web Application HTTP Request-Response Test Automation with JavaScript


Write a simple browser-based request-response test automation using JavaScript that's platform independent and useful when you are working in a highly dynamic environment.

James McCaffrey

MSDN Magazine January 2010

Test Run: Request-Response Testing With F#


This month we show you how to use F# to perform HTTP request-response testing for ASP.NET Web applications.

James McCaffrey

MSDN Magazine July 2009

Test Run: Request/Response Testing with Windows PowerShell


Did you know you can use Windows PowerShell to perform lightweight request/response testing for an ASP.NET Web app? Here's how.

Dr. James McCaffrey

MSDN Magazine May 2008

Talk Back: Voice Response Workflows with Speech Server 2007


Speech Server 2007 lets you create sophisticated voice-response applications with Microsoft .NET Framework and Visual Studio tool integration. Here's how.

Michael Dunn

MSDN Magazine April 2008

Cutting Edge: Context-Sensitive Feedback with AJAX


Beyond progress bars: talking to server-side apps with ASP.NET AJAX.

Dino Esposito

MSDN Magazine July 2007

Foundations: Build a Queued WCF Response Service


With queued calls in Windows Communication Foundation you can perform work in a disconnected manner by sending messages through Microsoft Message Queuing. Juval Lowy explains.

Juval Lowy

MSDN Magazine February 2007

Cutting Edge: Context-Sensitive PictureBox Controls


Great ideas are timeless. A long time ago in Microsoft Systems Journal Paul DiLascia demonstrated a neat trick to display context-sensitive tooltips floating over pictures. As the user moved the mouse over the picture, the tooltip control updated its text to reflect the name of the pointed figure.

Dino Esposito

MSDN Magazine July 2006

Cutting Edge: Adding a Context Menu to ASP.NET Controls


Although the context menu is a common element of most desktop applications, it is still fairly uncommon in Web application names because it doesn't map well to a server-based technology like ASP. NET.

Dino Esposito

MSDN Magazine February 2005

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend