想要将文件保存在用户的桌面中 [英] want to save a file in user's Desktop

查看:62
本文介绍了想要将文件保存在用户的桌面中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...
我想在用户的桌面中保存文件

我的代码是

hi Everyone...
I want to save a file in user''s Desktop

my code is

string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

File.WriteAllText(path, This is created by Animesh Datta.....);



但是这里发生了异常.拒绝访问该路径.

如何在桌面中保存文件?



but here exception is occurred . Access to the path is denied.

how can i save a file in desktop ?

推荐答案

您的"path"变量包含文件夹名称,而不是文件名.您可以追加文件名并使用StreamWriter写入文件,例如
Your "path" variable contains the folder name, not a filename. You can append your filename and write the file with a StreamWriter, e.g.
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Testfile.txt");
using (StreamWriter writer = new StreamWriter(filename))
{
    writer.Write("This is created by Animesh Datta.....");
}



还要注意,由于客户的安全设置,桌面可以是只读的.



Also note that the Desktop can be read-only due to the security settings of your customer.


亲爱的

试试这个

hi dear

try this

string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string filepath = path + "\\myfile.txt";




请尝试上面的Bernhard Hiller提供的代码,如果它不起作用,则您当前的用户帐户无权在操作系统文件夹中写入文件,请尝试使用管理员帐户.
Hi,

Try the above code given by Bernhard Hiller if it does''t work then your current user account does''t has permission to write file in operating system folder try with administrator account.


这篇关于想要将文件保存在用户的桌面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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