有没有办法在没有FileUpload的情况下附加文件?

时间:2017-07-30 19:11:20

标签: c# sql asp.net file-upload

我加密了pdf并希望将其保存到数据库中,下面是关于我是如何做到的代码。我想知道是否有任何方法可以设置Created" PDFEncrypted.pdf"在不使用FileUploader的情况下进入Stream fs?

     string WorkingFolder = Server.MapPath("~/Files/");
        string InputFile = Path.Combine(WorkingFolder, "PDF.pdf");
        string OutputFile = Path.Combine(WorkingFolder, "PDFEncrypted.pdf");

        using (Stream input = new FileStream(InputFile, FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            using (Stream output = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                PdfReader reader = new PdfReader(InputFile);
              PdfEncryptor.Encrypt(reader, output, true, "pass123", "secret", PdfWriter.ALLOW_SCREENREADERS);
            }
        }

所以我有这些代码上传

Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);

0 个答案:

没有答案