将二进制保存为文件

本文关键字:文件 保存 二进制 | 更新日期: 2023-09-27 18:16:09

如何将二进制字符串保存为文件?我从Excel张贴二进制字符串。下面是它的代码:

Sub PostFileAsBinary()
Dim Filename  As String
Filename = "''Network Drive'Test File'TestFile.pdf"
FileURL = "http://localhost:11212/Upload/BinaryFile/"
Dim ReadFile As String
Dim n As Integer
n = FreeFile()
Open Filename For Binary As n
ReadFile = String(LOF(n), vbNullChar)
Get n, , ReadFile
Close n
Debug.Print ReadFile
Set httpReq = New MSXML2.XMLHTTP
httpReq.Open "POST", FileURL & "?ID= " & 2, False
httpReq.SetRequestHeader "Content-Length", Len(ReadFile)
httpReq.send ReadFile
Debug.Print httpReq.responseText
ReadFile = ""
Set httpReq = Nothing
End Sub

这是我的控制器动作:

        [HttpPost]
    public ActionResult PostLPFile(int LPKey, string ReadFile)
    {
        using (FileStream srReadFile = new FileStream(@"D:'Temp", FileMode.Create))
        {
            using (BinaryWriter writer = new BinaryWriter(srReadFile))
            {
                writer.Write(ReadFile);
                writer.Close();
            }
        }
        return View();

我成功地发布了二进制文件,但无法在提到的位置上传文件:''Network Drive'Posted File

我想我将不得不转换二进制字符串发布到流,我认为我正在努力。有人能帮忙调查一下吗?

将二进制保存为文件

访问ASP中目录位置的安全性。Net取决于如何在您的web应用程序中实现安全性:

如果您正在模拟最终用户或特定用户,则该用户将需要访问目录位置。

如果不使用模拟,则需要访问该目录的是运行网站的应用程序池的用户身份。

有关ASP中模拟含义的更多信息。