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();
ds = GetRevenueDetails();
int rowscount = ds.Tables[0].Rows.Count;
pnlDC_dgrdRevenueOthers.CurrentPageIndex = pageIndex;
pnlDC_dgrdRevenueOthers.DataSource = ds;
pnlDC_dgrdRevenueOthers.DataBind();
}
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 f_Name = (String)e.CommandArgument;
f_Name = "presentations/" + f_Name;
string extension;
try
{
extension = Path.GetExtension(f_Name);
String FilePath = Server.MapPath(f_Name);
System.Diagnostics.Process.Start(FilePath);
}
catch (FileNotFoundException ex)
{
throw (ex);
}
}
please someone answer for this problem.