首页后端开发ASP.NETvb点虐取文件路径 vbnet filestream

vb点虐取文件路径 vbnet filestream

时间2023-04-18 10:36:01发布访客分类ASP.NET浏览1119
导读:vb点虐怎么实现点击下载,获取文件路径并下载 下载,直接通过url读取文件,然后Response.OutputStream.Write( 数据下面提供个下载的静态方法,是C#的,供参考:/// summary/// 下载文件/// /sum...

vb点虐怎么实现点击下载,获取文件路径并下载

下载,直接通过url读取文件,然后Response.OutputStream.Write()数据

下面提供个下载的静态方法,是C#的,供参考:

/// summary

/// 下载文件

/// /summary

/// param name="fileName"下载的文件名称(包括扩展名)/param

/// param name="filePath"下载文件的绝对路径/param

public static void DownFile(string fileName, string filePath)

{

    //打开要下载的文件,并把该文件存放在FileStream中                

    System.IO.FileStream Reader = System.IO.File.OpenRead(filePath);

    //文件传送的剩余字节数:初始值为文件的总大小                

    long Length = Reader.Length;

    HttpContext.Current.Response.Buffer = false;

    HttpContext.Current.Response.AddHeader("Connection", "Keep-Alive");

    HttpContext.Current.Response.ContentType = "application/octet-stream";

    HttpContext.Current.Response.Charset = "utf-8";

    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;  filename=" + System.Web.HttpUtility.UrlEncode(fileName));

    HttpContext.Current.Response.AddHeader("Content-Length", Length.ToString());

    byte[] Buffer = new Byte[10000]; //存放欲发送数据的缓冲区                

    int ByteToRead;  //每次实际读取的字节数               

    while (Length  0)

    {     

 //剩余字节数不为零,继续传送                    

        if (HttpContext.Current.Response.IsClientConnected)

        {     

//客户端浏览器还打开着,继续传送                        

            ByteToRead = Reader.Read(Buffer, 0, 10000);                    //往缓冲区读入数据                        

            HttpContext.Current.Response.OutputStream.Write(Buffer, 0, ByteToRead);     

//把缓冲区的数据写入客户端浏览器                        

            HttpContext.Current.Response.Flush();  //立即写入客户端                        

            Length -= ByteToRead; //剩余字节数减少                            }

        else

        {                          

//客户端浏览器已经断开,阻止继续循环                        

            Length = -1;

        }

    }                 //关闭该文件               

    Reader.Close();

}

QQ:121一九五五121

VB.NET 获取文件目录

Server.MapPath("~") "\" "Web.config"Server.MapPath("~") 是取当前目录上一级的路径Server.MapPath(".") 是取当前目录的路径

vb点虐 d盘有个文件夹file里面有excel类型文件怎么用getfile取到文件的路径

你好,请使用System.IO.Directory.EnumerateFiles()方法

Dim XLS文件列表 As IEnumerable(Of string)

Dim XLSX文件列表 As IEnumerable(Of string)

Dim path As String = "D:\File\"

XLS文件列表 = Directory.EnumerateFiles(path, "*.xls", SearchOption.TopDirectoryOnly)

XLSX文件列表 = Directory.EnumerateFiles(path, "*.xlsx", SearchOption.TopDirectoryOnly)

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: vb点虐取文件路径 vbnet filestream
本文地址: https://pptw.com/jishu/3662.html
vb点虐查看word vbnetdatagridview查询 学vb点虐英语要求 vb net

游客 回复需填写必要信息