/// <summary> /// method name:BtnUpload_Click /// Description: Upload The Excel File and Save In Specific Path Which assign in web.config /// Author:bhumi /// Created On:21/7/2015 /// </summary> protected void BtnUpload_Click(object sender, EventArgs e) { string filePath, fileName; try { //check to make sure a file is selected if (InpFileUpload.HasFile) { if (hdnTestValue.Value == "T") { //create the path to save the file to filePath = ConfigurationManager.AppSettings["Path"].ToString(); fileName = Path.Combine(Server.MapPath(filePath), InpFileUpload.FileName); //save the file to our path InpFileUpload.SaveAs(fileName); objconst = new ConstantMessages(); ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert('" + objconst.strFileUploadSuccessfully + "');", true); } } } catch (Exception) { objconst = new ConstantMessages(); Response.Redirect(objconst.strErrorPage);//Error Page } finally { objconst = null; } }
public void Grid_Fill() { StringBuilder strbuilder;//string builder for query try { objconstmsg = new ConstantMessages(); //insert SQLquery in String builder strbuilder = new StringBuilder("SELECT EmployeeID,FirstName,LastName,TitleOfCourtesy,CONVERT(nvarchar,BirthDate,110) AS BirthDate,Address,City,Country,HomePhone"); strbuilder.Append(" FROM"); strbuilder.Append(" Employees;"); //connection generation and read the data fro reader objcmnfunction = new CommonFunction(); //store data in grid view gvEmployees.DataSource = objcmnfunction.ConnectionGenerate(strbuilder.ToString()); gvEmployees.DataBind(); } catch (Exception) { objconstmsg = new ConstantMessages(); Response.Redirect(objconstmsg.strErrorPage); } finally { objcmnfunction = null; strbuilder = null; } }
protected void BtnExport_Click(object sender, EventArgs e) { StringWriter strwritter; HtmlTextWriter htmltextwrtter; string FileName; try { Response.Clear(); Response.Buffer = true; Response.ClearContent(); Response.ClearHeaders(); Response.Charset = ""; FileName = "Employee" + DateTime.Now + ".xls"; strwritter = new StringWriter(); htmltextwrtter = new HtmlTextWriter(strwritter); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName); gvEmployees.GridLines = GridLines.Both; gvEmployees.HeaderStyle.Font.Bold = true; gvEmployees.RenderControl(htmltextwrtter); Response.Write(strwritter.ToString()); } catch (Exception) { objconstmsg = new ConstantMessages(); Response.Redirect(objconstmsg.strErrorPage, false); } finally { Response.End(); objcmnfunction = null; strwritter = null; htmltextwrtter = null; } }