c# - 如何在 C# 中将图像文件上传到 Active Directory 用户配置文件?

标签 c# active-directory

我需要一种方法来获取 *.jpg 图像文件并将其上传到 Windows AD 2003 的 Active Directory 中的用户配置文件。

还有一种方法可以将照片作为流检索或将其公开为安全 Web 服务,以供 Java 等跨平台应用程序调用(该死!我是不是要求太多了!!!)

正在上传的文件将是 *.jpg,它基本上是用户创建的视觉签名文件。

有没有在 C# 中使用 Active Directory 的任何经验的人提供一些信息,说明如何在与安全相关的最小影响下完成此操作。

从 Windows Active Directory 管理员的角度来看,他必须 使这成为可能。对用户配置文件等架构的更改/规定

正在上传图像,以便稍后可以从 AD 中检索图像以将其插入 PDF 文档以供签名。

这可以用 C# 完成吗?或者有没有完成的库等?

最佳答案

这是一系列博客文章,其中包含展示如何执行此操作的代码:

(第一个是怎么把照片弄进来,第二个是怎么把照片弄出来)

Using the jpegPhoto attribute in AD - Part I

Using the jpegPhoto attribute in AD - Part II

编辑:这是一个实现第一部分代码的通用函数:

void AddPictureToUser(
    string strDN,       // User Distinguished Name, in the form "CN=Joe User,OU=Employees,DC=company,DC=local"
    string strDCName,   // Domain Controller, ie: "DC-01"
    string strFileName // Picture file to open and import into AD
    )
{
    // Open file
    System.IO.FileStream inFile = new System.IO.FileStream(strFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);

    // Retrive Data into a byte array variable
    byte[] binaryData = new byte[inFile.Length];

    int bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length);
    inFile.Close();

    // Connect to AD
    System.DirectoryServices.DirectoryEntry myUser = new System.DirectoryServices.DirectoryEntry(@"LDAP://" + strDCName + @"/" + strDN);

    // Clear existing picture if exists
    myUser.Properties["jpegPhoto"].Clear();

    // Update attribute with binary data from file
    myUser.Properties["jpegPhoto"].Add(binaryData);
    myUser.CommitChanges();
}

编辑:我发现在我的组织中,要设置的正确属性是“thumbnailPhoto”,如下所示:

myUser.Properties["thumbnailPhoto"].Add(binaryData);

这似乎也是商业产品 Exclaimer正在设置(但它可能只在我的组织中这样做)

关于c# - 如何在 C# 中将图像文件上传到 Active Directory 用户配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1978717/

相关文章:

tomcat - JNDI Tomcat Servelet(grails)尝试从身份验证的 LDAP 绑定(bind)中获取更多属性

c# - IList 和 IBindingList 的区别

c# - WPF - DataGrid 中记录插入的自定义验证规则

c# - ILookup<TKey, TVal> 与 IGrouping<TKey, TVal>

c++ - 在客户端-服务器应用程序中使用 Active Directory 对用户进行身份验证

c# - 使用 C# 从通讯组列表中获取电子邮件地址

c# - 尝试将 FK 设置为 null 时违反参照完整性约束

c# - 转换字符串 Ex : "Friday, 11 of november of 2022" to DateTime C#

azure - 为什么我不能 "Configure Azure AD Authentication"

c# - 如何查询 Active Directory 中的更改,包括已删除的对象?