ASP.Net C#:从fileupoad获取二进制文件以生成XML

ASP.Net C#:从fileupoad获取二进制文件以生成XML,c#,asp.net,xml,pdf,base64,C#,Asp.net,Xml,Pdf,Base64,我目前正在结束我的课程,但我进入了一个我没有经验的部分。我已经能够在其他方法中将PDF转换为Base64,但根据我得到的说明,这些方法是不允许的。我在下面发布了我的代码,希望有人能让我朝着正确的方向开始。我也不知道如何把这些卷放进去,所以任何帮助都是很棒的!包含Get二进制文件及其读取的IO类 Default.cs.aspx private static List<Binary> GetBinaries() { return new List<Binary>

我目前正在结束我的课程,但我进入了一个我没有经验的部分。我已经能够在其他方法中将PDF转换为Base64,但根据我得到的说明,这些方法是不允许的。我在下面发布了我的代码,希望有人能让我朝着正确的方向开始。我也不知道如何把这些卷放进去,所以任何帮助都是很棒的!包含Get二进制文件及其读取的IO类

Default.cs.aspx

private static List<Binary> GetBinaries()
{
    return new List<Binary>
    { 
        new Binary
        {
            //hardcoded but need to call from fileUpload1
            BinaryBase64Object = IO.ReadFromFile(@"..\..\EFACTS eRecord Technical Specification.pdf"), **<-- How do I get this to read from fileupload1**
            BinaryID = "BIN1234", //hardcoded
            BinarySizeValue = 56443, //hardcoded
            FileName = " test.my.pdf", //hardcoded
            PageRange = "23-89", //hardcoded
            NoOfPages = 14, //hardcoded
            TotalVolumes = 1, //hardcoded
            Volume = 1 //hardcoded
        }
    };
}

你应该请求更多的帮助。可能已经有一些用于读取PDF文件的库在使用中。试着找出它是什么,并阅读代码,看看它是如何使用的

如果这是项目中第一次有人必须阅读PDF文件,您将不得不采用一些库。自己写一本是非常耗时的。您正在寻找的是一个可以从PDF中读取元数据的库

两个这样的库分别是和。以下是PDFSharp的一个示例:

var doc = PdfReader.Open(@"icpc_briefing_1_sep_10.pdf");
Console.WriteLine("Number of pages: {0}", doc.PageCount);

Console.WriteLine();
Console.WriteLine("=== INFO ===");
foreach (KeyValuePair<string, PdfItem> pair in doc.Info)
{
    Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
}

byte[] xmlData = GetMetadata(doc);
if (xmlData != null)
{
    Console.WriteLine();
    Console.WriteLine("=== XMP ===");
    Console.Write(Encoding.UTF8.GetString(xmlData));
    Console.WriteLine();
}

byte[] GetMetadata(PdfDocument doc)
{
    // PdfSharp does not have direct support for the XML metadata, but it does
    // allow you to go poking into the internal structure.
    PdfItem metadataItem;
    if (doc.Internals.Catalog.Elements.TryGetValue("/Metadata", out metadataItem))
    {
        var metadataRef = (PdfReference) metadataItem;
        var metadata = (PdfDictionary) metadataRef.Value;
        return metadata.Stream.Value;
    }
    return null;
}

基本上,我相信这就是他们想要的。明天我会向老板了解更多细节。你说得对。我在另一个地方的一位同事正在使用PDFSharp进行此过程。我甚至不知道如何开始这个过程。我的一个问题是从cs.aspx调用我的文件上载,并在“获取二进制文件”部分使用它。@RaymondBeyrle我修改了代码以使用PDFSharp而不是iTextSharp。你是了不起的Markus!!!我会尽我最大的努力把它落实到我的计划中。我从来没有做过这种技术性的事情,所以这确实是一个挑战。再次感谢!旁白:你认为PDFSharp比iTextSharp好吗?好奇的是all.BinaryBase64Object=IO.ReadFromFile(@“.\..\EFACTS-eRecord-eRecord-Technical Specification.pdf”),
var doc = PdfReader.Open(@"icpc_briefing_1_sep_10.pdf");
Console.WriteLine("Number of pages: {0}", doc.PageCount);

Console.WriteLine();
Console.WriteLine("=== INFO ===");
foreach (KeyValuePair<string, PdfItem> pair in doc.Info)
{
    Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
}

byte[] xmlData = GetMetadata(doc);
if (xmlData != null)
{
    Console.WriteLine();
    Console.WriteLine("=== XMP ===");
    Console.Write(Encoding.UTF8.GetString(xmlData));
    Console.WriteLine();
}

byte[] GetMetadata(PdfDocument doc)
{
    // PdfSharp does not have direct support for the XML metadata, but it does
    // allow you to go poking into the internal structure.
    PdfItem metadataItem;
    if (doc.Internals.Catalog.Elements.TryGetValue("/Metadata", out metadataItem))
    {
        var metadataRef = (PdfReference) metadataItem;
        var metadata = (PdfDictionary) metadataRef.Value;
        return metadata.Stream.Value;
    }
    return null;
}
var doc = PdfReader.Open(FileUpload1.FileContent);