标题:急呀!!怎么没有人会呀?????
只看楼主
premking
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-7-30
 问题点数:0 回复次数:15 
急呀!!怎么没有人会呀?????
问题是这样的,我要在客户端调用WEB页面实现文件的下载,可是点击客户端下载按钮后,弹出的保存文件对话框经常跟我捉迷藏,时有时无。各位大虾帮忙看看是怎么回事。谢谢了!在线等
web端代码如下:
void Page_Load(Object sender, EventArgs e)
{
string Hid;
string company;
string year;
string filepath;
string filename;
Hid = Request.Params["HID"];
company = Request.Params["Company"];
year = Request.Params["iYear"];

filename = "Y" + year + "-Results.xls";
try
{

filepath = ("D:\\abc\\Ind") + Hid + "\\" + company ;
if (System.IO.Directory.Exists(filepath))
{
Response.Clear();
Response.Buffer = true;
//Response.ContentType = "text/html";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename);
Response.ContentType = "binary/vnd.ms-excel";
Response.WriteFile(filepath + "\\"+ filename);
Response.Flush();
Response.End();
Response.Write("0");
}
else { Response.Write("1"); }// 表示文件路径不存在
}

}
vb端代码如下:

Const DataPath = "http://192.168.0.141/"

Sub CheckID(URL As String)
Dim WebBrowser: Set WebBrowser = CreateObject("InternetExplorer.Application")
WebBrowser.Visible = False
WebBrowser.Navigate URL
Do While WebBrowser.busy
DoEvents
Loop

On Error Resume Next
If Strings.Left(WebBrowser.Document.body.innertext, 1) = "0" Then
WebBrowser.Quit
'get file
downloadfromServer
Unload Me
Exit Sub
End If
MsgBox "密码错误!", vbCritical, Title
Set WebBrowser = Nothing
End Sub
Private Sub PrintButton2_Click()
Dim Uname, PWord As String
Uname = Strings.Trim(Txt2ID.Text)
PWord = Strings.Trim(TxtPSW2.Text)
CheckID DataPath & "CheckLog.aspx?u=" & Uname & "&p=" & PWord
End Sub

Private Sub UserForm_Layout()
Txt2ID.Text = Workbooks("Main.xls").Worksheets("D").Range("IN").Value
End Sub
Public Sub downloadfromServer()
Dim FileName, phpName As String
Dim fso As New Scripting.FileSystemObject
Dim myfile As Scripting.File
Dim fs As Scripting.TextStream
' Dim DPath As String
Dim iYear As Integer
Dim HID As String '行业号
Dim Company As String '公司号
Dim Indsecret As String '行业密码前4位
Dim Year As String ' 年份
Dim CO As String
Dim COLIST As Variant
COLIST = Array("", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P")
Year = TextBox1.Text
phpName = "down.aspx"
HID = Workbooks("Main.xls").Worksheets("D").Range("IN").Value
CO = Workbooks("Main.xls").Worksheets("D").Range("CO").Text
Company = COLIST(CO)
IEGetStringRequest DataPath & phpName & "?HID=" & HID & "&Company=" & Company & "&iYear=" & Year

End Sub

Function GetFile(FileName As String) As String
Dim FileContents() As Byte, FileNumber As Integer
ReDim FileContents(FileLen(FileName) - 1)
FileNumber = FreeFile
Open FileName For Binary As FileNumber
Get FileNumber, , FileContents
Close FileNumber
GetFile = Strings.StrConv(FileContents, vbUnicode)
End Function


Sub IEGetStringRequest(URL As String)
Dim WebBrowser: Set WebBrowser = CreateObject("InternetExplorer.Application")
WebBrowser.Visible = False

'Dim filepath As String

WebBrowser.Navigate URL
Do While WebBrowser.busy
DoEvents
Loop
On Error Resume Next
If Left(WebBrowser.Document.body.innertext, 1) = "0" Then
MsgBox "文件下载失败!" & Err.Description, vbCritical, Title
End If

End Sub
搜索更多相关主题的帖子: 客户端下载 company Object 对话框 
2007-08-09 12:20
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
得分:0 

真是好贴

[此贴子已经被作者于2007-8-9 18:40:03编辑过]

2007-08-09 12:33
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
得分:0 

真是好贴

[此贴子已经被作者于2007-8-9 18:40:14编辑过]

2007-08-09 13:00
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
得分:0 

真是好贴

[此贴子已经被作者于2007-8-9 18:40:24编辑过]

2007-08-09 13:21
premking
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-7-30
得分:0 
multiple1902
你会吗?我昨天等了一天了
如果会我先谢了!如果不会闭上你的嘴
2007-08-09 16:26
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
得分:0 

真是好贴

[此贴子已经被作者于2007-8-9 18:40:31编辑过]

2007-08-09 18:18
premking
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-7-30
得分:0 
我从不激人,我昨天等了一天,今天又重新编辑了一下,这是我早上发的,我不可能一天什么都不干,在那等帖,我昨天已经等一天了,今天我也觉得没什么戏就干别的事去了,我对我的失信道歉,但是我看到你写的话。说实话你的心里素质不咋的!而且说话欠水平。不过还是谢谢你的关注。
2007-08-09 18:32
premking
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-7-30
得分:0 
顺便说一声我下线了。

2007-08-09 18:35
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
得分:0 
我能说什么呢?
这种问题就拿出来问?
自己做不到在线等就不要吹牛。事实上我回答了,然后很失望地看到LZ没有履行“在线等”的承诺。
2007-08-09 18:41
premking
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-7-30
得分:0 
如果我是学这个的我问你干吗?
如果能指点迷津不胜感激!请在回帖中指出。如果不想回答就算了。
2007-08-10 09:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-161466-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.195795 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved