以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  如何给文件上传做个进度条?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=127609)

--  作者:ZJZK2018
--  发布时间:2018/11/18 0:43:00
--  如何给文件上传做个进度条?
如何计算文件大小,再根据文件大小做个进度条,为什么下面代码一执行就死机?

Dim st As String = "D:\\图集规范\\图集\\建筑工程\\钢筋工程\\16G1012现浇混凝土板式楼梯.pdf"

Dim stt As String"C:\\AAA\\16G1012现浇混凝土板式楼梯.pdf

Dim pg As WinForm.ProgressBar = e.Form.Controls("ProgressBar1")

Dim fif As new FileInfo(st)

Dim fift As new FileInfo(stt)

pg.Maximum = fif.Length

pg.Minimum = 0

pg.Value = 0

 

For i As Integer = 0 To (fif.Length - fift.Length)

    FileSys.CopyFile(st,stt,True)

    If i Mod 100 = 0 Then

        pg.Value = i

    End If

Next


--  作者:有点甜
--  发布时间:2018/11/18 22:44:00
--  

1、copyFile无法做进度条;

 

2、除非自己写代码拷贝文件,如

 
try
    Dim ms1 As New IO.FileStream("d:\\test.jpg", IO.FileMode.Open)
    Dim ms2 As New IO.FileStream("d:\\000.jpg", IO.FileMode.Create)
    Dim buffer(1024) As Byte
    Dim count = ms1.read(buffer, 0, buffer.length)   
    Do While (count > 0)
        ms2.Write(buffer, 0, count)
        count = ms1.Read(buffer, 0, buffer.Length)
    Loop

    ms1.Dispose()
    ms2.Dispose()
    msgbox("ok")
catch ex As exception
    msgbox(ex.message)
End try

[此贴子已经被作者于2018/11/18 22:44:25编辑过]

--  作者:ZJZK2018
--  发布时间:2018/11/19 0:08:00
--  
老师如何赐值给进度条?
--  作者:有点甜
--  发布时间:2018/11/19 0:17:00
--  

try
    Dim ms1 As New IO.FileStream("d:\\test.jpg", IO.FileMode.Open)
    Dim ms2 As New IO.FileStream("d:\\000.jpg", IO.FileMode.Create)
    Dim buffer(1024) As Byte
    Dim count = ms1.read(buffer, 0, buffer.length)
    msgbox(ms1.length)
    Dim sum As Double = 0
    Do While (count > 0)
        sum += count
        output.show(sum)

        ms2.Write(buffer, 0, count)
        count = ms1.Read(buffer, 0, buffer.Length)
    Loop
    ms1.Dispose()
    ms2.Dispose()
    msgbox("ok")
catch ex As exception
    msgbox(ex.message)
End try