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();
    }
}
7
  • Show the code you're using for downloading the file Commented Feb 13, 2015 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 = @"<style> .textmode { } </style>"; Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); } } Commented Feb 13, 2015 at 10:17
  • it is show the save dialog after the line "Respone.Flush()" executed. Commented Feb 13, 2015 at 10:20
  • Edit your question (and format it), don't add code in comments. Commented Feb 13, 2015 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. Commented Feb 13, 2015 at 10:37

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

3 Comments

Let me try. Thanks @jithendra
FolderBrowserDialog is WinForms - he talks about ASP.Net
see the edited answer, you can access file using elevated privileges rite, then i think its possible, i didn't tried it out sorry for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.