Advertisement

03.09.2008 at 02:42PM PDT, ID: 23227101
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

open a doc in a new browser window

Tags: c#, asp.net 2.x, visual studio 2008 pro, sql 2005 server, iis 6.0
attached is the script I use to open respective document.

this replaces the current .aspx file and opens the doc.

would like to open the doc in a different browser window (or tab) -- initiated via server-side scripting.

how is achieved please?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
private void ViewDocument(string viewingFileNameExt)
        {
            switch (viewingFileNameExt)
            {
                case ".pdf": Response.ContentType = "Application/pdf";
                    break;
                case ".txt": Response.ContentType = "text/plain";
                    break;
                case ".jpg": Response.ContentType = "image/JPEG";
                    break;
                case ".gif": Response.ContentType = "image/GIF";
                    break;
                case ".doc": Response.ContentType = "Application/msword";
                    break;
                case ".xls": Response.ContentType = "Application/x-msexcel";
                    break;
                case ".ppt": Response.ContentType = "application/vnd.ms-powerpoint";
                    break;
                case ".pps": Response.ContentType = "application/vnd.ms-powerpoint";
                    break;
                case ".pptm": Response.ContentType = "application/vnd.ms-powerpoint.presentation.macroEnabled.12";
                    break;
                case ".pptx": Response.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
                    break;
                case ".xlsm": Response.ContentType = "application/vnd.ms-excel.sheet.macroEnabled.12";
                    break;
                case ".xlsx": Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    break;
                case ".docm": Response.ContentType = "application/vnd.ms-word.document.macroEnabled.12";
                    break;
                case ".docx": Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                    break;
            }
 
            Response.WriteFile(hostedSubFolderLocation + "\\" + hostedFileName);
            Response.End();
        }
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: amillyard
Solution Provided By: GreenGhost
Participating Experts: 1
Solution Grade: A
Views: 468
Translate:
Loading Advertisement...
03.09.2008 at 02:58PM PDT, ID: 21082879

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.09.2008 at 03:43PM PDT, ID: 21083019

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.09.2008 at 04:03PM PDT, ID: 21083068

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.10.2008 at 03:00AM PDT, ID: 21085056

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.12.2008 at 01:22AM PDT, ID: 21103878

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.12.2008 at 02:35AM PDT, ID: 21104159

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.12.2008 at 03:12PM PDT, ID: 21111338

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.12.2008 at 04:01PM PDT, ID: 21111692

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.09.2008 at 02:58PM PDT, ID: 21082879

Rank: Master

That is not possible. When the server code starts, it has already been determined where the page will open. Once the request has been sent, it's too late to change where the response will go.

You have two alternatives:

1. Open the page in a new window instead of doing a postback. This has to be done in the browser before the page is requested.

2. Return a page that contains a Javascript that opens the document in a new window. You can use the Page.ClientScript.RegisterStartupScript to add Javascript code to the page.
 
03.09.2008 at 03:43PM PDT, ID: 21083019
GreenGhost: ok, filename is picked from a datagrid row -- so that button press initiates the db call to collect the filename / location details -- when then calls the above procedure to display the document.

just confirming -- does that mean option 2 is more suited?
 
03.09.2008 at 04:03PM PDT, ID: 21083068
when I try the attached I am getting the current web-page and document merged into the same web-page (same browser window)
1:
Page.ClientScript.RegisterStartupScript(GetType(), "test", "window.open('" + hostedSubFolderLocation + "','Height=300px,Width=700px,menubar=No,toolbar=no,scrollbars=yes');");
Open in New Window
 
03.10.2008 at 03:00AM PDT, ID: 21085056

Rank: Master

You forgot the target parameter in the window.open call. Also the width and height of the window should not have the css unit "px".

Page.ClientScript.RegisterStartupScript(GetType(), "test", "window.open('" + hostedSubFolderLocation + "','_blank','Height=300,Width=700,menubar=No,toolbar=no,scrollbars=yes');");

Have you removed the Response.WriteFile call?
 
03.12.2008 at 01:22AM PDT, ID: 21103878
"Have you removed the Response.WriteFile call?"   do I need to remove this scripting?  if so, how would I then display the document?  (or is the naem of the file added to end of hostedSubFolderLocation ?
 
03.12.2008 at 02:35AM PDT, ID: 21104159

Rank: Master

> do I need to remove this scripting?

Yes.

> if so, how would I then display the document?

It's displayed in the new window that is opened by the Javascript.

> or is the naem of the file added to end of hostedSubFolderLocation ?

What you should use in the javascript, is the virtual path to the file, i.e. the same that you would use in a link.

If the document is in the same folder as the page, it's simpy hostedFileName:

Page.ClientScript.RegisterStartupScript(GetType(), "test", "window.open('" + hostedFileName + "','_blank','Height=300,Width=700,menubar=No,toolbar=no,scrollbars=yes');");
Accepted Solution
 
03.12.2008 at 03:12PM PDT, ID: 21111338
GreenGhost:  have made the adjustments as attached.

but 1. no new browser opens, and 2. the document and web-page are merged together (in the same browser window)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
        private void ViewDocument(string viewingFileNameExt)
        {
            switch (viewingFileNameExt)
            {
                case ".pdf": Response.ContentType = "Application/pdf";
                    break;
                case ".txt": Response.ContentType = "text/plain";
                    break;
                case ".jpg": Response.ContentType = "image/JPEG";
                    break;
                case ".gif": Response.ContentType = "image/GIF";
                    break;
                case ".doc": Response.ContentType = "Application/msword";
                    break;
                case ".xls": Response.ContentType = "Application/x-msexcel";
                    break;
                case ".ppt": Response.ContentType = "application/vnd.ms-powerpoint";
                    break;
                case ".pps": Response.ContentType = "application/vnd.ms-powerpoint";
                    break;
                case ".pptm": Response.ContentType = "application/vnd.ms-powerpoint.presentation.macroEnabled.12";
                    break;
                case ".pptx": Response.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
                    break;
                case ".xlsm": Response.ContentType = "application/vnd.ms-excel.sheet.macroEnabled.12";
                    break;
                case ".xlsx": Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    break;
                case ".docm": Response.ContentType = "application/vnd.ms-word.document.macroEnabled.12";
                    break;
                case ".docx": Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                    break;
                case ".tif": Response.ContentType = "image/tiff";
                    break;
                case ".tiff": Response.ContentType = "image/tiff";
                    break;
            }
 
            Page.ClientScript.RegisterStartupScript(GetType(), "test", "window.open('" + hostedSubFolderLocation + "\\" + hostedFileName + "','_blank','Height=400,Width=700,menubar=No,toolbar=no,scrollbars=yes');");
 
            //Response.WriteFile(hostedSubFolderLocation + "\\" + hostedFileName);
            //Response.End();
        }
Open in New Window
 
03.12.2008 at 04:01PM PDT, ID: 21111692

Rank: Master

Also comment out the code that sets the content type. As the document is not returned in the response, you should not change the content type of the response.

The url that you use in the window.open method is a virtual path, so it uses slash (/) as separator, not backslash (\).

You have to add another parameter in the RegisterStartupScript call. You need to send the value true for the addScriptTags parameter, so that a script tag is added around the Javascript code.
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628