I've had to add to the function so that it can be used in two ways. One for pulling all similar files as descripbed above and now I'm wanting to add to it the ability to get a specific image and store it in the datatable. My code now is below and I'm getting the following error (the exetype param value is 0)
error:
Message:
ArrayTypeMismatchException - GetPersonImageSingle
Source array type cannot be assigned to destination array type.
Stack Trace: at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Array.CopyTo(Array array, Int32 index)
at CTS.DBOBJECT.CODETHREE.BaseQuery`1.FillMugShotDataTable(DataTable dt, String ID, Int32 exetype)
at CTS.DBOBJECT.CODETHREE.MugShot.GetMug(String mugShotID)
at CTS.DBOBJECT.CODETHREE.DBLogic.GetPersonImages(PersonDescription oPerson, String UserID, String UserName, String MugID)
at CTS.WS.DATASEARCH.BIZLogic.GetPersonImages(PersonDescription oPerson, RequestorSecurityLevel RequestorInfo, UsernameToken uToken, String MugID, Boolean GetThumbNail)
at CTS.WS.DATASEARCH.SEARCH.GetPersonImageSingle(String ECSOID, RequestorSecurityLevel RequestorInfo, String MUGID, Boolean GetThumbNail)
.
Code:
protected void FillMugShotDataTable(DataTable dt, string ID, int exetype)
{
string strFilename;
if (exetype == 1)
strFilename = "F" + ID.Trim() + "_*";
else
strFilename = ID;
byte[] data = new byte[1024];
DirectoryInfo myDirectory = new DirectoryInfo(@"C:\WEBS\CTS.WS.DATASEARCH\images");
FileInfo[] files = myDirectory.GetFiles(strFilename);
DataRow myRow;
if (exetype == 1)
{
foreach (FileInfo file in files)
{
{
// Load files into datatable
myRow = dt.NewRow();
myRow["ECSOID"] = ID;
myRow["MugID"] = file.Name;
myRow["DATE"] = "01/01/1900";
myRow["TIME"] = "00:00";
myRow["IMAGE_TYPE"] = "F";
myRow["IMAGE_DESC"] = "";
using (System.IO.FileStream fs = file.OpenRead())
{
if (fs.CanRead)
{
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, bytes.Length);
myRow["Image01"] = bytes;
myRow["ImageSize"] = bytes.Length;
}
}
}
dt.Rows.Add(myRow);
}
}
else
{
// Load files into datatable
myRow = dt.NewRow();
myRow["ECSOID"] = ID;
myRow["MugID"] = ID;
myRow["DATE"] = "01/01/1900";
myRow["TIME"] = "00:00";
myRow["IMAGE_TYPE"] = "F";
byte[] bytes = new byte[1024];
files.CopyTo(bytes,0);
//using (System.IO.FileStream fs = files.)
//{
//if (fs.CanRead)
//{
// byte[] bytes = new byte[fs.Length];
// fs.Read(bytes, 0, bytes.Length);
myRow["Image01"] = bytes;
myRow["ImageSize"] = bytes.Length;
//}
//}
}
}