ASP .Net C# - Get File location after downloaded

2019-09-02 02:37发布

问题:

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:

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();
    }
}

回答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.



回答2:

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.