能不能把文件写到客户端的一个指定目录,答对有分 maybe ActiveX Control can do it. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果你有足够的权限可以用:Import System.IO进行文件操作 基本上很难,你最多可以保存cookie到ie临时文件里。。还有,就是客户端(浏览器)的安全性设置较低,可允许你运行某些可执行程序。 可以 用HttpContext.Current.Response.Write( strData )方法!这里是一个将datagrid保存到client端excel文档的例子你可以搜一下论坛里关于将文件保存到客户端的例子 /// <summary> /// Export & download all data out to a file on clientside. /// Try setting ExportFileName / ExportFileType / ExportInvisibleColumns / AddDateInfoToFileName before export data /// </summary> public void Export() { ExportFileName = ExportFileName.Replace( "." + ExportFileType, "" ); if ( AddDateInfoToFileName ) ExportFileName += DateTime.Now.ToString("_yyyyMMdd"); if ( ExportFileType != FileType_Export.AllType ) ExportFileName += "." + ExportFileType.ToString(); HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+""+ExportFileName); HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default ; HttpContext.Current.Response.ContentType ="application/ms-excel/ms-word";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword string strData = "<table border=1>"; for ( int i=-1; i< this.Items.Count ; i++ ) { strData += "<tr>"; for ( int j=0; j< this.Columns.Count ; j++ ) { // Igore none visible columns or not . if ( !this.Columns[j].Visible && !ExportInvisibleColumns ) continue; strData += "<td>"; if ( i < 0 ) strData += "<b>"+this.GetHeaderText( j )+"</b>"; else strData += this.GetItemString( i,j ); strData += "</td>"; } strData += "</tr>"; } strData += "</table>"; HttpContext.Current.Response.Write( strData ); HttpContext.Current.Response.End(); } 如果用winform,实现起来没问题,但如果是webform,因为它是运行在服务器端的,你写文件只能写到服务器端而无法直接写到客户端,只能把相应的文件以http流的形式发送给客户端,然后由客户端指定保存的位置。 webform应该不行,除非用ActiveX UP,除非你自己预先写个ActiveX的控件装到用客户端! 在没打开ie的安全情况下,只有用ActiveX 或者 嵌入的WinForm http://developer.irt.org/script/1421.htm 求 asp.net web 项目打包 含iis及sql 数据库(iis及数据库检测,如没有自动安装) 实例 网站发布,遇到500.21问题 请教一个服务器防火墙设置问题 fckeditor中文插入乱码问题 提个简单问题,关于界面的html代码 求ASP.NET操作word实例。。。。。100分 asp.net网站发布之后出错 框架中的ASPX页面有无办法判断框架中的另一个页面中是否存在某个控件? 怎样部署asp.net程序 100分求购用C#写的无刷新聊天室,一定要能运行呀 如何动态加载用户控件 文件上传
可以用:Import System.IO进行文件操作
这里是一个将datagrid保存到client端excel文档的例子
你可以搜一下论坛里关于将文件保存到客户端的例子 /// <summary>
/// Export & download all data out to a file on clientside.
/// Try setting ExportFileName / ExportFileType / ExportInvisibleColumns / AddDateInfoToFileName before export data
/// </summary>
public void Export()
{
ExportFileName = ExportFileName.Replace( "." + ExportFileType, "" );
if ( AddDateInfoToFileName ) ExportFileName += DateTime.Now.ToString("_yyyyMMdd");
if ( ExportFileType != FileType_Export.AllType ) ExportFileName += "." + ExportFileType.ToString();
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+""+ExportFileName);
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default ;
HttpContext.Current.Response.ContentType ="application/ms-excel/ms-word";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword string strData = "<table border=1>";
for ( int i=-1; i< this.Items.Count ; i++ )
{
strData += "<tr>";
for ( int j=0; j< this.Columns.Count ; j++ )
{
// Igore none visible columns or not .
if ( !this.Columns[j].Visible && !ExportInvisibleColumns ) continue; strData += "<td>";
if ( i < 0 )
strData += "<b>"+this.GetHeaderText( j )+"</b>";
else
strData += this.GetItemString( i,j );
strData += "</td>"; }
strData += "</tr>";
}
strData += "</table>";
HttpContext.Current.Response.Write( strData );
HttpContext.Current.Response.End();
}