相关疑难解决方法(0)

如何将一个流的内容复制到另一个流?

将一个流的内容复制到另一个流的最佳方法是什么?有没有标准的实用方法?

c# stream copying

511
推荐指数
3
解决办法
28万
查看次数

Azure下载blob文件流/ memorystream

我希望用户能够从我的网站下载blob.我想要最快/ cheapeast /最好的方式来做到这一点.

这是我想出的:

        CloudBlobContainer blobContainer = CloudStorageServices.GetCloudBlobsContainer();

        CloudBlockBlob blob = blobContainer.GetBlockBlobReference(blobName);
        MemoryStream memStream = new MemoryStream();
        blob.DownloadToStream(memStream);

        Response.ContentType = blob.Properties.ContentType;
        Response.AddHeader("Content-Disposition", "Attachment; filename=" + fileName + fileExtension);
        Response.AddHeader("Content-Length", (blob.Properties.Length).ToString());
        Response.BinaryWrite(memStream.ToArray());
        Response.End();
Run Code Online (Sandbox Code Playgroud)

我现在正在使用内存流,但是我猜我应该使用文件流,因为在某些情况下,blob是大的..对吧?

我尝试使用文件流,但我失败了.想想你可以给我一些文件流的代码吗?

asp.net-mvc azure

7
推荐指数
1
解决办法
7122
查看次数

使用HTTP GET流式传输文件:ASP .NET CORE API

我已经编写了一个控制器来下载/流文件到客户端本地机器.除了只生成响应体之外,代码不会在对URL进行GET时传输文件.

streamcontent方法有什么问题.在调试我找不到问题.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using System.Net.Http;
using System.Net;
using System.IO;
using System.Text;

namespace FileDownloaderService.Controllers
{
    [Route("api/[controller]")]
    public class FileDownloadController : Controller
    {

        [HttpGet]
        public HttpResponseMessage Get() {
            string filename = "ASPNETCore" + ".pdf";
            string path = @"C:\Users\INPYADAV\Documents\LearningMaterial\"+ filename;

            if (System.IO.File.Exists(path)) {
                HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
                var stream = new FileStream(path, FileMode.Open);
                stream.Position = 0;
                result.Content = new StreamContent(stream);
                result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") { FileName = filename };
                result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf"); …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net

4
推荐指数
1
解决办法
9175
查看次数

将PDF流写入响应流

当我尝试从我的asp.net页面运行以下代码时遇到问题.该代码来自另一篇文章(http://stackoverflow.com/questions/5828315/write-pdf-stream-to-response-stream).当Test.pdf文件位于我的本地驱动器中时,单击对话框上的打开按钮时,我无法打开该文件.当单击保存按钮时,文件以"C:\ Downloads"中的myAspPageName.pdf方式尝试,该操作将继续执行,而不会实际保存任何内容.

我确定我做错了什么.谢谢你的帮助.有没有更好的方法做同样的事情?

protected void Page_Load(object sender, EventArgs e) 
{         
    Context.Response.Buffer = false;         
    FileStream inStr = null;         
    byte[] buffer = new byte[1024];         
    long byteCount; inStr = File.OpenRead(@"C:\Downloads\Test.pdf");         
    while ((byteCount = inStr.Read(buffer, 0, buffer.Length)) > 0) 
    {    
        if (Context.Response.IsClientConnected) 
        { 
            Context.Response.ContentType = "application/pdf";
            Context.Response.OutputStream.Write(buffer, 0, buffer.Length);
            Context.Response.Flush();             
        }        
    }     
} 
Run Code Online (Sandbox Code Playgroud)

asp.net

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net ×2

c# ×2

.net ×1

asp.net-mvc ×1

azure ×1

copying ×1

stream ×1