directoryinfo

C# - How to use DirectorySecurity.SetOwner() ? I'm having troubles

社会主义新天地 提交于 2019-12-02 06:43:07
I'm having troubles figuring out the SetOwner() method. In my case, I've created an user in Active Directory by code, then, I create a folder for the user. It all works fine, but I cannot set the newly created user as the owner of the folder. I'm not a C# guru, so I'm having troubles to understand the DirectorySecurity.SetOwner() method. Can anyone please help me out? Here is the code that creates the folder, sets the rights like i want it, but I also need to set the user as the owner. string pathIntern = @"\\11fil01\brukar\" + user.UserName; System.IO.DirectoryInfo diIntern = new System.IO

DirectoryInfo.Exists always returns false during MSTest

こ雲淡風輕ζ 提交于 2019-12-02 00:48:15
问题 I have a little bit of logic at the boundary of my app dealing with creating directories. I would like to test that it actually creates directories as expected, but the DirectoryInfo.Exists property always returns false even when the directory actually exists. See also this question - you need to set a breakpoint to see that the directory has actually been created because MSTest will delete it when the test ends. Is there some setting that tells MSTest to allow "normal" filesystem IO during

DirectoryInfo.Exists always returns false during MSTest

六月ゝ 毕业季﹏ 提交于 2019-12-01 20:15:43
I have a little bit of logic at the boundary of my app dealing with creating directories. I would like to test that it actually creates directories as expected, but the DirectoryInfo.Exists property always returns false even when the directory actually exists. See also this question - you need to set a breakpoint to see that the directory has actually been created because MSTest will delete it when the test ends. Is there some setting that tells MSTest to allow "normal" filesystem IO during tests? Assuming you create the DirectoryInfo instance somewhat earlier there is some internal caching of

c# why when the path is “C:” the directoryInfo takes me to the application folder?

南楼画角 提交于 2019-12-01 03:43:38
问题 Why when i give the path "c:" it changed me directly to application folder? static void Main(string[] args) { DirectoryInfo dir = new DirectoryInfo("c:"); Console.WriteLine(dir.FullName); Console.ReadLine(); } The output is the following: c:\users...\documents\visual studio 2010\projects\consoleApplication9\bin\debug But when I give @"c:\" it goes to disk c: despite that "d:" and @"d:\" takes to disk d: . So I need a way to let "c:" takes to disk c: Thanks in advance! 回答1: static void Main

Directory vs DirectoryInfo

隐身守侯 提交于 2019-11-30 02:42:57
Are they equivalent or alternatives to each other? Is any of them deprecated and if so which one? Which one is recommended for use in an ASP.NET web application. My aim is to extract all files from a specific directory recursively. Directory is a static class that provides static methods for working with directories. DirectoryInfo is an instance of a class that provides information about a specific directory. So for example if you wanted the information about C:\Temp: var dirInfo = new DirectoryInfo("C:\\Temp"); if (dirInfo.Exists) { FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption

DirectoryInfo, FileInfo and very long path

别来无恙 提交于 2019-11-29 17:52:00
问题 I try to work with DirectoryInfo, FileInfo with very long path. I try use \\?\c:\long path (i got illegal caracter with fileInfo and DirectoryInfo) I try use file://c:/long path (i got uri not supported) Can i use ~ in a path or something else. I read this post but i would like to use another way that call a API. Is it any other solutions ? There is an article from microsoft for use \\? in file path link text The question is how can i work with very long path, and DirectoryInfo, and FileInfo

Directory vs DirectoryInfo

て烟熏妆下的殇ゞ 提交于 2019-11-28 22:02:44
问题 Are they equivalent or alternatives to each other? Is any of them deprecated and if so which one? Which one is recommended for use in an ASP.NET web application. My aim is to extract all files from a specific directory recursively. 回答1: Directory is a static class that provides static methods for working with directories. DirectoryInfo is an instance of a class that provides information about a specific directory. So for example if you wanted the information about C:\Temp: var dirInfo = new

.NET - Check if directory is accessible without exception handling

放肆的年华 提交于 2019-11-28 10:58:52
I need to go through various directories on the computer (via DirectoryInfo). Some of them aren't accessible, and UnauthorizedAccessException occurs. How can I check directory access without catching the exception? Oded You need to use the Security namespace. See this SO answer. From the answers: FileIOPermission writePermission = new FileIOPermission(FileIOPermissionAccess.Write, filename); if(!SecurityManager.IsGranted(writePermission)) { //No permission. //Either throw an exception so this can be handled by a calling function //or inform the user that they do not have permission to write to

Is there an async version of DirectoryInfo.GetFiles / Directory.GetDirectories in dotNet?

那年仲夏 提交于 2019-11-28 05:44:34
Is there an asynchronous version of DirectoryInfo.GetFiles / Directory.GetDirectories in dotNet? I'd like to use them in an F# async block, and it'd be nice to have a version that can be called with AsyncCallbacks. Problem is I'm trying to suck in a bunch of directories, probably on SMB mounts over slow network connections, and I don't want a bunch of thread pool threads sitting around waiting for network reads when they could be doing other work. No, I don't think there is. The pool thread approach is probably the most pragmatic. Alternatively, I guess you could drop down to P/Invoke - but

C#: How to logon to a share when using DirectoryInfo

家住魔仙堡 提交于 2019-11-27 14:07:02
If I want to instantiate a DirectoryInfo object with an UNC path DirectoryInfo myDI = new DirectoryInfo (@"\\server\share"); how can I pass a username / password that is required to access that share? Thanks In .NET 4 this class works perfectly for me to logon in none windows server via UNC. using Microsoft.VisualBasic; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Linq; using System.Web; using System.Runtime.InteropServices; using System.Security.Principal; using System.Web.Security; namespace