ASP.NET的C# - 获取文件的位置后downloded [英] ASP .Net C# - Get File location after downloded

查看:187
本文介绍了ASP.NET的C# - 获取文件的位置后downloded的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个简单的程序(使用ASP.Net C#)来填充GridView控件从数据导入Excel文件。 Excel文件将需要下载到客户端计算机。

对于一些原因,我需要操作的Excel文件快速后下载到客户端本地计算机。

问题是我不能让该文件被下载的文件的位置。
我怎样才能得到文件的位置后,下载到客户端计算机?

这是截图:

下载code:

 私人无效Create_ExcelContent2()
{
    Response.Clear();
    将Response.Buffer =真;
    Response.AddHeader(内容处置,附件;文件名=+ ddlBatchID.Text +的.xl​​s);
    Response.Charset的=;
    Response.ContentType =应用程序/ vnd.ms-EXCEL;
    使用(StringWriter的SW =新的StringWriter())
    {
        HtmlTextWriter的HW =新的HtmlTextWriter(SW); ...
        gvBatchSummary.RenderControl(HW);
        串风格= @<风格> .textmode {}< /风格与GT;
        的Response.Write(样式);
        Response.Output.Write(sw.ToString());
        Response.Flush();
        到Response.End();
    }
}


解决方案

简短的答案是,你不能做到这一点。一旦该文件是本地机器上的服务器端code不能使用操作它。如果你可以在安全的影响将是一个雷区。

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

解决方案

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.

这篇关于ASP.NET的C# - 获取文件的位置后downloded的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆