如何使用C#在ASP.NET中的特定路径中保存Excel [英] How to save excel in specific path in ASP.NET using C#

查看:123
本文介绍了如何使用C#在ASP.NET中的特定路径中保存Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有gridview,我将这个gridview数据表示为excel。



在下载之前我将show popup打开保存取消。



当用户点击打开excel文件打开时。



excel开放代码如下



i have gridview and i am exproting that gridview data to excel.

Before downloading i show popup as Open Save Cancel.

When user click the Open the excel is file open.

The excel open code as follows

System.Threading.Thread.Sleep(3000);
           System.IO.StringWriter sw = new System.IO.StringWriter();
           HtmlTextWriter htw = new HtmlTextWriter(sw);
           gvEmpdetails.AllowPaging = false;
           BindGrid();
           //Applying stlye to gridview header cells
           for (int i = 0; i < gvEmpdetails.HeaderRow.Cells.Count; i++)
               gvEmpdetails.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");
           gvEmpdetails.RenderControl(htw);
           Session["ResponseData"] = sw.ToString();
           iframe1.Attributes.Add("src", "Download.aspx");

When user the Open button in the popup excel is open it is working correctly.

Simliarily When user Click Save button in the popup the user select the path where excel is to be there and save the excel file.

for that saving the excel file what code i have to do.

What I have tried:

i have gridview and i am exproting that gridview data to excel.

Before downloading i show popup as  Open Save Cancel.

When user click the Open the excel is file open.

The excel open code as follows

<pre lang="C#">System.Threading.Thread.Sleep(3000);
           System.IO.StringWriter sw = new System.IO.StringWriter();
           HtmlTextWriter htw = new HtmlTextWriter(sw);
           gvEmpdetails.AllowPaging = false;
           BindGrid();
           //Applying stlye to gridview header cells
           for (int i = 0; i < gvEmpdetails.HeaderRow.Cells.Count; i++)
               gvEmpdetails.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");
           gvEmpdetails.RenderControl(htw);
           Session["ResponseData"] = sw.ToString();
           iframe1.Attributes.Add("src", "Download.aspx");

When user the Open button in the popup excel is open it is working correctly.

Simliarily When user Click Save button in the popup the user select the path where excel is to be there and save the excel file.

for that saving the excel file what code i have to do.

推荐答案

ASP.NET无法与客户端计算机文件夹结构进行交互,因为它只能访问浏览器。

这就是原因,当您从Web应用程序下载任何文件时,它会询问您存储文件的路径。您不能直接在客户端计算机上放置/下载文件,它可能会被视为恶意活动。
ASP.NET is unable to interact with client machine folder structure, as it has only access to browser only.
that's why, When you download any file from web application it ask you for the path to store the file. You can not directly put/download file in client machine it may treat as malicious activity.


这篇关于如何使用C#在ASP.NET中的特定路径中保存Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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