Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 26th, 2007, 01:51 AM
Registered User
 
Join Date: May 2006
Location: pune, maharashtra, India.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Open A Word Doc... using ASP .net

hi buddies....;)

i want to open a word document through asp.net using VB.net,
if someone has the Code 4 that plz. send me.....

Nikhil
  #2 (permalink)  
Old May 27th, 2007, 01:40 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: Amman, , Jordan.
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mate the following is ur requested code :)
i'm a kind person.. so it also has how to open PDF and XLS.. and I don't know what else (actually i was too lazy to delete them :) anyway it's in C#.. so delete the (";"), define the string with dim, and use only one "/" in the string.. and the code will be perfect :).. and yeah.. remove the "{" "}"
:)
                string strFileName = "C:\\FileName.doc" ;
   // string strFileName = "C:\\temp.doc";
                Response.ClearContent();
                Response.ClearHeaders();
                if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "pdf")
                {
                    Response.ContentType = "application/PDF";
                }
                else
                    if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "doc")
                    {
                        Response.ContentType = "application/msword";
                    }
                    else
                        if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "xls")
                        {
                            Response.ContentType = "application/vnd.ms-excel";
                        }
                        else if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "ppt")
                        {
                            Response.ContentType = "application/vnd.ms-powerpoint";
                        }
                        else if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "txt")
                        {
                            Response.ContentType = "text/plain";
                        }
                Response.WriteFile(strFileName);
                Response.Flush();
                Response.Close();
                Response.Write("<script>window.print();window.clos e()</script>");

Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
  #3 (permalink)  
Old July 31st, 2007, 12:51 AM
Registered User
 
Join Date: Sep 2006
Location: ahmedabad, gujarat, India.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jigu_2811
Default

hi

this code is helpful to me,

but here one problem, this code is run perfectly in IE and also open word document in a IE browser but in MOZILA it is not working perfectly, it will save .aspx page every time and word doc is open in Microsoft Word not in a mozila browser.

Thanks
Jigisha Gajjar

  #4 (permalink)  
Old August 1st, 2007, 07:30 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: Amman, , Jordan.
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Default

man can't understand your problem

Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
  #5 (permalink)  
Old August 1st, 2007, 09:05 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Quote:
quote:Originally posted by jigu_2811
 ...and word doc is open in Microsoft Word not in a mozila browser.

This is simply an issue with windows. Because I.E. is the MS browser, they are able to embed the office applications into the browser. Something like Adobe Reader behaves similarly because the plugin supports many browser types. But MS Office isn't that way. This is a shortcoming of non I.E. browsers you have to live with.

-Peter
  #6 (permalink)  
Old April 19th, 2008, 03:37 PM
Registered User
 
Join Date: Apr 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I also want to open doc and ppt files.I use a similar code.There is not a problem while openning files with msword.But I ppt files can not be opened.Powerpoint is opened but no slides are shown (I have been using office 2007).Here is my code which is written in a rowcommand event of a gridview:

protected void GridView1_RowCommand(Object src, GridViewCommandEventArgs e)
    {

        if (e.CommandName == "openDoc") {

            GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Par ent;

            string filePath = row.Cells[4].Text;

            // Create New instance of FileInfo class to get the properties of the file being downloaded
            FileInfo file = new FileInfo(filePath);

            // Checking if file exists
            if (file.Exists)
            {
                // Clear the content of the response
                Response.ClearContent();

                // LINE1: Add the file name and attachment, which will force the open/cance/save dialog to show, to the header
                Response.AddHeader("Content-Disposition", "filename=" + file.Name);

                // Add the file size into the response header
                Response.AddHeader("Content-Length", file.Length.ToString());

                // Set the ContentType
                Response.ContentType = ReturnExtension(file.Extension.ToLower());

                // Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)

                file.IsReadOnly = true;
                Response.TransmitFile(file.FullName);

                // End the response
                Response.End();
            }
        }

    }

    private string ReturnExtension(string fileExtension)
    {
        switch (fileExtension)
        {
            case ".htm":
            case ".html":
            case ".log":
                return "text/HTML";
            case ".txt":
                return "text/plain";
            case ".doc":
                return "application/ms-word";
            case ".zip":
                return "application/zip";
            case ".pdf":
                return "application/pdf";
            case ".ppt":
                return "application/vnd.ms-powerpoint";
            default:
                return "application/octet-stream";
        }

    }

Thank you for your help.


  #7 (permalink)  
Old May 8th, 2008, 02:21 PM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am using Response.ContentType = "application/msword" in an asp.net application and it works fine with Word 2000 but anyone that has Word 2003 or Word 2007 installed it does not work. I have Word 2000 and 2003 installed on my machine and it works. Anybody know what I can do to make this work?

Brian
bkaralow@aol.com

  #8 (permalink)  
Old March 5th, 2014, 05:45 AM
Registered User
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default RE: How to Open A Word

Hi, well one solution that you can try out is to convert DOC to a HTML file in .NET, and then show the HTML version on the client's browser.
This can work on any browser and regardless of what version of MS Office a client's machine has installed (actually MS Office installation would be unnecessary in this case).
  #9 (permalink)  
Old March 31st, 2015, 04:45 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by zaghmout View Post
mate the following is ur requested code :)
i'm a kind person.. so it also has how to open PDF and XLS.. and I don't know what else (actually i was too lazy to delete them :) anyway it's in C#.. so delete the (";"), define the string with dim, and use only one "/" in the string.. and the code will be perfect :).. and yeah.. remove the "{" "}"
:)
                string strFileName = "C:\\FileName.doc" ;
   // string strFileName = "C:\\temp.doc";
                Response.ClearContent();
                Response.ClearHeaders();
                if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "pdf")
                {
                    Response.ContentType = "application/PDF";
                }
                else
                    if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "doc")
                    {
                        Response.ContentType = "application/msword";
                    }
                    else
                        if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "xls")
                        {
                            Response.ContentType = "application/vnd.ms-excel";
                        }
                        else if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "ppt")
                        {
                            Response.ContentType = "application/vnd.ms-powerpoint";
                        }
                        else if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "txt")
                        {
                            Response.ContentType = "text/plain";
                        }
                Response.WriteFile(strFileName);
                Response.Flush();
                Response.Close();
                Response.Write("<script>window.print();window.clos e()</script>");

Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
Hi, how can I able to display the documents in browser.
The above code only viewing pdf document. Word and Excel documents are gets downloaded.
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open a MS Word doc saved in a database cmw2992 Classic ASP Databases 0 November 26th, 2007 01:22 PM
How to store word doc in sql server using asp.net kv Priya .NET Framework 2.0 2 November 28th, 2006 09:38 AM
Help need to geneate word doc in open office satyakishore Servlets 0 March 16th, 2006 04:14 AM
Creating word doc in ASP.NET ghari ASP.NET 1.0 and 1.1 Basics 1 December 10th, 2005 04:01 AM
How to open a .DOC file with MS-Word ? sherbir Servlets 0 July 26th, 2004 03:39 AM



All times are GMT -4. The time now is 08:30 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.