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

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

问题描述

我需要这将需要一个* .JPG图像文件,并上传到用户配置文件中的Active Directory中的方法的Windows AD 2003。

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.

有没有人有任何与Active Directory在C#中的工作经验提供了一些资料,说明如何能以最少的含义与安全相关的工作要做。

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管理员的点是什么,他要 这样做,使这个possible.Changes /规定的用户配置文件等模式。

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?

在此先感谢您的答复,片段和解决方案。

Thanks in advance for your replies,snippets and solutions.

推荐答案

下面是一系列博客文章与code,它展示了如何做到这一点:

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属性在公元 - 第一部分

使用jpegPhoto属性的AD - 第二部分

编辑:下面是一个通用的功能,从第一部分执行code:

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);

这似乎也是TBE的一个商业产品 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天全站免登陆