通过网页在客户端系统中写入新文件 [英] Write New File in Client System through web page

查看:91
本文介绍了通过网页在客户端系统中写入新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何在客户端系统(C:\ XXX \ Config.txt)中创建文本文件
当用户单击我的网页上的创建"按钮时,我正在使用
ASP.Net,C#.Net,

请帮帮我.








谢谢
Sudheer.N

Hi all,

How can i create a text file in client system (C:\XXX\Config.txt)
when user click on Create Button on my WebPage, i am using
ASP.Net , C#.Net,

please help me.








Thanks
Sudheer.N

推荐答案

否,您无法在客户端计算机中写入文件.其安全功能.在浏览器中执行的任何程序都可以在浏览器沙箱中执行,并且可以访问打印机,Cookie等受限功能.

但是您不能在用户计算机上写入文件.有人可能会用它在用户的计算机上写病毒.受限制.

检查此方法以找到其他解决方案.它将文件作为响应对象"写入用户的浏览器.用户可以选择是否将其保存到自己的计算机中.
http://forums.asp.net/t/544299.aspx/1 [ ^ ]
No you cannot write to the file in the client''s machine. Its the security features. Any program executing in the browser executes within the browser sandbox and has access to limited features like printer, cookies etc.

But you cannot write to a file on user''s machine. Somebody may use it to write a virus on user''s machine. Its restricted.

Check this for a alternative solution..It writes the file as a "Response object" to the user''s browser. The user has the choice whether to save it or not to his machine..

http://forums.asp.net/t/544299.aspx/1[^]


我不知道认为不可能在客户端计算机上写.如果您想使用文件中的数据进行逻辑处理,则可以将数据保存在cookie中,并正确使用这些cookie.

如果您的要求是将文件保存在磁盘上,则必须让用户知道他将必须下载文件并将其保存在某个位置.在这种情况下,您将必须提供要下载的文件.
I don''t think it is possible to write on a clients computer. You can save you data in cookies and use these cookies properly if you want to do something in logic using the data in file.

If your requirement is saving the file on disk then you will have to let the user know that he will have to download the file and save it in some location. you will have to provide the file to download in this case.


尝试以下代码:

Try the below code:

Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename="test.xls"");
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.Html32TextWriter oHtmlTextWriter = new System.Web.UI.Html32TextWriter(oStringWriter);
0Table.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();



这将提示用户在客户端打开或保存test.xls文件.

B Birajdar-添加了参考链接
http://stackoverflow.com/questions/1072814/c-sharp- asp-net-write-file-to-client [ ^ ]



This will give prompt the user to open or save test.xls file at the client side.

B Birajdar-Added the reference link
http://stackoverflow.com/questions/1072814/c-sharp-asp-net-write-file-to-client[^]


这篇关于通过网页在客户端系统中写入新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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