Open file in browser or application getting the page's name as the file's name

Hi, I'm am trying to get a file to open in either a browser or application depending on the mime type. I'am using the following code in the page load.

protected void Page_Load(object sender, EventArgs e)

{ if (!IsPostBack)   


DocumentInfo document = (DocumentInfo)Session["View_Document"];

StreamFile(document.Document, document.DocumentName, document.FileType.MimeType);




private void StreamFile(byte[] fileData, string originalFileName, string mimeType)





Response.ContentType = mimeType;

Response.AddHeader("Content-Type", mimeType);

Response.AddHeader("Content-Disposition", "inline;filename=" + originalFileName);



catch (Exception)








DocumentInfo class holds the bytes, the mime type and the file name.

If the document is a pdf or image it opens in the browser no problems, but if i go to save the pdf the name of the pdf is the DocumentView.pdf, (The page is called DocumentView.aspx) and not the file name.

If the document is a file which requires an external application to launch, such as an excel file, i get a warning message from excel: 'The file you are trying to open, 'DocumentView.aspx', is in a different format than specified by the file extension........Do you want to open the file now?' on clicking yes excel is opened and the file name is 'DocumentView.aspx', on clicking no excel is still opened and the file name is the correct file name 'filename.xls'.

If i change Response.AddHeader("Content-Disposition", "inline;filename=" + originalFileName); to Response.AddHeader("Content-Disposition", "attachment;filename=" + originalFileName); the file name is correct in the open save dialog, but i dont want this i want to open the file in browser by default.

 How do i get the correct file name to be recognised instead of the page's Name?


1/22/2009 12:32:25 AM 93655 articles. 6 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 28
Get it on Google Play
Get it on Apple App Store

 You running excel 2007?

Seems like it is happening with the office 2007, because of some optimization stuff. There seem to be a registry fix to suppress this message.

Also, with inline file download, I am not sure browser will remember the name of the file it opened

Kumar Reddi
1/22/2009 2:12:36 AM


I am running excel 2007, but even when the pdf is successfully displayed in a browser, going to the save button of the acrobat reader plugin  the name of the file is then name of the page with aspx replaced with pdf. Excel is complaining about opening an aspx file even though the actual file is a xls
1/22/2009 3:08:21 AM

I think these messages are browser specific and varies by browsers and operating systems.

Bind GridView to Dynamically created DataTable | Bind DataTable to DropDownList

My Blog
1/22/2009 11:12:14 AM

Similar Artilces:

How can I get out of my Mozilla's browser the Winamp browser and get back the Google's or Mozilla's browser.
Please I have got to my browser ( I don't know how.) the Winamp browser he behave like virus stick in.But he doesn't has uninstalation section so I can't do anything to get him away from Mozilla's file. I'm not happy of Winamp's behave its like advertisement against a customer's will. Please is there any way to get him away from Mozilla?Please send me exact direction I have tried many ways but he is deeply inside the systeme so when I install new Mozilla he is always here ready to pester me. Thank you for an answer. Richard ...

How to get a page's own file name
I want a user control that can be used to add 'favourites' to the db. ThereforeI need the user control to know what page (the aspx filename) it is currently being used on. Anyone know if this can be done? The containing page of a User control can be got using the Page property, e.g. MyUserControl.Page, or Me.Page. Once you have a reference to the page object, you can get all its properties from there. I have a blog. Perhaps you'd like to read it. Request.URL can help as wel (you can create a System.Uri instance based on this string value in order to extract the filename from the ...

File name only on designer's open file tabs.
When in the VS designer with several files open, the associated file's tab displays the file path and file name in an abreviated format.  ie: App_code/Ec...ncMain.cs Is the a way to remove the file path information and just display the file name?  ie: IncMain.cs Thanks Someone must have pointed this out since VS2005 behaves exactly like you wanted.  I assume you are using the previous version (2003?).  If you're thinking of upgrading, then at least this problem will go away. Well I'm using VS2005 and it displays the file path and file name. When I am u...

How do I get the previous page's file name?
I've found a bunch of strings that return various parts of the previous page's URL (see below).  What I can't seem to find is a string that returns just the file name.  For example, in this URL:  http://localhost:51813/PC_Dev/Posts_Tags.aspx   ...what string would I use to get just the "Posts_Tags.aspx" part?   Here is the stuff that I've found that doesn't give me what I want:  Label1.Text = Request.UrlReferrer.PathAndQuery.ToString() …results in:  Everything to the right of the domain name.   Label1.Text = Req...

How to retrieve the current page's file name from Master Page?
I like to put some code in the Master Page to retrieve the currently displayed page's file name. Is this possible? I want to display different blurb for different page based on their file name and I wanted to do it from the Master Page so I don't have to copy the code and pasted to all of the child pages. I just posted this in another thread. See if this gives you what you want... System.IO.Path.GetFileName(HttpContext.Current.Request.FilePath)Thanks,MaxLet Me Google That For You! I didn't even realize that the other thread that I posted to was also yours...Thanks,MaxLet Me...

How can i get the web file's file type?
I want get the web file's file type because i want to show it by a same aspx page so i must know the Response.ContentType. The web page such as: ...Thanks for your help.Weboy B.Wan---------------------------------------MSN: weboy.wan"at"msn.comE-Mail: weboy.wan"at" huh? Are you iterating through a directory structure and wanting to show some image based on the file type? If so just split on the "." and tak...

Determining a Page's File Name
Can you access the Page's file name programmatically? with the full relative path preferably. Hi,You can use Request.AppRelativeCurrentExecutionFilePath method. Also, on another note, you can use Server.MapPath("~") to get website root (full physical path of the VD).Hope this helps,VivekSocial Networking Platform in ASP.NET || Join now: CodeASP.NET Community Please mark the most helpful reply/replies as "Answer". One correction..Request.AppRelativeCurrentExecutionFilePath  is a property and not a method :-)-VivekSocial Networking Platform in ASP.NET || Join n...

superreview granted: [Bug 361730] Seamonkey _deletes_ mail file if the mail file's size is greater than 2GiB and the .msf file has zero length : [Attachment 246709] biesi's proposal
Scott MacGregor <> has granted David Bienvenu <>'s request for superreview: Bug 361730: Seamonkey _deletes_ mail file if the mail file's size is greater than 2GiB and the .msf file has zero length Attachment 246709: biesi's proposal ...

superreview requested: [Bug 361730] Seamonkey _deletes_ mail file if the mail file's size is greater than 2GiB and the .msf file has zero length : [Attachment 246709] biesi's proposal
David Bienvenu <> has asked Scott MacGregor <> for superreview: Bug 361730: Seamonkey _deletes_ mail file if the mail file's size is greater than 2GiB and the .msf file has zero length Attachment 246709: biesi's proposal ...

Invalid file name for monitoring: ''. File names for monitoring must have absolute paths, and no wildcards
HelloMy web site's index page works when I use IIS, but I dont want to use IIS from some reasons.I use another web server called abyss and it has also support. I configured that and also permissions for the folders but I am having error" Exception Details: System.Web.HttpException: Invalid file name for monitoring: ''. File names for monitoring must have absolute paths, and no wildcards. Thanks Selim  The problem probably lies within the web server.Does it do this you put code in it? Have you tried loading a blank ASPX page?Cheers,   &nbs...

I have the following code that creates a file and stores a string in it when I call the 'getsvrmbox' to recall the string I get an invalid file name on the Reset(fn) the file is present I have done this many times and can't see why I am getting the error I need a fresh look from someone to find the obvious thanks const mboxfile = 'c:\cuplers\adr\e0000-0000-0000-0000'; Procedure tform1.createmboxfile; var fn: textfile; ct: ansistring; begin {create the mboxfile} ct := edit2.Text; assignfile(fn,mboxfile); rewrite(fn); write(fn,ct); ...

How store ultralite10's database file(.udb file) in wince emulator's store card?
i use ultralite10(develop version) in vs2005 with wm5.0 emulator. i find i can't store .udb file in emulatotr store will make a "SQLE_MEMORY_ERROR", why happened this? what should i do so i can may the .udb file in emulator's store card? We haven't had any issues with this. You can post more details about how you attempted to connect or open a tech support case Mike > We haven't had any issues with this. You can post more > details about how you attempted to connect or open a tech > support case > > Mike > > t...

How to get the current file's name in on coding?
i am chinese,i am sorry i know a little english.i want to get the file that is editing currently whose filename.for example to this,a file named "Introduction.aspx",in a future,may be,i will modify the filename to "SimpleIntroduction.aspx",i want to there is a method to return the filename but i will not pay attentions to wether if modifed in the past or in the future.i don't know i say my problem clearly.THX! Hi, You can use the Response.Write(Request.Url.ToString()) to get the current page's URL and from that you can retrieve the filename by using string split me...

how to get page's width and page's height
hi all....... i created a user control function in .ascx file which contain a button, it display a message in <div>, and i include this user control file into many web pages, but the div display's position is vary because the height in each page is different... so how can i get the page's height of the current display page.... thanks use javascript to receive window size, this function will display it with alert: function alertSize() {  var myWidth = 0, myHeight = 0;  if( typeof( window.innerWidth ) == 'number' ) {    //Non-IE    myWidth = ...

Web resources about - Open file in browser or application getting the page's name as the file's name -

Application - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Would you give up chocolate for better application performance?
Application performance is critical to business performance according to 98 percent of businesses, yet 89 percent of executives say the poor ...

Gun Sales, Concealed Permit Applications Surge After San Bernardino
The day after Syed Farook and Tashfeen Malik opened fire in San Bernardino, gun sales and concealed carry permit applications surged.

MBA: Mortgage Applications Increase in Latest MBA Weekly Survey, Purchase Applications up 29% YoY
From the MBA: Mortgage Applications Increase in Latest MBA Weekly Survey Mortgage applications increased 1.2 percent from one week earlier, ...

Falling Costs, Rising Applications Will Boost US Energy Storage Market
... in 2013 to 3,659MWh by 2020 on improving economics and policy developments, predicted GTM Research's Shayle Kann Falling Costs, Rising Applications ...

Mortgage applications down 0.2%
Mortgage interest rates haven't moved much in the past three weeks, but they are holding at a higher level than for all of 2015.

California Film & TV Tax Credits Applications Dip In New Small Screen Round
With production on the uptick in the home of Hollywood , the second round of those seeking small screen Golden State tax credits saw 32 applications ...

Digitimes Research: China touch panel makers increasing investments in niche products and large-size ...
The China International Touchscreen Exhibition (C-Touch) was recently held in Shenzhen, China, featuring a number of local and international ...

Six internet-of-things applications in big new government trial
Manchester, England, is set to be the UK demonstrator city for internet-of-things innovation. Of course, there is much smart technology already ...

New patent application suggests Nintendo’s NX console is like nothing we’ve seen before
Nintendo has been close-mouthed about its plans for the Nintendo NX, but a recent patent filing may have tipped the company's hand. If so, then ...

Resources last updated: 12/12/2015 9:45:21 PM