【发布时间】:2012-02-29 04:06:40
【问题描述】:
我正在编写一个应用程序来将内容转储到文件中。
流程,到目前为止是这样的:
1 - User enters a Path
2 - App checks if the Directory Exists and if i have Writting Permissions
2.a - If if exists, creates a empty file inside and closes it
2.b - If it does not, creates the directory and the file inside it, and closes the file
问题是,一旦我实际必须在我之前创建的这个文件中写入内容时,我不能写一行,它会抛出“拒绝访问路径”。
这是与问题相关的代码sn-p:
// Writting ImgPixels to file
if (BDC.BDCCommons.CommonUtils.DirectoryHasWritePermissions(folderPath))
{
using (StreamWriter filePointer = File.AppendText(folderPath))
{
filePointer.WriteLine(imgPixels);
}
}
else
{
LogWriter.Error ("Permissão Negada", "Diretorio [ " + folderPath + "] nao tem permissao de escrita");
}
这可能是什么原因?! 先谢谢各位了
改进问题:
@500 - 内部服务器错误:folderPath 是文件夹的路径,是的。
我想我知道我的错误在哪里。没有要写入的文件,只是一个文件夹。我的坏
【问题讨论】:
-
Hmm - "folderPath" 是文件夹的名称(仅)还是整个文件名?
-
您在文件夹上调用
File.AppendText()? -
是using语句还是filePointer.WriteLine语句出错?
-
@EdwardThomson 正确,我传递的是文件夹路径而不是文件路径。谢谢
标签: c# file-io file-permissions