You must Sign In to post a response.
  • Category: ASP.NET

    User has to select the path and save the file

    Save button code as follows

    i am directly save the excel in D folder.

    for that code as follows

    System.IO.StringWriter sw = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
    gvEmpdetails.RenderControl(htw);
    string renderedGridView = sw.ToString();
    File.WriteAllText("D:Employee123.xl", renderedGridView)


    but i want user has to select the path and save the excel.

    for selecting path how can i do
  • #765820
    1.first Create File on Server. You can use Server.MapPath
    Server. MapPath method to get the physical path for a file in your web application.
    2. User below code to download File from saver witch will Prompt you for Path

    System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
    response.ClearContent();
    response.Clear();
    response.ContentType = "text/plain";
    response.AddHeader("Content-Disposition",
    "attachment; filename=" + fileName + ";");
    response.TransmitFile(Server.MapPath("Employee123.xl"));
    response.Flush();
    response.End();

    you can also check
    http://stackoverflow.com/questions/1268766/writing-file-to-web-server-asp-net
    http://stackoverflow.com/questions/18477398/asp-net-file-download-from-server
    https://msdn.microsoft.com/en-us/library/ez801hhe(v=vs.110).aspx

  • #765827
    Your existing code will not work after it will deploy on server, after deployment asp.net will work on server directories not on client machine so as per your code your excel file will save on D:\ of server not on client machine
    To resolve this you first need to create excel file (which obviously created on server) then download it using below code

    string a = HttpContext.Current.Server.MapPath("D:\\test.xls");
    Response.AppendHeader("content-disposition", "attachment; filename=" + name);
    if (type != "")
    Response.ContentType = type;
    Response.WriteFile(path);
    Response.End();

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #765836
    Hi,

    You can pass the path location in textbox control and concatenate the textbox value with the appropriate location or get the drivers information in to dropdown and based on the selected value of dropdown you have to do some customization to concatenate your code.

    Refer below link, how to get the drivers information : http://www.dotnetspider.com/resources/45476-Display-Drivers-Information.aspx

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments