簡體   English   中英

在C#中讀取pdf文件時出現System.byte錯誤

[英]System.byte error while reading a pdf file in C#

我嘗試了網站上給出的所有可能的解決方案。

private byte[] GetBinaryFile()
{
    Stream fs = FileUpload1.PostedFile.InputStream;
    BinaryReader br = new BinaryReader(fs);
    Byte[] bytes = br.ReadBytes((Int32)fs.Length);
    return bytes;
}

這是我試圖從fileuploader中讀取的內容,但是沒有用。 然后我改變了主意,首先將文件上傳到服務器上,然后嘗試讀取,但這又給了我相同的system.byte()錯誤。 問題是它不返回pdf的字節格式,但在我的本地系統上運行良好,是否與服務器有關? 任何幫助將不勝感激

您可以嘗試以下方法:

byte[] bytes = new byte[FileUpload1.PostedFile.ContentLength];
bytes = FileUpload1.FileBytes;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM