vb.net制作下载文件 vbs下载文件

VB.NET中如何实现下载功能Dim strPath As String = Server.MapPath("xxx/xxx.xxx") '这里是你的文件路径以及名称后缀名,使用相对路径即可,不过记得路径最好是英文,用中文是否连接不到我就不知道了,记得是"/"哦! Page.Response.Clear() Page.Response.AddHeader("Content-Type", "text/xml") Page.Response.AddHeader("Content-Disposition", "attachment;filename=") Page.Response.WriteFile(strPath) Page.Response.End()路径的话你可以使用变量的 所以这样一来需要下载的文件就会相当灵活 顺便附送一个删除文件的方法 System.IO.File.Delete(Server.MapPath("xxx/xxx.xxx")) 不过删除文件跟写文件是一样的 需要WEB服务器开启可写功能!、好用的话记得给分哦 嘿嘿!
vb.net怎么实现点击下载,获取文件路径并下载下载 , 直接通过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 (Length0)
{
//剩余字节数不为零 , 继续传送
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 实现文件下载Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
sub command1_click()
R= URLDownloadToFile(0,"
, "c:\1.exe", 0, 0)
end sub
vb.net下载文件下载文件的话你要到这个名称空间找都这个函数
System.Net.WebClient.DownloadData(ByVal
String)
As
Byte(
)
--下载资源
DownloadData:
Public
Function
DownloadData(ByVal
address
As
String)
As
Byte(
)
System.Net.WebClient
的成员
摘要:

System.Byte
数组形式通过指定的
URI
下载资源 。
参数:
address:
从中下载数据的
URI 。
返回值:
一个
【vb.net制作下载文件 vbs下载文件】System.Byte
数组,其中包含下载的资源 。
异常:
System.Net.WebException:
通过组合

推荐阅读