Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 写入目录中的文件系统_C#_Asp.net_.net - Fatal编程技术网

C# 写入目录中的文件系统

C# 写入目录中的文件系统,c#,asp.net,.net,C#,Asp.net,.net,我想在目录C:\directory name中写入文件系统,目前我有以下代码: if (! System.IO.File.Exists (HttpContext.Current.Server.MapPath (filename))) { TXTFile = new System.IO.StreamWriter (HttpContext.Current.Server.MapPath (filename)); } else { TXTFile = System.IO.File.Appen

我想在目录C:\directory name中写入文件系统,目前我有以下代码:

if (! System.IO.File.Exists (HttpContext.Current.Server.MapPath (filename)))
{
   TXTFile = new System.IO.StreamWriter (HttpContext.Current.Server.MapPath (filename));
}
else
{
   TXTFile = System.IO.File.AppendText (HttpContext.Current.Server.MapPath (filename));
}
但这样写在应用程序文件夹上。 如何修复它?

就这么做吧

Path.Combine(@"C:\", filename)
而不是

HttpContext.Current.Server.MapPath (filename)
确保您的应用程序对目标具有写访问权限。

只需执行此操作即可

Path.Combine(@"C:\", filename)
而不是

HttpContext.Current.Server.MapPath (filename)

确保您的应用程序对目标具有写访问权限。

您似乎是从web应用程序执行此操作的

虽然可以(使用正确的权限)写入C:\root,但这不是很好的做法


你最好把它存到别的地方。还要研究一下这个方法

您似乎是从一个web应用程序中执行此操作的

虽然可以(使用正确的权限)写入C:\root,但这不是很好的做法


你最好把它存到别的地方。还可以研究一下这个方法

如果已经有一个类似c:\like的路径,则不需要使用mappath。当您有一个服务器路径并且需要一个c:\like路径时,将使用Mappath。此外,由于这似乎是一个ASP.NET应用程序,您可能无法访问您试图写入的路径。如果您已经有一个c:\like路径,则不必使用Mappath。当你有一个服务器路径并且需要一个c:\like路径时,就会使用Mappath。另外,由于这似乎是一个ASP.NET应用程序,你可能无法访问你试图写入的路径。你的意思是
“c:\\”
@“c:\”
我想非常感谢你,这就是我想要的
“c:\\”
@“c:\”
我想非常感谢你,这就是我想要的