Tag: ntfs

在.net(c#)中检查重新分析点的最佳方法是什么?

我的function几乎是一个标准的搜索function…我已将它包含在下面。 在函数中,我有1行代码负责清除重新分配NTFS点。 if (attributes.ToString().IndexOf(“ReparsePoint”) == -1) 问题是现在我收到错误Access to the path ‘c:\System Volume Information’ is denied. 我调试了代码,运行时该目录的唯一属性是: System.IO.FileAttributes.Hidden | System.IO.FileAttributes.System | System.IO.FileAttributes.Directory 我正在Windows 2008服务器上执行此代码,任何想法我能做些什么来治愈这个失败? public void DirSearch(string sDir) { foreach (string d in Directory.GetDirectories(sDir)) { DirectoryInfo dInfo = new DirectoryInfo(d); FileAttributes attributes = dInfo.Attributes; if (attributes.ToString().IndexOf(“ReparsePoint”) == -1) { foreach (string f in Directory.GetFiles(d, searchString)) { […]

如何使用C#同步并一致地删除NTFS上的文件夹

这个: Directory.Delete(dir, true); 是不同步的。 在紧接着的行中,您仍然可以操作/读取目录。 例如,这个: Directory.Delete(destinationDir, true); Directory.CreateDirectory(destinationDir); Thread.Sleep(1000); 导致文件夹不存在。 删除运行异步, CreateDirectory不创建,因为它已经存在,然后删除实际触发并删除目录。 是否有一个IO API可以提供一致性? 涉及Thread.Sleep答案将调用Zalgo。 我想要一个真正的解决方案。

如何在.NET / C#中创建带尾随点(。)的文件夹?

我需要使用C#创建带尾随点(。)的文件夹。 这是我的代码: System.IO.Directory.CreateDirectory(“d:\\MyCorp Inc.”); 但是创建的文件夹没有最后一个点。 有解决方案吗? 我正在使用.NET Framework 4.5 / C#。 我的文件系统是Windows 8上的NTFS。

C#代码自动授予对Windows Server 2008上的文件夹的IIS写入权限? 目前抛出exception

我正在尝试编写一个命令行工具,它将使Windows Server 2008上的IIS7.5对wwwroot中的文件夹具有写入权限,以便Web应用程序可以访问其基本目录中的特定文件夹。 以前,您可以通过在给予该组修改访问权限的文件夹上分配IIS_WPG组来执行此操作。 在Server 2008中,我正在尝试使用IIS_IUSRS执行相同的操作,但是出现exception。 这是代码: private static void ManagePermissions(string directory, string account, FileSystemRights rights, AccessControlType controlType, bool addAccess) { DirectoryInfo directoryInfo = new DirectoryInfo(directory); DirectorySecurity directorySecurity = directoryInfo.GetAccessControl(); if (addAccess) directorySecurity.AddAccessRule( new FileSystemAccessRule(account, rights, controlType)); else directorySecurity.RemoveAccessRule( new FileSystemAccessRule(account, rights, controlType)); directoryInfo.SetAccessControl(directorySecurity); } 对此方法的调用如下: ManagePermissions( “c:\inetpub\wwwroot”, “MACHINENAME\IIS_IUSRS”, FileSystemRights.Modify, AccessControlType.Allow, true); 当执行对ManagePermissions的调用时,将引发具有以下类型和消息的exception: System.Security.Principal.IdentityNotMappedException: Some […]

什么可能导致XML文件填充空字符?

这是一个棘手的问题。 我怀疑它需要一些文件系统的高级知识才能回答。 我有一个针对.NET framework 4.0的WPF应用程序“App1”。 它有一个Settings.settings文件,用于生成标准App1.exe.config文件,其中存储了默认设置。 当用户修改设置时,修改将进入AppData\Roaming\MyCompany\App1\XX0.0\user.config 。 这是所有标准的.NET行为。 但是,有时,我们发现客户机器上的user.config文件不是它应该是的,这会导致应用程序崩溃。 问题看起来像这样: user.config大小与XML填充时的大小相同,但是它只是一堆NUL字符而不是XML。 它的字符0一遍又一遍地重复。 我们没有关于导致此文件修改的内容的信息。 如果我们只是删除user.config ,我们可以在客户的设备上修复该问题,因为公共语言运行时只会生成一个新的。 他们将失去他们对设置所做的更改,但可以再次进行更改。 但是,我在另一个WPF应用程序“App2”中遇到了这个问题,另一个XML文件是info.xml 。 这次是不同的,因为文件是由我自己的代码而不是CLR生成的。 常见的主题是两个都是C#WPF应用程序,都是XML文件,在这两种情况下,我们完全无法在测试中重现问题。 这可能与C#应用程序与XML文件或文件交互的方式有关吗? 我们不仅无法在当前的应用程序中重现该问题,而且我甚至无法通过编写有意产生错误的自定义代码来重现该问题。 我找不到单个XML序列化错误或文件访问错误导致文件填充空值。 那么可能会发生什么? App1通过调用Upgrade()和Save()以及获取和设置属性来访问user.config 。 例如: if (Settings.Default.UpgradeRequired) { Settings.Default.Upgrade(); Settings.Default.UpgradeRequired = false; Settings.Default.Save(); } App2通过序列化和反序列化XML来访问info.xml : public Info Deserialize(string xmlFile) { if (File.Exists(xmlFile) == false) { return null; } XmlSerializer xmlReadSerializer = […]

如何从C#设置文件夹ACL

如何在C#中自动执行以下手动步骤? 右键单击Windows资源管理器中的文件夹; Properties -> Security -> Advanced -> Edit 取消选中“包括此对象的父级的可inheritance权限”,然后单击“删除”。 单击“添加”,选择一个组并授予其“修改”权限。 我发现这篇文章 ,看起来就像我需要的,但我没有,也找不到Microsoft.Win32.Security 。

以编程方式向文件夹添加权限

我有一个问题,我需要为所有经过身份validation的用户添加对文件夹的访问权限,以存储与应用程序相关的设置。 我发现这可以通过以下代码完成… var Info = new DirectoryInfo(settingsdir); var Security = Info.GetAccessControl(AccessControlSections.Access); Security.AddAccessRule( new FileSystemAccessRule( “Authenticated Users”, FileSystemRights.Modify, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)); 我发现的问题是“Authenticated Users”是Windows上的系统帐户,但是在Windows的不同语言版本上,此帐户名被翻译,例如在德国,该帐户被称为“Authentifizierte Benutzer”。 有没有办法知道这个帐户的正确名称(显而易见的是通过每种语言并找到正确的帐户名称)。

c#文件路径字符串比较不区分大小写

我想在c#中比较包含文件路径的两个字符串。 但是,因为在ntfs中默认使用不区分大小写的路径,所以我希望字符串比较以相同的方式不区分大小写。 但是,我似乎无法找到有关ntfs如何实际实现其不区分大小写的任何信息。 我想知道的是如何使用ntfs用于文件路径的相同大小写规则对字符串进行不区分大小写的比较。

重复GetAccessRules,FileSystemAccessRule条目

我从以下代码中获取了一个重复的FileSystemAccessRule: C:\inetpub\wwwroot\AspInfo\Account BUILTIN\IIS_IUSRS : Allow : ReadAndExecute, Synchronize BUILTIN\IIS_IUSRS : Allow : -1610612736 NT SERVICE\TrustedInstaller : Allow : FullControl NT SERVICE\TrustedInstaller : Allow : 268435456 我无法弄清楚它是什么或为什么。 并且显示的权限与我可以看到的文件FileManager属性不匹配。 例如,如何从此迭代或类似迭代中找到“列出文件夹内容”权限。 如果有人知道.NET文档中的示例,那将会有所帮助。 protected void directoryInfo() { var di = new DirectoryInfo(Server.MapPath(“/”)); foreach (DirectoryInfo dir in di.GetDirectories()) { Response.Write(dir.FullName + “”); DirectorySecurity ds = dir.GetAccessControl(); foreach (FileSystemAccessRule fsar in […]

在.NET中,如何获取符号链接(或重新分析点)的目标?

在.NET中,我认为我可以通过调用System.IO.File.GetAttributes()并检查ReparsePoint位来确定文件是否是符号链接。 像这样: var a = System.IO.File.GetAttributes(fileName); if ((a & FileAttributes.ReparsePoint) != 0) { // it’s a symlink } 在这种情况下,如何获得符号链接的目标? ps:我知道如何创建符号链接。 它需要P / Invoke: [Interop.DllImport(“kernel32.dll”, EntryPoint=”CreateSymbolicLinkW”, CharSet=Interop.CharSet.Unicode)] public static extern int CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, int dwFlags);