Reputation: 1663
I have web app that lists files stored inside it.
Each item has a hyperlink that, when clicked, forces the Open/Save dialog to appear.
Now, if I click on a link pointing to, say, a Word document and select 'Open' it opens in it's own window, as you would expect. However, if the file is an HTML file and I select the 'Open' option it opens to page in the browser [correct] but it opens in the window I used to select the document [bad].
So, to the question: Is it possible to force the 'Open' option of the Open/Save dialog to open a document in a new window?
Edit: The hyperlink that forces the document to be opened is not just a pointer to the file (for a number of reasons). The .NavigateUrl property contains a call to a JavaScript function, This function makes an Ajax request to the app proper, which fetches the document from secure storage and presents it to the user's browser as an attachment (Content-Disposition: attachment)
Further Edit: The JavaScript function simply makes an Ajax call back in to the page. The result of this action is to cause a page to be displayed in an IFrame. This page write directly to the Response Object as follows:
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", FileName));
Response.AddHeader("Content-Length", String.Format("{0}", length));
Response.Flush();
Response.Close();
I suppose, if it is possible to change the action of the 'Open' button in the resulting Open/Save dialog, it's going to be something I do in this code that will force it.
If it makes a difference, this is a .Net v4.0 app written in C#.
I know about the good and bad of opening new windows, but this is a private app and it's what the client wants.
Upvotes: 4
Views: 1989
Reputation: 3999
Instead of having each of the links point to a JS function within the base page try doing this...
Have each link point to a URL (e.g. /GetFileContent.aspx?fileid=123) and have that page perform the necessary logic before loading the file. Keep your ContextType and response header code as it is.
Each link would open a new window and look something like this:
<a href="/GetFileContent.aspx?file=123" target="_blank">filename.doc</a>
Upvotes: 5