| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 474 人关注过本帖
标题:在线求助!急!急!!怎么没有人会呀。。。。。。。。
取消只看楼主 加入收藏
premking
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-7-30
收藏
 问题点数:0 回复次数:0 
在线求助!急!急!!怎么没有人会呀。。。。。。。。
问题是这样的,我要在客户端调用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

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

搜索更多相关主题的帖子: 在线 
2007-08-08 12:28
快速回复:在线求助!急!急!!怎么没有人会呀。。。。。。。。
数据加载中...
 
   



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

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