Skip to main content
added 50 characters in body
Source Link
1011 1110
  • 771
  • 2
  • 17
  • 44
                    <td>
                        @if (item.ThumbnailPhoto != null)
                        {
                            Image thumbnail;
                            byte[] byteArray = item.ThumbnailPhoto;
                            using (MemoryStream s = new MemoryStream(byteArray, 0, byteArray.Length))
                           {
                               
                               s.Write(byteArray, 0, item.ThumbnailPhoto.Length);
                               s.Position=0;
                               thumbnail = Image.FromStream(s,true);
                           }

                        }
                    </td>
                    <td>
                        @if (item.ThumbnailPhoto != null)
                        {
                            Image thumbnail;
                            byte[] byteArray = item.ThumbnailPhoto;
                            using (MemoryStream s = new MemoryStream(byteArray, 0, byteArray.Length))
                           {
                               s.Write(byteArray, 0, item.ThumbnailPhoto.Length);
                               thumbnail = Image.FromStream(s,true);
                           }

                        }
                    </td>
                    <td>
                        @if (item.ThumbnailPhoto != null)
                        {
                            Image thumbnail;
                            byte[] byteArray = item.ThumbnailPhoto;
                            using (MemoryStream s = new MemoryStream(byteArray, 0, byteArray.Length))
                           {
                               
                               s.Write(byteArray, 0, item.ThumbnailPhoto.Length);
                               s.Position=0;
                               thumbnail = Image.FromStream(s,true);
                           }

                        }
                    </td>
added 2 characters in body
Source Link
1011 1110
  • 771
  • 2
  • 17
  • 44

Grabbing a thumbnailPhoto from active directory. Would this be the correct way of encoding it to byte array. Because when I try to convert this byte array to an image, I get parameter not validparameter not valid error. So I believe it is the way it is being encoded. Note, I am retrieving byte information, but wondering if it is correct information.

Grabbing a thumbnailPhoto from active directory. Would this be the correct way of encoding it to byte array. Because when I try to convert this byte array to an image, I get parameter not valid error. So I believe it is the way it is being encoded. Note, I am retrieving byte information, but wondering if it is correct information.

Grabbing a thumbnailPhoto from active directory. Would this be the correct way of encoding it to byte array. Because when I try to convert this byte array to an image, I get parameter not valid error. So I believe it is the way it is being encoded. Note, I am retrieving byte information, but wondering if it is correct information.

Source Link
1011 1110
  • 771
  • 2
  • 17
  • 44

Retrieving thumbnailPhoto in C#

Grabbing a thumbnailPhoto from active directory. Would this be the correct way of encoding it to byte array. Because when I try to convert this byte array to an image, I get parameter not valid error. So I believe it is the way it is being encoded. Note, I am retrieving byte information, but wondering if it is correct information.

foreach (SearchResult iResult in searchresult)
{
     ADUser userAttributes = new ADUser("", "", "", "", "", "", "", null);
     foreach (string PropertyName in iResult.Properties.PropertyNames)
     {
         foreach (Object key in iResult.GetDirectoryEntry().Properties[PropertyName])
         {
             try
             {

                 switch (PropertyName.ToUpper())
                 {
                     case "DISPLAYNAME":
                         DisplayName = key.ToString();
                         userAttributes.Name = DisplayName;
                         break;

                     case "SAMACCOUNTNAME":
                         SAMAccountName = key.ToString();
                         userAttributes.DomainUserName = SAMAccountName;
                         break;

                     case "MAIL":
                         Mail = key.ToString();
                         userAttributes.EmailAddress = Mail;
                         break;

                     case "DESCRIPTION":
                         Description = key.ToString();
                         userAttributes.JobDescription = Description;
                         break;

                     case "TELEPHONENUMBER":
                         TelephoneNumber = key.ToString();
                         userAttributes.TelephoneNumber = TelephoneNumber;
                         break;

                     case "FAX":
                         Fax = key.ToString();
                         userAttributes.FaxNumber = Fax;
                         break;

                     case "DEPARTMENT":
                         Department = key.ToString();
                         userAttributes.Department = Department;
                         break;

                     case "THUMBNAILPHOTO":
                         BinaryFormatter bf = new BinaryFormatter();
                         MemoryStream ms = new MemoryStream();
                         bf.Serialize(ms, key);

                         ThumbnailPhoto = ms.ToArray();
                         userAttributes.ThumbnailPhoto = ThumbnailPhoto;
                         break;
                    }
                 }
                 catch
                 {

                 }
              }
           }

         Users.Add(userAttributes);
       }

     return View(Users);
    }
  return View();
 }

In my View:

                    <td>
                        @if (item.ThumbnailPhoto != null)
                        {
                            Image thumbnail;
                            byte[] byteArray = item.ThumbnailPhoto;
                            using (MemoryStream s = new MemoryStream(byteArray, 0, byteArray.Length))
                           {
                               s.Write(byteArray, 0, item.ThumbnailPhoto.Length);
                               thumbnail = Image.FromStream(s,true);
                           }

                        }
                    </td>

If it is wrong, how would I encode this properly.