大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
下载,直接通过url读取文件,然后Response.OutputStream.Write()数据
创新互联主要从事成都做网站、网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务四川,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108
下面提供个下载的静态方法,是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();
}
Imports System
Imports System.IO.Ports
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'获取计算机有效串口
Dim ports As String() = SerialPort.GetPortNames() '必须用命名空间,用SerialPort,获取计算机的有效串口
Dim port As String
For Each port In ports
portnamebox.Items.Add(port) '向combobox中添加项
Next port
'初始化界面
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
OpenFileDialog.Filter = "文本文件(*.jpg)|*.jpg|所有文件(*.*)|*.*"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = OpenFileDialog.FileName
' TODO: 在此处添加打开文件的代码。
textbox1.Text = FileName
End If
第一个按钮 上传
Dim filelast As String = fileaddbefore.Text.Substring(fileaddbefore.Text.LastIndexOf("."), fileaddbefore.Text.Length - fileaddbefore.Text.LastIndexOf("."))
MessageBox.Show(filelast)
My.Computer.Network.UploadFile(textbox1.Text, "" 文件名.Text filelast, "登录名1", "登录密码", True, 100)
第二个按钮
My.Computer.Network.UploadFile
比如上传到FTP
My.Computer.Network.UploadFile("d:\1.txt", "“, "FTP账号", "FTP密码", True, 100)
新手路过。