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);
    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.ContentType = "text/plain";
    "attachment; filename=" + fileName + ";");

    you can also check

  • #765827
    Your existing code will not work after it will deploy on server, after deployment 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;

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

  • #765836

    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 :

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

    Blog :

  • Sign In to post your comments