如何在 C# 中将图像文件上传到 Active Directory 用户配置文件? [英] How to upload an image file to Active Directory user profile in C#?

查看:20
本文介绍了如何在 C# 中将图像文件上传到 Active Directory 用户配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need a method which will take an *.jpg image file and upload it to a user profile in the Active Directory of Windows AD 2003.

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

Also a method to retrieve the photo as stream or expose it as secure web service to be called by cross platform apps in java etc (Damn! am I asking too much!!!)

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

The file being uploaded will be a *.jpg which is basically a visual signature file created by a user.

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

Does anyone having any experience working with Active Directory in C# provide some information as to how this can be done with minimum implication related to security.

从 Windows Active Directory 管理员的角度来看,他需要做什么做使这成为可能.对用户配置文件等架构的更改/规定.

From the point of view of the Windows Active Directory Administrator what does he have to do to make this possible.Changes/provisions to schema of user profile etc.

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

The image is being uploaded so that it can be later retrieved from the AD to be inserted into PDF document for signature purposes.

这可以在 C# 中完成吗?或者有没有完成的图书馆等?

Can this be done in C#? Or is there any done libraries etc?

推荐答案

以下是一系列博客文章,其中包含展示如何操作的代码:

Here's a series of blog postings with code that shows how to do it:

(第一个显示如何放入照片,第二个显示如何取出)

(The first shows how to get a photo in, the second shows how to get it out)

在广告中使用 jpegPhoto 属性 - 第一部分

在 AD 中使用 jpegPhoto 属性 - 第二部分

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

Here's a generic function implementing the code from Part I:

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",如下所示:

I found that in my organisation, the correct attribute to set was "thumbnailPhoto" like this:

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

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

This also seems to tbe the one that the commercial product Exclaimer is setting (but it might be only doing that in my organization)

这篇关于如何在 C# 中将图像文件上传到 Active Directory 用户配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆