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. 38初识xml

    XML(可扩展标记语言)是一种用于记录多种数据类型的标记语言.使用XML可以将各类型的文档定义为容易读取的格式,便于用户读取.而且,在应用程序中使用XML,可以轻松实现数据交换. QT中提供两种访问X ...

  2. 使用nagios+python监控nginx进程数

    1.编写python脚本监控nginx #!/usr/bin/python # -*- coding: utf-8 -*- import os, sys, time import string imp ...

  3. 一个Golang例子:for + goroutine + channel

    Rob Pike 在 Google I/O 2012 - Go Concurrency Patterns 里演示了一个例子(daisy chain). 视频地址:https://www.youtube ...

  4. windows下通过ping和tracert工具来测试网站访问速度

    一.环境 OS: windows 二.步骤 2.1.ping mirrors.163.com Pinging mirrors.163.com [23.111.1.151] with 32 bytes ...

  5. Knockout 监控数组对象属性

    代码: function Product(ProductID,ProductName,ProductNum,Result,Price) { this.ProductID = ko.observable ...

  6. Kubernetes证书相关(CFSSL)

    CFSSL是CloudFlare开源的一款PKI/TLS工具. CFSSL 包含一个命令行工具 和一个用于 签名,验证并且捆绑TLS证书的 HTTP API 服务. 使用Go语言编写. Github ...

  7. Spring Cloud 开发的一些推荐规划

    1.提供一个统一的 父 pom 依赖    作用:统一版本与引入必要依赖 2.提供一个模板模型. 作用: 开发人员不必关系具体基础启动项 3.提供一个统一基础配置模型 作用: 开发人员不比太过关注与必 ...

  8. 获取主机的对外ip

    # curl -w "\n" ifconfig.me # curl -w "\n" ipinfo.io/json # curl -w "\n" ...

  9. SSH防止暴力破解--fail2ban

    一.ssh密钥对无交互登录 实战1:通过密钥进行sshd服务认证 服务端:linl_S    IP:10.0.0.15 客户端:lin_C    IP:10.0.0.16   1)在客户端生成密钥对 ...

  10. Spring中<bean>标签之使用p标签配置bean的属性

    在spring的bean配置文件中我们常可以见到下面的例子: <bean id="user" class="com.sys.User" p:name-re ...