Mac/Safari Opening .doc file from SQL Server Database

Last post 11-27-2007 6:01 AM by Deepesh. 11 replies.

Sort Posts:

  • Mac/Safari Opening .doc file from SQL Server Database

    11-23-2007, 7:34 AM
    • Loading...
    • Deepesh
    • Joined on 07-21-2006, 3:31 AM
    • Posts 111

    Hello,

    We are using ASP.NET and SQL Server 2005 for storing doc/jpeg/gif images in database.

    All thing works fine in IE and FF. But when try to open the doc file on safari browser on any platform it ask as to save the .aspx file.

    How can I open the doc file on safari browser??

    Thanks,
    Deepesh Verma

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
  • Re: Mac/Safari Opening .doc file from SQL Server Database

    11-23-2007, 10:45 AM

    Are you using the correct MIME types for the files. i.e. image/jpeg for JPEGs image/gif for GIFs and application/msword for DOC files in your handler?

  • Re: Mac/Safari -Opening .doc file from SQL Server Database

    11-24-2007, 12:38 AM
    • Loading...
    • Deepesh
    • Joined on 07-21-2006, 3:31 AM
    • Posts 111


    TheDarkKnight:

    Are you using the correct MIME types for the files. i.e. image/jpeg for JPEGs image/gif for GIFs and application/msword for DOC files in your handler?

     

     

     Yes I am using same MIME type.

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
  • Re: Mac/Safari -Opening .doc file from SQL Server Database

    11-24-2007, 2:57 AM
    Answer

    Try changing the mime type of the doc to application/octet-stream. As it is very much likely that Safari may not recognize .doc as a MIME type. It's better to set the MIME header as application/msword in case of IE and set it to application/octet-stream in Firefox & Safari when the file is to be sent to the browser by the handler.

  • Re: Mac/Safari -Opening .doc file from SQL Server Database

    11-24-2007, 4:14 AM
    • Loading...
    • Deepesh
    • Joined on 07-21-2006, 3:31 AM
    • Posts 111

    Not working, For you reference the code I am using is below, this might help you to find the problem.

    Thanks in advance.

     

      protected void LinkButton1_Click(object sender, EventArgs e)
        {

            string str = "SELECT [ID] ,[FileName] ,[Extension] ,[Content] FROM [TestDB].[dbo].[TestTable] where ID = (Select Max(ID) from TestTable ) ";
            using (SqlConnection cnn = new SqlConnection("Data Source=earth;Initial Catalog=TestDB;Persist Security Info=True;User ID=sa;Password=sa"))
            {

                cnn.Open();
                SqlCommand cmd = new SqlCommand(str, cnn);
                cmd.CommandType = CommandType.Text;

                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    dr.Read();
                    string strExtenstion = dr[2].ToString();
                    byte[] bytFile = (byte[])dr[3];

                    Response.Clear();
                    Response.Buffer = true;

                    if (strExtenstion == ".doc" || strExtenstion == ".docx")
                    {
                       // Response.ContentType = "application/msword";
                        Response.ContentType = "application/octet-stream";

                        //Response.AddHeader("Content-Disposition", "inline; filename=report.aspx.doc");
                        Response.AddHeader("content-disposition", "inline;filename=tr.doc");
                    }
                    else if (strExtenstion == ".xls" || strExtenstion == ".xlsx")
                    {
                        Response.ContentType = "application/vnd.ms-excel";
                        Response.AddHeader("content-disposition", "attachment;filename=Tr.xls");
                    }
                    else if (strExtenstion == ".pdf")
                    {
                        Response.ContentType = "application/pdf";

                        Response.AddHeader("content-disposition", "attachment;filename=Tr.pdf");
                    }

                    Response.Charset = "";
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);

                    // If you write,
                    // Response.Write(bytFile1);
                    // then you will get only 13 byte in bytFile.
                    Response.BinaryWrite(bytFile);

                    Response.End();
                }
            }
          
        }

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
  • Re: Mac/Safari -Opening .doc file from SQL Server Database

    11-24-2007, 7:57 AM

    I implemented your logic on a simple page and tested on Safari 3.4 beta on Windows. And it works here ... Are you facing problems with Safari on Mac?

  • Re: Mac/Safari -Opening .doc file from SQL Server Database

    11-24-2007, 8:09 AM
    • Loading...
    • Deepesh
    • Joined on 07-21-2006, 3:31 AM
    • Posts 111

     Thanks a lot for the confirmation,

    But we are facing problem on Safari 3.0.3 on windows XP and we are using a third party tool www.browsercam.com for testing it on MAC, and there also is saving the file as .aspx.
    As it is working at your end, I think it may be some plug-in issues or some thing else.

    What do you suggest??

    Thanks one again 

     

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
  • Re: Mac/Safari -Opening .doc file from SQL Server Database

    11-25-2007, 5:02 AM

    I can confirm if there is indeed a problem with Safari on Mac in the next 24 hours. I do not have access to a Mac @ home.

  • Re: Mac/Safari -Opening .doc file from SQL Server Database

    11-25-2007, 5:27 AM
    • Loading...
    • Deepesh
    • Joined on 07-21-2006, 3:31 AM
    • Posts 111

    Thanks, no issues. 

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
  • Re: Mac/Safari -Opening .doc file from SQL Server Database

    11-27-2007, 3:25 AM
    • Loading...
    • Deepesh
    • Joined on 07-21-2006, 3:31 AM
    • Posts 111
    TheDarkKnight:

    I can confirm if there is indeed a problem with Safari on Mac in the next 24 hours. I do not have access to a Mac @ home.

    Hello,

    Did you get the time to check the code with safari on Mac. Waiting for reply.

    Thanks, 

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
  • Re: Mac/Safari -Opening .doc file from SQL Server Database

    11-27-2007, 5:51 AM

    Yes, I've tested the code right now on a mac with OS X 10.4. It works without any problems.

  • Re: Mac/Safari -Opening .doc file from SQL Server Database

    11-27-2007, 6:01 AM
    • Loading...
    • Deepesh
    • Joined on 07-21-2006, 3:31 AM
    • Posts 111

     Thanks a lot!!!

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
Page 1 of 1 (12 items)