C# - Response.AddHeader("Content-Disposition") Not Opening File In IE6?

Oct 8, 2010

I'm using Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.HtmlEncode(FileName)); to pop a 'open/save file' dialog for the users, so that they can download an file on to their local machines.

This is working good normally in IE7,But on IE6 the file is not opening when user click on the open button in 'open/save file' dialog. I gone through the net and found that Response.AddHeader("Content-Disposition", "inline; filename="+Server.HtmlEncode(FileName)); should be provide to work that in IE6,and its works fine..

But the issue is most of the files that can open in browser opens on the page itself.. ie user on a mail page and click download an image file it opens there,, i need it to open in another window as in case of IE7 what can i do... other files that cannot open in bowser open with current application in system ie(word,excel etc)..

The Code i used is here....

Response.AddHeader("Content-Disposition", "attachment; filename=" +FileName);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = ReturnExtension(file.Extension.ToLower());
Response.TransmitFile(file.FullName);
Response.End();
private string ReturnExtension(string fileExtension)
{
switch (fileExtension)
{
case ".txt":
return "text/plain";
case ".doc":
return "application/ms-word";
case ".xls":
return "application/vnd.ms-excel";
case ".gif":
return "image/gif";
case ".jpg":
case "jpeg":
return "image/jpeg";
case ".bmp":
return "image/bmp";
case ".wav":
return "audio/wav";
case ".ppt":
return "application/mspowerpoint";
case ".dwg":
return "image/vnd.dwg";
default:
return "application/octet-stream";
}
}

View 2 Replies


Similar Messages:

C# - Response.AddHeader In An Ascx File?

Apr 1, 2011

Is it possible to use the Response.AddHeader particularly Im trying to use the "Refresh" of it. I need it to pause before it redirects but the place where the code is being ran is in a ASCX in the codebehind. It does nothing when I have the following in my Codebehind:

HttpContext.Current.Response.AddHeader("Refresh", "6;URL=Default.aspx");

Any way I can redirect a user in the codebehind on a ascx page?

View 2 Replies

Docx File Doesn't Open In Browser With Content Disposition Inline In IE 8

Jul 2, 2010

I want to open docx file in IE from asp.net. The IIS has mime type correctly mapped. I can open pdf fine but docx will always prompt me to download like content-disposition='attachment'. Is there any setting to be done?

[code].....

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

C# - Error With Content-disposition?

May 17, 2010

how should I handle an exception that occurs after sending a Content-Disposition header for an attachment? I'm trying to generate a report at server and send it as a file, but if an exception occurs during the report generation, the error message itself is sent to browser which still takes it as a content of a file and shows a Save As dialog. User cannot know there was an error generating report, saves the file which is in wrong format now.Is there a way to cancel the response with this header and redirect to an error page? Or what else can I do to inform user about the error?

Probably I could generate the report first and only if there was no error send the headers, but I want the report render directly to the Response output stream so that it does not need to stay in memory.

Here is my code:

this.Response.ContentType = "application/octet-stream";
this.Response.AddHeader("Content-Disposition", @"attachment; filename=""" + item.Name + @"""");
this.Response.Flush();
GenerateReportTo(this.Response.OutputStream); // Exception occurs

View 1 Replies

Web Forms :: Not Posting Back After Response.AddHeader

Jan 1, 2011

I used the following code for the form download

[Code]....

But form is not posting back on execution of the above statement. What should I do , so that form postback also occurs after this statement.

View 3 Replies

Web Forms :: Form Not Submitting After Response.AddHeader?

Dec 29, 2010

I am using the following code to download the file from web server

[Code]....

View 7 Replies

Web Forms :: Response.AddHeader Not Working In Safari?

Nov 20, 2010

my website www.findmyhomefromhome.com after a sucessful entry i redirect the users to their previous uploads which is the manageaccomm page. The code behind that does this is Response.AddHeader("REFRESH", "3;URL=manageaccomm.aspx");

This works in firefox but not in safari. In safari it goes to the following [url]

and the message "resource could not be found Requested URL: /manageaccomm.aspx, 3;URL=manageaccomm.aspx".

I'd like to fix this but keep it working on other browsers .

View 4 Replies

Error In Opening Word File Using Response.transmitfile?

Aug 27, 2010

I'm using asp.net 2.0 (VS2005) on a windows 2008 server.

i'm using MS Office 2007

when open word docuemnt from server using the following code -

Response.ContentType = "application/ms-word";
Response.AppendHeader("Content-Disposition", "attachment; filename= " + strDocName);
Response.TransmitFile(Server.MapPath(Defpath1));
Response.End();

it works fine when i run it in debug mode, but gives the following error when running through IIS Problems during Load Problems came up in the following areas during loadMissing file:
QTnicFLJ5JKZN8dyEzUEsK2jPtygbkw....

View 1 Replies

MVC :: Providing File Content As A URL Response?

Jun 25, 2010

I hope this is a ridiculously simple problem. In my ASP.NET MVC web application, I have several places where the appropriate response to the {whatever}/Detail/{#} URL is the binary content of a file that lives outside of the installed application, with an appropriate ContentType in the header.I don't_ want to expose the directory containing the files or its contents as files to the web. That would make it possible to browse other files by educated guessing and would require special work to interact well with the authorization mechanism.I _do_ want HTTP response to contain the content stream of the file corresponding to the supplied ID, so that it will result in the usual open or save-to-file stuff in the browser. The client should have no clue as to where the content originates I can imagine a solution where I write code in my controller to open streams and feed the output to the response, taking the HttpResponse by the throat and forcing it to skip the master page and forcing the content type. I'm already doing something similar
to dump some log content into a support page.However, ASP.NET MVC is a strong framework and this has got to be a pretty common situation. Is there a kinder, gentler way to do this already provided by the platform, either through routing or in my controller? At first blush, I didn't see an ActionResult for this. I do see that returning something other than an ActionResult will cause the object supplied to be rendered as content, which sounds like what I want. However, what sort of object should I return to do this for a whole file, perhaps a relatively large.

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

VS 2005 - Opening Word In The Background (Response)

Aug 17, 2010

My web application is opening up a word document using Response -

Code:
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + CreateObjectiveDocumentName(strLetter) + ".doc");
Response.ContentType = "application/vnd.ms-word";
Response.Charset = "";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.WriteFile(strFinalDocName);

Which works fine.

However, is there anyway to open the word document in the background?

View 11 Replies

Web Forms :: Opening A Protected PDF With Page.Response?

Apr 6, 2010

I am trying to open a PDF file that is protected. Is there a way using Response.AddHeader to define the password without having to prompt the user? Adobe automatically prompts the user to enter in the password. I do not want this to occur.

The following is how the pdf file is served to the user:

[Code]....

The file is protected as it may contain private information and we do not want to the user to freely download the file using Adobe reader without having the pdf protected. Is there a way to pass the password to the browser without prompting the user (through Adobe)?

View 3 Replies

Web Forms :: Opening Response.write In A New Window?

Dec 22, 2010

i am posting some data from my application to an external website i.e for a credit card payment

so i am using a response.write object.how to display the reposnse.write in a new window

this is my code

Dim sb As New StringBuilder()
sb.AppendFormat("runat=server")
sb.Append("<html>")
sb.AppendFormat("<body onload='document.forms[""form""].submit()'>")
sb.AppendFormat("<form name='form' action='{0}' method='post'>", postbackUrl)

[Code]....

View 6 Replies

Print Div Content From User Control Without Opening A New Window?

Feb 2, 2010

I have a USER CONTROL with a <div> tag and a button. I want to print the content of the <div> when the button is clicked. Only the content of the div and nothing else no matter where the control is used. This without opening a new window.

View 3 Replies

Security :: Opening Public Content In Private Site

Feb 10, 2010

My site is 100% private (only public facing page is login) I've had the need to open up a page to anon via the <location> node in the web config...and that all seems to work However the issue now appears to be that dynamic resources such as the Telerik.Web.UI.WebResource.axd and imagesjavascript changed via handlers dont load. A firebug of the situation shows that for those dynamic elements, it's trying to re-direct to login to get them Is there anyway around this?

View 3 Replies

WCF / ASMX :: Content Type Text / Html Of The Response Message Does Not Match The Content Type Of The Binding

May 7, 2010

I'm getting this message when going to a web app that accesses my service.

"The content type text/html of the response message does not match the content type of the binding (text/xml; charset=utf-8)..."

The thing is, it happens once in a while even when no changes have been made to the service or the web app. And I can make it go away most of the time by going directly to the .svc?wsdl page in my browser and then coming back to the web app.

View 2 Replies

C# - Templated Control - Content Is Not Allowed Between The Opening And Closing Tags?

Sep 9, 2010

I'm trying to run the templated user control example provided by MSDN. Code is as follows:

So according to MSDN this should implement as follows:

[code]...

Designer complains that content is not allowed between the opening and closing tags of TemplatedFirstControl and that FirstTemplate is not supported. So what's missing? I duplicated MSDN's code verbatim

MSDN Article: [URL]

View 1 Replies

Web Forms :: Downloading A File - File Name Is Shown Incorrectly On Opening

Apr 21, 2010

we are working on a file download page. We want to download a file with a name with spaces and accents. Although the filename is shown correctly on the filedownload dialog, when we click open, the file name is shown with %e1%ba%a3n%20... on notepad. ('Save as' shows the correct name) This problem only happens in Internet Explorer.

Is there anyway we can Display the file name correctly (on the target application) after opening it (without saving) from file download dialog ?

We use this code to set the filename :

fileName = Server.UrlPathEncode(fileName);
Response.AppendHeader("Content-Disposition", "attachment; filename="" + fileName + """);

View 6 Replies

C# - Content Inside Zip File / Use Zippackage Class To Know About The Content In .zip File?

May 14, 2010

how to use zippackage class to know about the content in .zip file?for ex to know the type of file inside this zip file.

View 1 Replies

Web Forms :: Opening CSV File In Browser Without Any File Dialog

May 21, 2010

I want to open a CSV file in the client browser "WITHOUT" a save/open file dialoge. I am able to do it with file dialoge but unfortunately I need to do it without it.

View 4 Replies

Response.Content Open In New Window?

Sep 15, 2010

I have a button that when clicked on it will open a pdf file in the current window. Can someone help me modify my code to open in a new window? Here's what I have so far that works when the button is clicked:

[Code]....

View 3 Replies

How To Apply The Response.redirect Command To Have The Content

Jun 9, 2010

How do I apply the response.redirect command to have the content of what I a url that I fetch displayed in my web app. I fetch the url and since vb.net is not recognizing response.redirect I am a little stumped. I have a textarea where I display the responsestream which works but I would like it displayed the same way it displays in a browser. The pages source has a lot of javascript functions so I am not sure if this is even relevant.

View 1 Replies

Setting Content - Type Of Empty Response In MVC

Dec 27, 2010

In order to support a legacy application that's in the field, I need my ASP.NET MVC app to return an empty response that also has a Content-Type. One of IIS, ASP.NET, or ASP.NET MVC is removing my Content-Type when I send back a null response. Is there any way around this? (While not requiring an empty response with a set Content-Type would obviously be the ideal solution, the clients are already out there, and many of them cannot be upgraded.)

EDIT: Since there was a request for code: I'm proxying the request from the new web application to the one that older clients rely on. To do this, I have a subclass of ActionResult, called LegacyResult, that you can simply return for those methods that need to be handled by the old software. This is the relevant part of its code:

public override void ExecuteResult(ControllerContext context)
{
using (var legacyResponse = GetLegacyResponse(context))
{
var clientResponse = context.HttpContext.Response;
clientResponse.Buffer = false;
clientResponse.ContentType = legacyResponse.ContentType; /* Yes, I checked that legacyResponse.ContentType is never string.IsNullOrEmpty */
if (legacyResponse.ContentLength >= 0) clientResponse.AddHeader("Content-Length", legacyResponse.ContentLength.ToString());
var legacyInput = legacyResponse.GetResponseStream();
using (var clientOutput = clientResponse.OutputStream)
{
var rgb = new byte[32768];
cb;
while ((cb = legacyInput.Read(rgb, 0, rgb.Length)) > 0)
{
clientOutput.Write(rgb, 0, cb);
}
clientOutput.Flush();
}
}
}

If legacyInput has data, then Content-Type is set appropriately. Otherwise, it's not. I can actually kluge the old backend to send an empty v. non-empty response for exactly the same request, and observe the difference in Fiddler.

EDIT 2: Poking around with Reflector reveals that, if headers have not been written at the time that HttpResponse.Flush is called, then Flush writes out the headers itself. The problem is that it only writes out a tiny subset of the headers. One of the missing ones is Content-Type. So it seems that, if I can force headers out to the stream, I can avoid this problem.

View 1 Replies

How To Configure IIS To Serve 404 Response With Custom Content

Mar 31, 2010

I would like to serve a custom 404 page from ASP.NET MVC. I have the route handler and all the infrastructure set up to ensure that nonexistent routes are handled by a single action:

public ActionResult Handle404()
{
Response.StatusCode = 404;
return View("NotFound");
}

Problem: IIS serves back its own content (some predefined message) when I set Response.StatusCode to 404 before returning the content.

On the VS development web server, this works as intended - the status code of the HTTP response is 404 while my content (the NotFound view) is served.

I believe that when the IIS processing pipeline sees that the application returns 404, it simply replaces the whole response with its own.

What setting in IIS affects this behavior?

I do not have access to the IIS installation so I can not investigate this - however, I can ask the hosting provider to tweak the configuration for me if I know what exactly needs to be changed.

View 1 Replies







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