Hello,
I am trying to use this client to set binary attributes such as Photo in FIM but found out that these attributes were defined as "Int' in the client schema instead of "Byte[]".
I am writing a WCF service which upload a photo to the FIM but i having issues wit the attribute as it is int.
Here is my code:
public UploadedFile Upload(Stream Uploading)
{
int length = 0;
UploadedFile upload = new UploadedFile { FilePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()) };
// This shows the basic steps to modify a resource.
using (DefaultClient client = new DefaultClient())
{
string filterName = "/Person[AccountName='" + HttpContext.Current.User.Identity.Name.Split('\\')[1].ToString() + "']";
System.Security.Principal.WindowsImpersonationContext ctx = null;
ctx = ((System.Security.Principal.WindowsIdentity)HttpContext.Current.User.Identity).Impersonate();
//set credentials and refresh schema
client.RefreshSchema();
// get the person(s) object(s) to modify
foreach (RmPerson person in client.Enumerate(filterName))
{
// create the object to track changes to the resource
RmResourceChanges changes = new RmResourceChanges(person);
try
{
changes.BeginChanges();
//byte[] m_Bytes = ReadToEnd(Uploading);
// person.Photo = Convert.ToInt32(m_Bytes.GetValue(0));
using (FileStream writer = new FileStream(upload.FilePath, FileMode.Create))
{
int readCount;
var buffer = new byte[8192];
byte[] fileContent = null;
BinaryReader binaryReader = new BinaryReader(writer);
while ((readCount = Uploading.Read(buffer, 0, buffer.Length)) != 0)
{
writer.Write(buffer, 0, readCount);
length += readCount;
}
// change something in the resource
person.Photo = binaryreader;
}
// modify the resource on the server
client.Put(changes);
// the operation succeeded: accept the changes.
changes.AcceptChanges();
// NOTE: after calling AcceptChanges the RmResourceChanges
// object does not contain any more changes to propagate to
// the server.
}
catch (Exception ex)
{
changes.DiscardChanges();
}
}
upload.FileLength = length;
return upload;
}
}
Can some one please post the solution to this issue? I need this ASAP.
Thanks,
Sravani
I am trying to use this client to set binary attributes such as Photo in FIM but found out that these attributes were defined as "Int' in the client schema instead of "Byte[]".
What is the reason for that?
Does anybody has some sample code to set binary attributes in FIM?
I am trying to use this client to set binary attributes such as Photo in FIM but found out that these attributes were defined as "Int' in the client schema instead of "Byte[]".
I am writing a WCF service which upload a photo to the FIM but i having issues wit the attribute as it is int.
Here is my code:
public UploadedFile Upload(Stream Uploading)
{
int length = 0;
UploadedFile upload = new UploadedFile { FilePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()) };
// This shows the basic steps to modify a resource.
using (DefaultClient client = new DefaultClient())
{
string filterName = "/Person[AccountName='" + HttpContext.Current.User.Identity.Name.Split('\\')[1].ToString() + "']";
System.Security.Principal.WindowsImpersonationContext ctx = null;
ctx = ((System.Security.Principal.WindowsIdentity)HttpContext.Current.User.Identity).Impersonate();
//set credentials and refresh schema
client.RefreshSchema();
// get the person(s) object(s) to modify
foreach (RmPerson person in client.Enumerate(filterName))
{
// create the object to track changes to the resource
RmResourceChanges changes = new RmResourceChanges(person);
try
{
changes.BeginChanges();
//byte[] m_Bytes = ReadToEnd(Uploading);
// person.Photo = Convert.ToInt32(m_Bytes.GetValue(0));
using (FileStream writer = new FileStream(upload.FilePath, FileMode.Create))
{
int readCount;
var buffer = new byte[8192];
byte[] fileContent = null;
BinaryReader binaryReader = new BinaryReader(writer);
while ((readCount = Uploading.Read(buffer, 0, buffer.Length)) != 0)
{
writer.Write(buffer, 0, readCount);
length += readCount;
}
// change something in the resource
person.Photo = binaryreader;
}
// modify the resource on the server
client.Put(changes);
// the operation succeeded: accept the changes.
changes.AcceptChanges();
// NOTE: after calling AcceptChanges the RmResourceChanges
// object does not contain any more changes to propagate to
// the server.
}
catch (Exception ex)
{
changes.DiscardChanges();
}
}
upload.FileLength = length;
return upload;
}
}
Can some one please post the solution to this issue? I need this ASAP.
Thanks,
Sravani