[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to display Word.doc saved in db via a dialogue box that says Open, Save, Cancel?

Posted on 2010-08-17
6
Medium Priority
?
413 Views
Last Modified: 2012-05-10
We are developing a web app that saves documents (Word, Excel, other) in the database itself.  I need to display the saved files via a dialogue box that says Open, Save, Cancel.   I've found several examples of how to view it via IE itself but I need to launch Word, Excel, etc. to view the files.

Have any idea how to do this?  Can you point me to a resource online to show how to do this?

Thx in advance.

PS:  This needs to be in C#.
0
Comment
Question by:Eric3141
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 33457266
From what I understand you cannot control this.  The user has the ability to determine how their browser should react to certain types of files.  If the user decides they want to have the browser open the file (i.e. view) within the browser - I don't think you can change that option.

The best you can do is provide the correct file types and application types to suggest to the browser what to do with he file, but then user preferences come into play after that...

At least that is what I have seen...
0
 
LVL 3

Expert Comment

by:shubham_gniiit
ID: 33457612
just think it might be done than what if you are opening the file in ms-word and it is not installed on the user computer
So always try to open such files in the browser itself to maintain the robustness of the application
0
 
LVL 2

Author Comment

by:Eric3141
ID: 33463573
shubham:  in our case here at work the customers want the document to open in Word.  If they don't have it installed they'll call our helpdesk and ask for it to be installed.  I understand that for a website made for the general public that might be a problem.  But here at our worksite MicroSoft Office comes loaded.  I can check the file extension of the file to be uploaded and make sure it's only one of the types that we have software loaded to view (.xls, .doc, etc.).
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Accepted Solution

by:
Eric3141 earned 0 total points
ID: 33469338
Guys,

I figured it out.  I've pasted the code below that works.  Note that in this crude example I hard-coded the value of intPictureID.


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.IO;
using System.Text;        

public partial class DisplayWordDoc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
           
            int PictureID = 11;

            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["CaseMgtConnectionString"].ConnectionString))
            {

                const string SQL = "SELECT vchUploadedFileFilename, vbinUploadedFileContent, vchUploadedFileMimeType FROM UploadedFile WHERE intUploadedFileID = @ID";
               
               

                SqlCommand myCommand = new SqlCommand(SQL, myConnection);
                myCommand.Parameters.AddWithValue("@ID", PictureID);

                myConnection.Open();
                SqlDataReader myReader = myCommand.ExecuteReader();

                if (myReader.Read())
                {
                    string filename = myReader["vchUploadedFileFilename"].ToString();


                    Response.ContentType = myReader["vchUploadedFileMimeType"].ToString();
                    Response.BinaryWrite((byte[])myReader["vbinUploadedFileContent"]);

                    //Next 1 line of code makes MS Word launch then open the downloaded document from the database
                    Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename);

                }

                myReader.Close();
                myConnection.Close();
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }

    }



0
 
LVL 35

Expert Comment

by:mrichmon
ID: 33535325
Just so you know that code you posted "suggests" to the browser to save - BUT the user can override that "suggestion"
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 33756851
You emailed asking:
======================================================
On Aug 26, you posted this comment about the solution to the question I asked:

Just so you know that code you posted "suggests" to the browser to save - BUT the user can override that "suggestion"

URL for the question = http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_26409189.html?cid=748#a33535325

I didn't understand what you meant - please explain.  When I run the code I posted I get a dialogue box that has options for "Save, Open, or Cancel".  Were you saying that if I view a Word document this way and hit "Save" that it defaults to a file extension of .doc but the user can change that if he wants to?
======================================================


What it means is that the user can set their browser to automatically open those files - and not even prompt for the save option.  The user can also set the browser to auto-save and not prompt for open.  These user settings override anything you do on the server.

Also yes, the user can change the document extension if they want when they save the document.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question