Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用文件位置从asp.net中的服务器下载文件 protectedvoid btn\u Getfolder(对象发送方,事件参数e) { 字符串路径=AppSettingConfigurationFolderPath+@“\Logs\”; 字符串文件=e.ToString(); string FileName=“path”//它是显示在客户端下载文件上的文件名。 System.Web.HttpResponse response=System.Web.HttpContext.Current.response; response.ClearContent(); response.Clear(); //response.ContentType=“image/jpeg”; AddHeader(“内容处置”、“附件;文件名=“+filename+”;”); 响应。传输文件(“路径”); response.TransmitFile(Server.MapPath(“”); response.Flush(); response.End(); 如果(iPostBack) { 文件=路径+文件; 字符串[]filepath=Directory.GetFiles(path+@“\General\”; 列表文件=新列表(); foreach(文件路径中的字符串文件路径) { 添加(新列表项(Path.GetFileName(filePath),filePath)); } GridViewFiles.DataSource=文件; GridViewFiles.DataBind(); } }_C#_Asp.net_.net_Datagridview_Frameworks - Fatal编程技术网

C# 如何使用文件位置从asp.net中的服务器下载文件 protectedvoid btn\u Getfolder(对象发送方,事件参数e) { 字符串路径=AppSettingConfigurationFolderPath+@“\Logs\”; 字符串文件=e.ToString(); string FileName=“path”//它是显示在客户端下载文件上的文件名。 System.Web.HttpResponse response=System.Web.HttpContext.Current.response; response.ClearContent(); response.Clear(); //response.ContentType=“image/jpeg”; AddHeader(“内容处置”、“附件;文件名=“+filename+”;”); 响应。传输文件(“路径”); response.TransmitFile(Server.MapPath(“”); response.Flush(); response.End(); 如果(iPostBack) { 文件=路径+文件; 字符串[]filepath=Directory.GetFiles(path+@“\General\”; 列表文件=新列表(); foreach(文件路径中的字符串文件路径) { 添加(新列表项(Path.GetFileName(filePath),filePath)); } GridViewFiles.DataSource=文件; GridViewFiles.DataBind(); } }

C# 如何使用文件位置从asp.net中的服务器下载文件 protectedvoid btn\u Getfolder(对象发送方,事件参数e) { 字符串路径=AppSettingConfigurationFolderPath+@“\Logs\”; 字符串文件=e.ToString(); string FileName=“path”//它是显示在客户端下载文件上的文件名。 System.Web.HttpResponse response=System.Web.HttpContext.Current.response; response.ClearContent(); response.Clear(); //response.ContentType=“image/jpeg”; AddHeader(“内容处置”、“附件;文件名=“+filename+”;”); 响应。传输文件(“路径”); response.TransmitFile(Server.MapPath(“”); response.Flush(); response.End(); 如果(iPostBack) { 文件=路径+文件; 字符串[]filepath=Directory.GetFiles(path+@“\General\”; 列表文件=新列表(); foreach(文件路径中的字符串文件路径) { 添加(新列表项(Path.GetFileName(filePath),filePath)); } GridViewFiles.DataSource=文件; GridViewFiles.DataBind(); } },c#,asp.net,.net,datagridview,frameworks,C#,Asp.net,.net,Datagridview,Frameworks,我应该走哪条路?我收到与物理路径相关的错误,告诉我在Server.MapPath中没有提供虚拟路径 protected void btn_Getfolder(object sender, EventArgs e) { string path = AppSettingConfigurationFolderPath + @"\Logs\"; string file = e.ToString(); string FileName = "path&

我应该走哪条路?我收到与物理路径相关的错误,告诉我在
Server.MapPath
中没有提供虚拟路径

protected void btn_Getfolder(object sender, EventArgs e)
{
    string path = AppSettingConfigurationFolderPath + @"\Logs\";
    string file = e.ToString();

    string FileName = "path"; // It's a file name displayed on downloaded file on client side.

    System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
    response.ClearContent();
    response.Clear();
    // response.ContentType = "image/jpeg";
    response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
    response.TransmitFile("path");
    response.TransmitFile(Server.MapPath(""));
    response.Flush();
    response.End();

    if (IsPostBack)
    {
        file = path + file;
        string[] filePaths = Directory.GetFiles(path + @"\General\");
        List<ListItem> files = new List<ListItem>();

        foreach (string filePath in filePaths)
        {
            files.Add(new ListItem(Path.GetFileName(filePath), filePath));
        }
        GridViewFiles.DataSource = files;

        GridViewFiles.DataBind();
    }
}