127 lines
3.3 KiB
C#
127 lines
3.3 KiB
C#
using EDOKA_Database;
|
|
using Syncfusion.DocIO.DLS;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Syncfusion.DocIO;
|
|
using Syncfusion.DocIO.DLS;
|
|
using Syncfusion.XlsIO;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
using Syncfusion.Pdf.Parsing;
|
|
|
|
|
|
namespace DOCGEN
|
|
{
|
|
public class clsGetDoc
|
|
{
|
|
private string connectionstring = "";
|
|
|
|
public clsGetDoc(string Connectionstring)
|
|
{
|
|
this.connectionstring = Connectionstring;
|
|
}
|
|
public string test_filetype(string filename)
|
|
{
|
|
string b64 = ConvertFileToBase64(filename);
|
|
string type = get_doc_filetype(b64);
|
|
return "";
|
|
}
|
|
|
|
public string GetDocAsPDF(string Docid)
|
|
{
|
|
string doc = GetDoc(Docid);
|
|
return "";
|
|
}
|
|
public string GetDoc(string Docid)
|
|
{
|
|
EDOKA_DB db = new EDOKA_DB(connectionstring);
|
|
db.GetDocumentAsBase64(Docid);
|
|
if (Docid != "")
|
|
{
|
|
return "";
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
|
|
}
|
|
|
|
public string ConvertFileToBase64(string fileName)
|
|
{
|
|
string ReturnValue = "";
|
|
|
|
|
|
using (FileStream BinaryFile = new FileStream(fileName, FileMode.Open))
|
|
{
|
|
BinaryReader BinRead = new BinaryReader(BinaryFile);
|
|
byte[] BinBytes = BinRead.ReadBytes(System.Convert.ToInt32(BinaryFile.Length));
|
|
ReturnValue = Convert.ToBase64String(BinBytes);
|
|
BinaryFile.Close();
|
|
}
|
|
|
|
return ReturnValue;
|
|
}
|
|
|
|
public string get_doc_filetype(string document)
|
|
{
|
|
string type = "";
|
|
var stream = new MemoryStream(Convert.FromBase64String(document));
|
|
|
|
try
|
|
{
|
|
Syncfusion.DocIO.DLS.WordDocument WordDocument = new Syncfusion.DocIO.DLS.WordDocument(stream);
|
|
type = WordDocument.ActualFormatType.ToString();
|
|
WordDocument = null;
|
|
return type;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
}
|
|
|
|
try
|
|
{
|
|
ExcelEngine excelEngine = new ExcelEngine();
|
|
IApplication application = excelEngine.Excel;
|
|
IWorkbook workbook = application.Workbooks.Open(stream);
|
|
type = workbook.Version.ToString();
|
|
workbook = null;
|
|
application = null;
|
|
excelEngine = null;
|
|
|
|
return type;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
}
|
|
|
|
try
|
|
{
|
|
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Helper.EncodeExtensions.DecodeBase642ByteArray(document));
|
|
loadedDocument = null;
|
|
return "PDF";
|
|
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
|
|
}
|
|
return type;
|
|
}
|
|
}
|
|
}
|