Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
HI , i had developed an application using asp.net with c# to display the files in gridview with linkbuttons.so when we click on that link file will open.
 
i can open the file using IE but problem is with Google Chrome it is directly opening not asking with download prompt message like open , save, cancel.
 
i want to open file not to save .how can i do it in google chrome. i am trying since two days but no result.please help.
 
my code is as follows:
 
in .aspx file
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
 
    <link href="css/css.css" rel="stylesheet" type="text/css" />
  <link type="text/css" rel="stylesheet" href="css/main-style.css" />
    <style type="text/css">
        #iframe1
        {
            height: 422px;
            width: 769px;
        }
    </style>
    <meta name="DownloadOptions" content="nosave"  content-Disposition="attachment"/>
</head>
<body>
    <form id="form1" runat="server" method="get" >
    <div class="blue-bar" style="width:320px"><p align="left">Name of the Presentation</p></div>
    <div style="width:320px;height:400px;">
     <asp:DataGrid Style="margin-bottom: 10px; border-color: White;background-color:#F0F8FF" ID="pnlDC_dgrdRevenueOthers"
    OnItemDataBound="pnlDC_dgrdRevenueOthers_ItemDataBound" CellPadding="0"  CellSpacing="0" AllowSorting="false"
    AutoGenerateColumns="False" ShowHeader="false" ShowFooter="false" DataKeyField="pre_id"
    Visible="true" Width="320px" Height="300px" runat="server" CausesValidation="false"  OnPageIndexChanged = "pnlDC_dgrd_PageIndexChanged"
    GridLines="Horizontal"  AllowPaging="true" PageSize="5" >
     <Columns>
            <asp:TemplateColumn  HeaderText=""  ItemStyle-Width="30%" >
            <ItemTemplate>
                <div style="float:left;vertical-align:middle;">
                <asp:Label ID="pnldrg_lbcomments" Width="150px"
                Text='<%# Convert.ToString(DataBinder.Eval(Container.DataItem, "pre_desc")) %>'
                runat="server" CausesValidation="false"  />
                </div>
            </ItemTemplate>
            </asp:TemplateColumn>
            <asp:TemplateColumn>
            <ItemTemplate>
                    <div style="float:left;vertical-align:middle;">
                     <asp:LinkButton ID="lnk_user_name" align="left" Width="100px"    runat="server" CausesValidation="false" ForeColor="#04a7ee" Font-Bold="true" style="font-size:13px;"
                    OnCommand="pnl_lname_Command"  CommandArgument='<%# Convert.ToString(DataBinder.Eval(Container.DataItem, "pre_filename")) %>'
                    Text='<%# Convert.ToString(DataBinder.Eval(Container.DataItem, "pre_filename")) %>' />
                    </div>
            </ItemTemplate>
            </asp:TemplateColumn>
    </Columns>
</asp:DataGrid>
 

</div>
</form>
</body>
</html>
 
in .cs file
protected void Page_Load(object sender, EventArgs e)
  {
      if (!IsPostBack)
      {
 
          string path = "Presentations/";
          string fileName = "";
 
          binduserdata(Convert.ToString(Session[FbConstUtil.USER_ID]), CurrentPageIndex);
 
          if (Directory.Exists(Server.MapPath(path)))
          {
              if (System.IO.Directory.Exists(Server.MapPath("Presentations")))
              {
              }
          }
      }
  }
 
  public void Open_File(string extension, string fileName)
    {
        switch (extension)
        {
            case ".pptx":
                Response.ContentType = "Application/powerpoint";
                Response.AppendHeader("Content-Disposition", "attachment; filename='" + fileName);
                Response.TransmitFile(Server.MapPath(fileName));
                Response.End();
                break;
            case ".ppt":
                Response.ContentType = "Application/powerpoint";
                Response.AppendHeader("Content-Disposition", "attachment; filename='" + fileName);
                Response.TransmitFile(Server.MapPath(fileName));
                Response.End();
                break;
            case ".ppsx":
                
                Response.ContentType = "Application/ms-powerpoint";
                Response.AppendHeader("Content-Disposition", "attachment; filename='" + fileName);
                Response.TransmitFile(Server.MapPath(fileName));
                Response.End();
                break;
            case ".pdf":
 
                Response.ContentType = "Application/pdf";
                Response.AppendHeader("Content-Disposition", "attachment; filename='" + fileName);
                Response.TransmitFile(Server.MapPath(fileName));
                Response.End();
                break;
            default:
                break;
        }
    }
 
    protected void pnlDC_dgrdRevenueOthers_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        ListItemType itemType = (ListItemType)e.Item.ItemType;
        if (itemType == ListItemType.Item || itemType == ListItemType.AlternatingItem)
        {
        }
    }
    private void binduserdata(string Userid, int pageIndex)
    {
        DataTable ldtbParentTable = new DataTable();
        DataTable ldtbChildTable = new DataTable();
        DataSet ds = new DataSet();
        DataView dv = new DataView();
        //DataTable dt = SnRevenueBao.GetRevenueDetails(pnlCC_ddlYear.SelectedItem.Text, pnlCC_ddlMonth.SelectedItem.Value);
        ds = GetRevenueDetails();
        int rowscount = ds.Tables[0].Rows.Count;
  
        /* if you not set 3rd parameter to false it will raise below exception*/
        /*This constraint cannot be enabled as not all values have corresponding parent values*/
      //  ds.Relations.Add("ClientRelation", ds.Tables[0].Columns[0], ds.Tables[1].Columns[2], false);
        pnlDC_dgrdRevenueOthers.CurrentPageIndex = pageIndex;
        pnlDC_dgrdRevenueOthers.DataSource = ds;
        pnlDC_dgrdRevenueOthers.DataBind();
        // txtPost.Text = "";
    }
    private DataSet GetRevenueDetails()
    {
        DataSet ds = new DataSet();
        SqlConnection sqlConn = new SqlConnection();
        sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings["JournalConnectionString"].ConnectionString;
        SqlCommand objCommand = new SqlCommand("snproc_get_Presentations", sqlConn);
        SqlDataAdapter DataAdapter = new SqlDataAdapter(objCommand);
        objCommand.CommandType = CommandType.StoredProcedure;
        DataAdapter.Fill(ds, "posts");
 
        return ds;
    }
 
    protected void pnlDC_dgrd_PageIndexChanged(Object sender, DataGridPageChangedEventArgs e)
    {
 
        CurrentPageIndex = e.NewPageIndex;
        binduserdata(Convert.ToString(Session[FbConstUtil.USER_ID]), CurrentPageIndex);
    }
 
    protected void pnl_lname_Command(object sender, CommandEventArgs e)
    {
        //string selecteduser_name = (String)e.CommandArgument;
        //string selectUser_id = GetUserId(selecteduser_name);
        //Response.Redirect("Monthly_Goals.aspx?UserID=" + selectUser_id + "&UserName=" + selecteduser_name + "&selected_user=selecteduser" + "&LoginUser=" + Session[SnConstUtil.USER_NAME].ToString() + "&LoginUserId=" + Session[SnConstUtil.USER_ID].ToString());
        
        string f_Name = (String)e.CommandArgument;
       // String f_Name = (String)e.CommandName;
        //int post_id = GetpostId(Commentid);
        f_Name = "presentations/" + f_Name;
        string extension;
       
        try
        {
            
            //String FilePath = Server.MapPath("Business Goals/" + "/Monthly" + "/" + Session["UserId"].ToString() + "/" + post_id + "/" + f_Name);
            extension = Path.GetExtension(f_Name);
            String FilePath = Server.MapPath(f_Name);
       
         
           // File.SetAttributes(FilePath,  FileAttributes.Hidden);
            System.Diagnostics.Process.Start(FilePath);
 

            //Open_File(extension, f_Name);
           // string kk = DownloadableProduct_Tracking(f_Name);
        }
        catch (FileNotFoundException ex)
        {
            throw (ex);
        }
    }
 
please someone answer for this problem.
Posted 11-Feb-13 13:16pm
srinvas685
Edited 11-Feb-13 18:04pm
v2
Comments
Karthik Harve at 11-Feb-13 23:05pm
   
[Edit] modified pre tags

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

PowerPoint?! Who told you that Chrome should open such documents? This is a proprietary thing. Therefore, standard behavior is the one of Chrome; and on IE it is… one of its bells and whistles.
 
You should never rely on such things. You want standard behavior which you can reasonably expect from all well-known browsers or other browsers using well-known rendering engines. For this purpose. If you need some kind of Web-based presentation or slide show, you can easily do in HTML.
 
Even if you want to work with PowerPoint files, you can use them on the server side. As you are using ASP.NET, I hope you do it on Windows platform where you can install Office and use Microsoft.Office.Interop.PowerPoint. But to represent it on a page, you will need to parse the document and represent it using HTML. Actually, many sites using Office documents do exactly this.
 
—SA
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Richard MacCutchan 269
1 Aajmot Sk 252
2 Marcin Kozub 235
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100