0

I'm currently developing a simple program (using ASP.Net C#) to populate data from GridView into Excel file. the Excel file will be need to downloaded into client computer.

For some reasons, I need to manipulate the Excel file quickly after it downloaded into client local computer.

The problem is I can't get the file location where the file was downloaded. How can I get the file location after it downloaded into client computer ?

This is the screenshot:

enter image description here

Download Code:

private void Create_ExcelContent2()
{
    Response.Clear();
    Response.Buffer = true;
    Response.AddHeader("content-disposition", "attachment;filename=" + ddlBatchID.Text + ".xls");
    Response.Charset = "";
    Response.ContentType = "application/vnd.ms-excel";
    using (StringWriter sw = new StringWriter())
    {
        HtmlTextWriter hw = new HtmlTextWriter(sw); ...
        gvBatchSummary.RenderControl(hw);
        string style = @"<style> .textmode { } </style>";
        Response.Write(style);
        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
h_minos
  • 9
  • 2
  • Show the code you're using for downloading the file – Wain Feb 13 '15 at 10:15
  • private void Create_ExcelContent2() { Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=" + ddlBatchID.Text + ".xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; using (StringWriter sw = new StringWriter()) { HtmlTextWriter hw = new HtmlTextWriter(sw); ... gvBatchSummary.RenderControl(hw); string style = @""; Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); } } – h_minos Feb 13 '15 at 10:17
  • it is show the save dialog after the line "Respone.Flush()" executed. – h_minos Feb 13 '15 at 10:20
  • Edit your question (and format it), don't add code in comments. – Wain Feb 13 '15 at 10:22
  • @fubo all i need is the address. after i get the address, i'll use it to get the file (coz i already have the address), open the file and copy it's contents into a new empty excel file. that it. – h_minos Feb 13 '15 at 10:37
  • Yes, and that is not possible - would be a nightmare if every website could manipulate files on my computer :) – fubo Feb 13 '15 at 10:52
  • @fubo i see. maybe it's because the development is still in my local computer and i can manipulate the file on my own drives. hahaha -___- – h_minos Feb 13 '15 at 10:58

2 Answers2

1

The short answer to this is you cannot do it. Once the file is on the local machine server side code cannot be use to manipulate it. If you could the security implications would be a mine field.

Fred
  • 5,663
  • 4
  • 45
  • 74
0

why don't you try as below

string folderPath = string.Empty;

using (FolderBrowserDialog fdb = new FolderBrowserDialog()) {
  if (fdb.ShowDialog() == DialogResult.OK ){
    folderPath = fdb.SelectedPath;
  }
}

sorry i didn't seen it @fubo ,

Edit:

if at all you want that directory path, then why don't you save it to a prefixed local system path, and from there you can read it and manipulate it.

Jithendra
  • 351
  • 3
  • 17