Hi, I want to open a file using c# by clicking a button where button in updatepanel, after opening the file i want to commit some data to the database. For this i have taken button which is in updatepanel and response.write commands. However after executingthese lines its not committing any data to the database. For this i have taken button which is in updatepanel and Response commands. However after executing these lines its not committing any data to the database. my aspx page looks like
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate><asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /><asp:Label ID="Label1" runat="server" Text=""></asp:Label></ContentTemplate><Triggers><asp:PostBackTrigger ControlID="Button1" /></Triggers></asp:UpdatePanel>
and my cs file Button1_Click contains
Label1.Text += "File Opening..."; Response.Buffer = true; Response.Clear(); Response.AppendHeader("Content-Type", "text/plain"); Response.AppendHeader("Content-disposition", "attachment; filename=147.txt"); FileStream sourceFile = new FileStream("D:\\147_1.txt", FileMode.Open); long FileSize; FileSize = sourceFile.Length; byte[] getContent = new byte[(int)FileSize]; sourceFile.Read(getContent, 0, (int)sourceFile.Length); sourceFile.Close(); Response.BinaryWrite(getContent); Response.Flush(); System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest(); Response.Close(); Label1.Text+="File Opened...";
In the above code nothing of text label1.text displayed or any other data committing to database.
Please help me on committing data to database after executing Response commands which opens a file.
Thanks in advance.