lundi 19 mai 2014

c# 4.0 - Tableau d'octets à convertir en pdf avec code c# - Stack Overflow


I have a table with much more binary type column. I have to convert these byte array to pdf. I write this with c# codes as follows:


this.Cursor = Cursors.WaitCursor;
using (CMEntities myEntity = new CMEntities())
{
myEntity.ContextOptions.LazyLoadingEnabled = false;
var r = (from b in myEntity.FileDatas
orderby b.Oid
where b.Status == null
select b).Skip(Directory.GetFiles(@"D:\test\FromBinary\", "*.*", SearchOption.AllDirectories).Length).Take(500);
button5.Text = Directory.GetFiles(@"D:\test\FromBinary\", "*.*", SearchOption.AllDirectories).Length.ToString();
int i = 1;
try
{
FileSystemStoreObject fileSystem = new FileSystemStoreObject();
foreach (var item in r)
{
byte[] a = item.Content;
File.WriteAllBytes(@"D:\test\FromBinary\" + item.Oid + "-" + item.FileName, a);
fileSystem.Oid = item.Oid;
fileSystem.FileName = item.FileName;
fileSystem.Size = item.size;
item.Status = 1;
myEntity.FileSystemStoreObjects.AddObject(fileSystem);
if (i == 500)
{
break;
}
i++;
fileSystem = new FileSystemStoreObject();
}
myEntity.SaveChanges();
}
catch { }
}

but when my program begin working my some pdf files didn't open. I get error that this file demaged or.... How can I get healthy pdf file? Please help me.



I have a table with much more binary type column. I have to convert these byte array to pdf. I write this with c# codes as follows:


this.Cursor = Cursors.WaitCursor;
using (CMEntities myEntity = new CMEntities())
{
myEntity.ContextOptions.LazyLoadingEnabled = false;
var r = (from b in myEntity.FileDatas
orderby b.Oid
where b.Status == null
select b).Skip(Directory.GetFiles(@"D:\test\FromBinary\", "*.*", SearchOption.AllDirectories).Length).Take(500);
button5.Text = Directory.GetFiles(@"D:\test\FromBinary\", "*.*", SearchOption.AllDirectories).Length.ToString();
int i = 1;
try
{
FileSystemStoreObject fileSystem = new FileSystemStoreObject();
foreach (var item in r)
{
byte[] a = item.Content;
File.WriteAllBytes(@"D:\test\FromBinary\" + item.Oid + "-" + item.FileName, a);
fileSystem.Oid = item.Oid;
fileSystem.FileName = item.FileName;
fileSystem.Size = item.size;
item.Status = 1;
myEntity.FileSystemStoreObjects.AddObject(fileSystem);
if (i == 500)
{
break;
}
i++;
fileSystem = new FileSystemStoreObject();
}
myEntity.SaveChanges();
}
catch { }
}

but when my program begin working my some pdf files didn't open. I get error that this file demaged or.... How can I get healthy pdf file? Please help me.


0 commentaires:

Enregistrer un commentaire