public async ask<HttpResponseMessage> GetGuidingPrincipleDownload(string name ) 

        {

            bool status = false;

            try

            {

                if (name != "")

                {

                    name += name + ".pdf";

                    status = connectState(@"\\10.10.10.178\phiic_file_hive\fdaBioEquiTestGuide", @"anonymous", "");//连接共享文件   connectState( 文件   用户名  密码)

                    if (status)

                    {

                        DirectoryInfo theFolder = new DirectoryInfo(@"\\10.10.10.178\phiic_file_hive\fdaBioEquiTestGuide\");

                        string path = Path.Combine(theFolder.ToString(), name);//路径

                        if (!string.IsNullOrWhiteSpace(path) && File.Exists(path))

                        {

                            string filename = Path.GetFileName(path);

                            var stream = new FileStream(path, FileMode.Open, FileAccess.Read);//打开文件

                            HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.OK)

                            {

                                Content = new StreamContent(stream)

                            };

                            resp.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")

                            {

                                FileName = filename

                            };

                            resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                            resp.Content.Headers.ContentLength = stream.Length;

                            return await Task.FromResult(resp);

                        }

                    }

                }

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

            return new HttpResponseMessage(HttpStatusCode.NoContent);

        }
public static bool connectState(string path, string userName, string passWord)

        {

            bool Flag = false;

            Process proc = new Process();

            try

            {

                proc.StartInfo.FileName = "cmd.exe";

                proc.StartInfo.UseShellExecute = false;

                proc.StartInfo.RedirectStandardInput = true;

                proc.StartInfo.RedirectStandardOutput = true;

                proc.StartInfo.RedirectStandardError = true;

                proc.StartInfo.CreateNoWindow = true;

                proc.Start();

                //proc.StandardInput.WriteLine(@"Net Use {0} /del", path); //必须先删除,否则报错

                string dosLine = "net use " + path + " " + passWord + " /user:" + userName;

                proc.StandardInput.WriteLine(dosLine);

                proc.StandardInput.WriteLine("exit");

                while (!proc.HasExited)

                {

                    proc.WaitForExit();

                }

                string errormsg = proc.StandardError.ReadToEnd();

                proc.StandardError.Close();

                if (string.IsNullOrEmpty(errormsg))

                {

                    Flag = true;

                }

                else

                {

                    throw new Exception(errormsg);

                }

            }

            catch (Exception ex)

            {

                throw ex;

            }

            finally

            {

                proc.Close();

                proc.Dispose();

            }

            return Flag;

        }

webapi 文件下载输出接口的更多相关文章

  1. C# asp.net webapi下支持文件下载输出接口

    /// <summary>     /// 下载文件     /// </summary>     public class DownloadController : ApiC ...

  2. WebApi统一输出接口

    public class WebApi { /// <summary> /// 成功后的输出 /// </summary> /// <param name="d ...

  3. ASP.NET CORE WEBAPI文件下载

    ASP.NET CORE WEBAPI文件下载 最近要使用ASP.NET CORE WEBAPI用来下载文件,使用的.NET CORE 3.1.考虑如下场景: 文件是程序生成的. 文件应该能兼容各种格 ...

  4. H5+Ajax+WebApi实现文件下载(进度条,多文件)

    前言 踩过的坑 1.WebAPI跨域 2.Jquery ajax低版本不支持XHR 2功能 3.Jquery ajax不支持Deferred的process事件 4.IE下文件名乱码问题 功能实现 & ...

  5. .net core webapi带权限的文件下载方法

    众所周知,在webapi中,如果有个接口需要权限,一般会将带权限的字段塞进header中.但是,在带权限的文档下载接口中,无论是用post,还是get方式,我们无法设置header头信息.苦恼呀?别急 ...

  6. webapi 下载Ftp文件并返回流到浏览器完成文件下载

    ResultModel<HttpResponseMessage> resultModel = new ResultModel<HttpResponseMessage>(Resu ...

  7. ASP.NET WebAPi之断点续传下载(下)

    前言 上一篇我们穿插了C#的内容,本篇我们继续来讲讲webapi中断点续传的其他情况以及利用webclient来实现断点续传,至此关于webapi断点续传下载以及上传内容都已经全部完结,一直嚷嚷着把S ...

  8. ASP.NET WebAPi之断点续传下载(中)

    前言 前情回顾:上一篇我们遗留了两个问题,一个是未完全实现断点续传,另外则是在响应时是返回StreamContent还是PushStreamContent呢?这一节我们重点来解决这两个问题,同时就在此 ...

  9. 如何在启用JWT Token授权的.NET Core WebApi项目中下载文件

    背景 前几天,做项目的时候遇到一个文件下载的问题.当前系统是一个前后端分离的项目,前端是一个AngularJs项目, 后端是一个.NET Core WebApi项目.后端的Api项目使用了Jwt To ...

随机推荐

  1. Codeforces Round #513 by Barcelona Bootcamp

    A. Phone Numbers 签. #include <bits/stdc++.h> using namespace std; #define N 110 char s[N]; ], ...

  2. ng-深度学习-课程笔记-13: 目标检测(Week3)

    1 目标定位( object localization ) 目标定位既要识别,又要定位,它要做的事就是用一个框框把物体目标的位置标出来. 怎么做这个问题呢,我们考虑三目标的定位问题,假定图中最多只出现 ...

  3. linux下高并发网络应用注意事项

    本文转自:http://www.blogjava.net/bacoo/archive/2012/06/11/380500.html linux下高并发网络应用注意事项 vi /etc/sysctl.c ...

  4. 20145211《网络对抗》注入Shellcode并执行&&Return-to-libc攻击

    Shellcode注入 基础知识 Shellcode实际是一段代码,但却作为数据发送给受攻击服务器,将代码存储到对方的堆栈中,并将堆栈的返回地址利用缓冲区溢出,覆盖成为指向 shellcode的地址. ...

  5. POJ 1034 The dog task(二分图匹配)

    http://poj.org/problem?id=1034 题意: 猎人和狗一起出去,狗的速度是猎人的两倍,给出猎人的路径坐标,除了这些坐标外,地图上还有一些有趣的点,而我们的狗,就是要尽量去多的有 ...

  6. Maximum Depth of Binary Tree,求树的最大深度

    算法分析:求树的最小最大深度时候,都有两种方法,第一种是递归思想.树最大最小深度,即为它的子树的最大最小深度+1,是动态规划的思想.还有一种方法是层序遍历树,只不过求最小深度时,找到第一个叶子节点就可 ...

  7. SDK manager 中 Done loading packages 问题

    1.在选项栏中点击tools,选择Optons… 在弹出的设置窗口中勾选Force https://…sources to be fetched using http://… 然后点击Close 4. ...

  8. codeforces 98 div2 C.History 水题

    C. History time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  9. postman 安装桌面版

    https://github.com/postmanlabs/postman-app-support

  10. python 解压zip压缩包

    在当前路径解压zip压缩包,生成同名文件夹,内部目录结构与压缩包一致 import zipfile import os def un_zip(file_name): """ ...