相关疑难解决方法(0)

你如何在.NET中进行模拟?

是否有一种简单的开箱即用方式来模拟.NET中的用户?

到目前为止,我一直在代码项目中使用这个类来满足我的所有模拟要求.

有没有更好的方法来使用.NET Framework?

我有一个用户凭据集(用户名,密码,域名),表示我需要模拟的身份.

.net c# impersonation

128
推荐指数
5
解决办法
22万
查看次数

检查.NET中的目录和文件写入权限

在我的.NET 2.0应用程序中,我需要检查是否有足够的权限来创建和写入目录的文件.为此,我有以下函数尝试创建一个文件并向其写入一个字节,然后删除自己以测试权限是否存在.

我认为检查的最佳方法是实际尝试并执行此操作,捕获发生的任何异常.虽然我对一般的异常捕获并不是特别高兴,所以有更好的或者更可接受的方式吗?

private const string TEMP_FILE = "\\tempFile.tmp";

/// <summary>
/// Checks the ability to create and write to a file in the supplied directory.
/// </summary>
/// <param name="directory">String representing the directory path to check.</param>
/// <returns>True if successful; otherwise false.</returns>
private static bool CheckDirectoryAccess(string directory)
{
    bool success = false;
    string fullPath = directory + TEMP_FILE;

    if (Directory.Exists(directory))
    {
        try
        {
            using (FileStream fs = new FileStream(fullPath, FileMode.CreateNew, 
                                                            FileAccess.Write))
            {
                fs.WriteByte(0xff);
            }

            if (File.Exists(fullPath))
            {
                File.Delete(fullPath);
                success …
Run Code Online (Sandbox Code Playgroud)

.net c# directory file-permissions winforms

75
推荐指数
5
解决办法
11万
查看次数

标签 统计

.net ×2

c# ×2

directory ×1

file-permissions ×1

impersonation ×1

winforms ×1