将文件写入C盘的根目录? [英] writing a file to the root of the C drive?

查看:151
本文介绍了将文件写入C盘的根目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在使用以下命令将文本文件写入C:驱动器时遇到了一个有趣的问题:

Hi All,

I have an interesting issue with writing a text file to the C: drive using the command below:

if (!File.Exists(FileName))
{
    StreamWriter sw = new StreamWriter(FileName);
    sw.WriteLine(TextReplyTrim + "\n");
    sw.WriteLine();
    sw.Close();
}
else
{
    StreamWriter sw = File.AppendText(FileName);
    sw.WriteLine(TextReplyTrim + "\n");
    sw.WriteLine();
    sw.Close();
}



这个或者至少看起来适用于XP我今天早上将它复制到了Windows7机器上。它抱怨我的PC上的用户帐户应具有的权限?我没有注意到这一点,直到我删除了它保存的文件,因为它太乱了它会更新(附加会起作用)而不是创作吗?

格伦(新年快乐全部!)


This works or at least appears to work on XP I copied it across to the Windows7 machine this morning. It complains about about permissions which my user account on my PC should have? I didn''t notice this until I delete the file it was saving to as it got too scrambled it will up date (the Append will work) just not the create?
Glenn (Happy New Year all!)

推荐答案

C:\ 变得更加谨慎地受到Vista的保护,并且仍然如此。您通常可以通过使用管理员权限运行程序来解决问题。但是,建议您不要使用此位置来存储数据,而是使用特殊文件夹 [ ^ ]。
C:\ became more carefully protected with Vista, and continues to be so. You can usually get round the problem by running the program with administrator privileges. However, it is recommended that you do not use this location to store your data, but use one of the Special Folders[^].


为c盘上的用户分配读/写权限。
Assign read /write permission to user on c drive.


这篇关于将文件写入C盘的根目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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